connect webserver

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
vantu2801
Posts: 1
Joined: Fri Apr 10, 2020 1:57 am

connect webserver

Post by vantu2801 » Fri Apr 10, 2020 2:11 am

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 :roll: :roll: :roll:
Thanks you !!
Have a nice day to everyone !!!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: connect webserver

Post by jimmo » Tue Apr 14, 2020 4:18 am

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.

Post Reply