简体   繁体   English

Raspberry PI Arduino通讯

[英]Raspberry PI Arduino communication

I have a Raspberry Pi and Arduino connected via UART(TxRx) and I have a website HTML hosted on the rPi. 我有一个通过UART(TxRx)连接的Raspberry Pi和Arduino,并且我在rPi上托管了一个网站HTML。
What do i need to do that when a button is pressed on the website a string would be sent to the arduino over UART. 当在网站上按下按钮时,我需要做的是将一个字符串通过UART发送到arduino。
I have already tried sending strings from rPi's terminal via command echo test > /dev/ttyAMA0 , test being the string i want to send and it worked. 我已经尝试过通过命令echo test > /dev/ttyAMA0从rPi的终端发送字符串,测试是我要发送的字符串,它可以正常工作。

You need a CGI script on the rPi. 您需要在rPi上使用CGI脚本。 When the user's web browser goes to that page (or is directed to it by pushing a button) then the CGI scirpt will run on the rPi which can pipe data out the serial port. 当用户的Web浏览器转到该页面(或通过按下按钮定向到该页面)时,CGI脚本将在rPi上运行,该rPi可以将数据通过串行端口输出。 Heres a random CGI tutorial if it helps, but you should look at the docs for whatever webserver your running (probably apache ?) 如果有帮助的话,这里提供了一个随机的CGI教程 ,但是您应该查看您正在运行的任何Web服务器的文档(可能是Apache吗?)

Yes I am running an apache webserver. 是的,我正在运行一个Apache Web服务器。 And I forgot to write that i have tried creating a .sh file that has the echo command in it. 而且我忘记写了我曾尝试创建一个带有echo命令的.sh文件的信息。 This is my .sh script i created: 这是我创建的.sh脚本:

#!/bin/sh
echo 1 > /dev/ttyAMA0
echo "Content-type: text/html"
echo ""
echo "<html><head><title>DzAnej Systems"
echo "</title></head><body>"
echo "<meta http-equiv=\"refresh\" content=\"0; url = http://192.168.1.3/dashboard.html\" />"
echo "</body></html>"

This script sends the 1 to the /dev/ttyAMA (Arduino) and returns the user to the previous page... The bottom part is working (return to the previous page) but the echo command is somehow not working... 该脚本将1发送到/ dev / ttyAMA(Arduino)并将用户返回到上一页...底部正在工作(返回上一页),但是echo命令在某种程度上不起作用...

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

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