简体   繁体   English

如何使用 websockets、js 和树莓派打开灯

[英]How to turn on a light with websockets, js, and raspberry pi

So i have a node-js thing set up, and if i press a button on the dashboard the light will turn on.所以我设置了一个node-js,如果我按下仪表板上的一个按钮,灯就会亮起来。 But, how can i do this with JavaScript and web-sockets?但是,我如何使用 JavaScript 和网络套接字来做到这一点?

1: Is it possible? 1:有可能吗?

2: How can it be done 2:怎么做

3: Does it work? 3:有效吗?

So these are the things i want to answer and i also want to turn on a light.所以这些是我想回答的问题,我也想打开一盏灯。 I have the light setup with aliases on bash, but i just do not know how i can make the light turn on by clicking a button on a html site?我在 bash 上有带别名的灯设置,但我只是不知道如何通过单击 html 站点上的按钮来打开灯? And is it possible有没有可能

So, ive already explained all i can and the website will not let me post.所以,我已经尽我所能解释了,网站不会让我发帖。 So this is just a 'summary'.所以这只是一个“总结”。 I want to use javascript to turn on a light on the GPIO's on my RPi, and with websockets connected to node-js.我想使用 javascript 打开我的 RPi 上 GPIO 的灯,并将 websockets 连接到 node-js。

So you want to design a system to turn on lights remotely through connected IoT devices, in order to create such system, you need a few things:所以你想设计一个系统来通过连接的物联网设备远程开灯,为了创建这样的系统,你需要一些东西:

  1. A backend server (A python server, PHP, or NodeJS) to facilitate the connection between the client and your Raspberry Pi.一个后端服务器(A python 服务器、PHP 或 NodeJS),以促进客户端和您的 Raspberry Pi 之间的连接。 There are cloud services such as Amazon's AWS IoT core that provide such feature.有提供此类功能的云服务,例如亚马逊的 AWS IoT 核心。

  2. A Client application with a user interface dashboard, either a Web Application(HTML, CSS, Javascript) or a Mobile Application (Flutter, React Native, Android Java/Kotlin, iOS Swift/Objective-C). A Client application with a user interface dashboard, either a Web Application(HTML, CSS, Javascript) or a Mobile Application (Flutter, React Native, Android Java/Kotlin, iOS Swift/Objective-C).

  3. An always-running Python script in the Raspberry Pi to listen to any possible instruction from the server, and trigger its respective I/O to turn on the circuit. Raspberry Pi 中始终运行的 Python 脚本用于侦听来自服务器的任何可能指令,并触发其各自的 I/O 以打开电路。

There are multiple technology that are involved within this whole process so I can't explain everything in a single answer.整个过程涉及多种技术,因此我无法在一个答案中解释所有内容。

So the short answer is yes, it can be done, it will work, but how well it works depends on the type of technology and architecture you use.所以简短的回答是肯定的,它可以完成,它会起作用,但它的效果取决于你使用的技术类型和架构。

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

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