简体   繁体   English

如何在RaspberryPi和远程托管的Webapp之间建立双向通信?

[英]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的“功能”。

  • How does one go about doing so? 如何去做呢? Are there any projects which I can draw inspiration from? 有什么项目可以吸引我的灵感吗?
  • Should I somehow use web-sockets to establish communication between the two? 我是否应该使用网络套接字在两者之间建立通信?
  • How do I send a 'request' from the server to the RPI, which has a local IP behind the router? 如何从服务器向RPI发送“请求”,该RPI在路由器后面具有本地IP?
  • What is a framework or a set of frameworks that might help me achieve that? 什么框架或一组框架可以帮助我实现这一目标? (SocketIO?) (SocketIO?)

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.

相关问题 如何在HTML和JS文件之间建立双向连接? - How to establish two-way connection between HTML and JS files? 流星与节点之间的双向通信 - Two-way communication between Meteor and Node AngularJS中父指令和子指令之间的双向通信 - Two-way communication between parent directive and child directive in AngularJS Node.js |工作进程:如何验证主进程和工作进程之间的双向通信 - Node.js|Worker Processes: How to verify two-way communication between a master and worker process 如何使用Firefox扩展代码注入来组织双向通信? - How to organize a two-way communication with the Firefox extension code injection? ExpressJS / Mongoose双向模型通信 - ExpressJS/Mongoose two-way model communication 范围之间的双向数据绑定 - Two-way Data Binding Between Scopes 如果 socketIO 生成的 id 是自动生成的,如何在两个用户之间建立通信? - How to establish a communication between two users, if the id generated by the socketIO are auto generated? AngularJS:如何在两个隔离的控制器和共享服务之间创建双向数据绑定? - AngularJS : How to create a two-way data binding between two isolated controllers and a shared service? 如何与数据库双向同步列表? - How to two-way sync lists with a database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM