4

I'm doing some experiments with some Linux-based embedded systems (Beaglebone, FriendlyARM mini6410, Embest Devkit 8000). I would like to write a web application using some kind of web technology PHP, Javascript,...whatever it is, whose purpose is just to blink a LED. I have to do this in order to see if I'm able to control some hardware resources through a Web application. I know that for the Beaglebone I can use node.js and bonescript but I would like to devise a solution that I can easily bring on other targets (with no or limited modifications to the application) since I have to replicate this on different embedded targets. I know that I have to go through sysfs in order to be able to control hardware resources from a user space application. I could do this in PHP (through sysfs I can drive a led just by opening and reading/writing files) or I could write a C CGI application wich does the same...But my question is, what are the other options? I would like to identify different possibilities for designing the web application in order to chose the proper one.

4

3 回答 3

4

写一个小cgi。它甚至可以用 shell 来完成,你可以在其中向 sysfs 发送命令

你可以做类似的东西

#!/bin/sh

#this will parse the sent parameters
eval $(echo "$QUERY_STRING"|awk -F'&' '{for(i=1;i<=NF;i++){print $i}}')


# this has to be set to whatever you want
GPIO=22

echo $GPIO > /sys/class/gpio/export
echo "out" /sys/class/gpio/gpio$GPIO/direction
echo 1 /sys/class/gpio/gpio$GPIO/value

cat << EOF
Content-Type: text/html

<!DOCTYPE html>
<html>
<body>
<h1>pin on</h1>
</body>
</html>
EOF

最后,您需要确保您有权在 sysfs 上进行写入,并且网络服务器已配置为使用 shell 作为 cgi 的解释器

于 2012-10-30T13:25:35.110 回答
1

我写了一个名为“php-gpio”的小库:https ://github.com/ronanguilloux/php-gpio

我想这可能有助于实现这种目的。

于 2012-12-04T23:08:02.987 回答
1

好吧,如果我这样做,我可能会选择套接字通信。也许是串行的硬件(可能没有以太网/wifi端口)。如果设备可以通过抽象通信层来互换,那么我可能会启用对两者的支持,以便服务器可以使用套接字或串行连接策略。大多数所有语言都支持一种或另一种方式。

于 2012-10-30T13:33:35.500 回答