Thursday, May 28, 2020

Messing around with Socket Servers on ESP32

https://shawnhymel.com/1675/arduino-websocket-server-using-an-esp32/

See the link above. I gave this a shot, but my computer immediately disconnects once I connect to the socket server. I need to somehow keep the socket open.

I am going to try his more advanced websocket server (link below) and see if I run into the same issue. Maybe I can backtrack the problem, or maybe I can ask a friend.

https://shawnhymel.com/1882/how-to-create-a-web-server-with-websockets-using-an-esp32-in-arduino/

Compare the result to using an HTTP server.

https://www.youtube.com/watch?v=3FNs-t-fbzU


Supposedly a Socket Server is better because I can keep the connection open. But how do I keep it open?


Edit (May 31st, 2020):

The second Shawn Hymel link mentions WiFi.SoftAP . The only mention in the Ardunio library that I found was:

https://github.com/arduino-libraries/WiFi/blob/425e5a45745e0985345dc5e9d86062dee3e2a153/extras/wifiHD/src/SOFTWARE_FRAMEWORK/COMPONENTS/WIFI/HD/wl_api.h#L1311

SoftAP is https://en.wikipedia.org/wiki/SoftAP . This requires a password, which is a problem according to Wikipedia. Maybe not if you go the verifiable credentials / DID route. Libraries? Ockam?

Edit (May 31st, 2020):

I tried the second project "1882" and recorded the results:

https://youtu.be/Gqzvq05QUKw
Now I do not know how to pull data from the Sockets Server. I know how to push data to it using the button. However, I notice that if I place a toggle switch in the circuit with the LED and break the connection the webserver code does not read any change in state from the sockets server. I need code that continuously listens to what is happening on the server side (i.e. whether there is a connection).

I suspect that a chat server is a good analogue.
https://www.youtube.com/watch?v=rxzOqP9YwmM

The code is here:
https://github.com/WebDevSimplified/Realtime-Simple-Chat-App

[review node modules for node project setup:
https://docs.npmjs.com/creating-node-js-modules]

Once I know how a chat server works, then maybe I will be able to apply it to an LED.

A sensor turns "on" and "off" when it receives new data.

[ note. the websocket server is on a different network than the wifi network. (uses softAP) this is a problem for my laptop (at least under the current configuration) . Perhaps I can connect to both networks in my network card supports it??
https://askubuntu.com/questions/488588/how-do-i-connect-to-multiple-wifi-networks] ... nvm...I can get the websocket server and the rest of the system to run on the same network

Edit:: I found a configuration that works. I can turn on an off an LED from a webpage.

Interesting document
https://tttapa.github.io/ESP8266/Chap01%20-%20ESP8266.html

It has websockets!
https://tttapa.github.io/ESP8266/Chap14%20-%20WebSocket.html

But how do I get it to forward my sensor data?? Try this::
https://esp8266-shop.com/blog/websocket-connection-between-esp8266-and-node-js-server/
or https://techtutorialsx.com/2018/09/11/esp32-arduino-web-server-sending-data-to-javascript-client-via-websocket/

In the future see:
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html

and:

https://www.youtube.com/watch?v=EvUI4vRhF88 (MQTT Over Websockets Explained for Beginners )

https://www.youtube.com/watch?v=2aHV2Fn0I60 (An Introduction to MQTT for Beginners) [one version uses TCP another uses UDP]

Espressif also provides a websocket client:
https://github.com/espressif/esp-idf/tree/7d75213674b4572f90c68162ad6fe9b16dae65ad/components/esp_websocket_client

No comments:

Post a Comment