Hello everyone ^^
i'm third-year student at the University of Viet Nam. i have a question T.T . How to connect nodejs serversocket from nodemcu clientsocket by micropython. I have trouble creating a socket ,i wonder how to easy connect nodemcu to a webserver use to turn on/off led light. help me, please
Thanks you !!
Have a nice day to everyone !!!
connect webserver
Re: connect webserver
Hi,
Instead of using sockets directly it might be easier to use HTTP.
I'm not sure which end you want to be the server, but the two options are:
- MicroPython is the server, you connect to it from nodejs to toggle the LED. Take a look at https://github.com/miguelgrinberg/microdot for an example of a web server that provides a way to toggle GPIO pins (see examples/gpio).
- nodejs is the server, and the micropython board periodically checks the server to see what state the LED should be in. In that case you can use the urequests library (which is installed by default on ESP8266/ESP32) to connect to the nodejs webserver.
Instead of using sockets directly it might be easier to use HTTP.
I'm not sure which end you want to be the server, but the two options are:
- MicroPython is the server, you connect to it from nodejs to toggle the LED. Take a look at https://github.com/miguelgrinberg/microdot for an example of a web server that provides a way to toggle GPIO pins (see examples/gpio).
- nodejs is the server, and the micropython board periodically checks the server to see what state the LED should be in. In that case you can use the urequests library (which is installed by default on ESP8266/ESP32) to connect to the nodejs webserver.