简体   繁体   English

使用SWIG / PHP控制Raspberry Pi上的应用程序(mjpg-streamer)

[英]Using SWIG/PHP to control applications on the Raspberry Pi (mjpg-streamer)

I try to start 'mjpg-streamer' via a swig/c/php interface on a raspberry pi. 我尝试通过树莓派上的swig / c / php接口启动“ mjpg-streamer”。 Previously, two apps are successfully controlled via swig/c/php: 以前,通过swig / c / php成功控制了两个应用程序:

  • GPIO-control via i2cset 通过i2cset进行GPIO控制
  • GPIO-control via wiringPI 通过接线进行GPIO控制

In case of the 'mjpg-streamer', I used the following code: 对于“ mjpg-streamer”,我使用以下代码:

  void stream(void) { system("export LD_LIBRARY_PATH=/usr/local/lib/"); system("mjpg_streamer -o 'output_http.so -w /media/MINIUSB/dev/Control/www' -i 'input_raspicam.so -x 640 -y 480 -fps 15'"); } 

and run 'make' as in case of the GPIO-controls 并像使用GPIO控件一样运行“ make”

    swig -Wextra -php camera.i
    gcc -fpic -c `php-config --includes` camera.c camera_wrap.c
    gcc -shared camera_wrap.o camera.o -o camera.so
    cp camera.so `php-config --extension-dir`
    service lighttpd restart

Finally I run 'chmod 4755 /usr/local/lib/input_raspicam.so' and 'chmod 4755 /usr/local/lib/output_http.so', as I did it to enable 'i2cset' etc. 最后,我运行了“ chmod 4755 /usr/local/lib/input_raspicam.so”和“ chmod 4755 /usr/local/lib/output_http.so”,因为我启用了“ i2cset”等功能。

In this example I do not use /dev/video[0..n], maybe it should be another device. 在此示例中,我不使用/dev/video[0..n],也许它应该是另一台设备。

The system runs under raspbian jessie, php-5.6.14, php5-[dev,cli,cgi], lighttpd, swig-2.0.12. 该系统在raspbian jessie,php-5.6.14,php5- [dev,cli,cgi],lighttpd,swig-2.0.12下运行。 According to phpinfo(), the module was successfully loaded. 根据phpinfo(),模块已成功加载。

Has anyone any idea what's going wrong? 有谁知道出什么事了吗?

I don't think the two calls to system do what you hope they will do when run consecutively like that. 我不认为这两个对system的调用不会像您希望的那样连续运行时那样。 The export of the first call will only impact the environment of the process of the shell spawned for that specific call to system . 首次调用的导出只会影响针对该特定system调用而生成的shell进程的环境。 The next call to system will inherit the environment of its parent, which won't have been changed. 下一次对system的调用将继承其父级的环境,该环境不会更改。 Instead what you might want to do is: 相反,您可能想做的是:

system("LD_LIBRARY_PATH=/usr/local/lib/ mjpg_streamer -o 'output_http.so -w /media/MINIUSB/dev/Control/www' -i 'input_raspicam.so -x 640 -y 480 -fps 15'");

Which will set the environment for the process that calls mjpg_streamer. 这将为调用mjpg_streamer的进程设置环境。 Or better yet use putenv/setenv instead. 最好还是改用putenv / setenv。

Since you're using PHP though and just calling system you'd be better off using PHPs shell_exec or similar since there isn't anything in your C that PHP can't already do (it just calls bash for you in a round about kind of way) 由于您虽然使用的是PHP,并且只是调用系统,所以最好使用PHP的shell_exec或类似的东西,因为C语言中没有PHP无法做的任何事情(它只是在某种程度上为您调用bash)当然)

When building your app, you can build the rpath into the .so with gcc -Wl,-rpath,/usr/local/lib ... instead of using LD_LIBRARY_PATH. 在构建应用程序时,可以使用gcc -Wl,-rpath,/usr/local/lib ...将rpath构建到.so中,而不是使用LD_LIBRARY_PATH。

As @Flexo noted, a separate system() to set the environment variable won't affect the environment in subsequent calls to system() 如@Flexo所指出的,用于设置环境变量的单独的system()不会在后续对system()的调用中影响环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM