简体   繁体   中英

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. But, how can i do this with JavaScript and web-sockets?

1: Is it possible?

2: How can it be done

3: Does it work?

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? 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.

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. There are cloud services such as Amazon's AWS IoT core that provide such feature.

  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).

  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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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