[英]How to establish two-way communication between a RaspberryPi and remotely hosted Webapp?
Hello to you great people, 大家好,
I have more of a 'conceptual' question rather than a purely code-oriented one. 我更多的是一个“概念性”问题,而不是纯粹的面向代码的问题。
So I have Node.js and Express running on my RPI. 所以我在RPI上运行了Node.js和Express。 I can connect to the board from a computer in the same local area and turn a single LED on and off remotely.
我可以从同一局域中的计算机连接到开发板上,并远程打开和关闭单个LED。
What I'd like to do next is host the web interface on Heroku for example and access the 'functionality' of my RPI from the web rather than from a local connection. 接下来,我想在Heroku上托管Web界面,然后从Web而非本地连接访问RPI的“功能”。
So... How does the 'internet of things' work really? 那么...“物联网”到底如何工作? How do you control a device from the internet and how do you send input from the device to a web interface?
您如何从互联网控制设备,以及如何将输入从设备发送到Web界面?
Thanks to anyone who takes the time to reply! 感谢所有花时间回复的人!
I would use socket.io. 我会使用socket.io。 It's a great library for websockets.
这是一个非常好的websockets库。 http://socket.io/
http://socket.io/
It depends more on how you want to connect. 这更多地取决于您要如何连接。 Two way communication can be as simple as rest communication being permitted on both ends.
双向通信可以像两端允许其余通信一样简单。 If you need continuous communication you can use websockets or direct tcp communication, etc. If you want just a status update on the website, you can have the device be the rest host.
如果需要连续通信,则可以使用websockets或直接进行tcp通信,等等。如果只想在网站上更新状态,则可以让设备作为其余主机。 You send a request to
{device.ip}/led/on
and the device turns on, or /status
and it will tell you what lights are on, etc. The web user would be a simple client which could even be hosted directly on the raspberry pi if you don't need a lot of clients connected simultaneously. 您向
{device.ip}/led/on
发送请求,然后设备打开,或/status
告诉您什么灯亮,等等。网络用户将是一个简单的客户端,甚至可以直接托管在该客户端上如果您不需要同时连接许多客户端,则使用树莓派。 It really depends on your application and what purpose/frequency you need to communicate. 这实际上取决于您的应用程序以及您需要沟通的目的/频率。
Some good resources for a node.js rest framework: 一些关于node.js其余框架的好资源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.