通过 RPi 托管网站控制 Arduino 输出
Controlling Arduino Output Via RPi Hosted Website
我目前有一个由 Raspberry Pi 托管的基本网站。我想做的是通过 HTML 表单按钮控制数字输出。目前它在我在 LAN 上时工作,因为按钮表单操作设置为 Arduino 的本地 IP。我正在努力弄清楚如何从另一个网络或我的 phone 控制这些输出。
我是否认为我需要将 on/off 命令传递给 RPi 上托管的 php 脚本之类的东西,并让 php 脚本生成 Post要求?
有没有人举个例子让我指出正确的方向?
提前致谢
您可以使用 RPi 托管网站控制 Arduino GPIO。
您需要学习的内容:
- I2C/Serial/SPI Arduino 和 RPi 之间的通信 (Sample Tutorial (I2C))
- CGI 可以执行用 C/C++、Python 等编写的程序,将 print/println/cout 重定向为 Web 响应,也可以执行系统命令来操纵通信总线, gpio 和系统调用。要了解更多有关 CGI 的信息,click here. (Get started with CGI)
- 您可以从 URL 调用 CGI 程序,就像调用网页一样:("192.168.1.0/cgi-bin/HelloWorld" ,对于 RPi "/usr/lib/cgi-bin/" 是存储 CGI 程序的文件夹,而 "HelloWorld" 是您的可执行文件。
As an example, assume that you want to turn on-off Arduino's on-board led D13 via webpage hosted on RPi. Webpage contains two buttons, On and Off. When "On" pressed (clicked), call C/C++ or Python code written to command Arduino via I2C. Define a common protocol to follow so that bytes sent by C/C++ or Python can be understand by Arduino. Like, if Arduino receives 1 from master (RPi), it should turn on D13 led and turn off for 0.
我目前有一个由 Raspberry Pi 托管的基本网站。我想做的是通过 HTML 表单按钮控制数字输出。目前它在我在 LAN 上时工作,因为按钮表单操作设置为 Arduino 的本地 IP。我正在努力弄清楚如何从另一个网络或我的 phone 控制这些输出。
我是否认为我需要将 on/off 命令传递给 RPi 上托管的 php 脚本之类的东西,并让 php 脚本生成 Post要求?
有没有人举个例子让我指出正确的方向?
提前致谢
您可以使用 RPi 托管网站控制 Arduino GPIO。
您需要学习的内容:
- I2C/Serial/SPI Arduino 和 RPi 之间的通信 (Sample Tutorial (I2C))
- CGI 可以执行用 C/C++、Python 等编写的程序,将 print/println/cout 重定向为 Web 响应,也可以执行系统命令来操纵通信总线, gpio 和系统调用。要了解更多有关 CGI 的信息,click here. (Get started with CGI)
- 您可以从 URL 调用 CGI 程序,就像调用网页一样:("192.168.1.0/cgi-bin/HelloWorld" ,对于 RPi "/usr/lib/cgi-bin/" 是存储 CGI 程序的文件夹,而 "HelloWorld" 是您的可执行文件。
As an example, assume that you want to turn on-off Arduino's on-board led D13 via webpage hosted on RPi. Webpage contains two buttons, On and Off. When "On" pressed (clicked), call C/C++ or Python code written to command Arduino via I2C. Define a common protocol to follow so that bytes sent by C/C++ or Python can be understand by Arduino. Like, if Arduino receives 1 from master (RPi), it should turn on D13 led and turn off for 0.