Description
Thank you very much for your clear and instructive tutorial! I appreciate your structured approach using many functions in particular!
I have a question and two suggestions.
Question:
You are using the processor function to process the index.html
file when it is sent to the client. In this way a new client gets directly the latest updated status of the led in the html-file.
In this tutorial, https://randomnerdtutorials.com/stepper-motor-esp8266-websocket/, they seem to take a different approach. When a new client connects, they initiate a notifyClients
command to notify (all) clients of the latest state. See code snippet below:
void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
switch (type) {
case WS_EVT_CONNECT:
Serial.printf("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
//Notify client of motor current state when it first connects
notifyClients(direction);
break;
case WS_EVT_DISCONNECT:
Serial.printf("WebSocket client #%u disconnected\n", client->id());
break;
I would say that the advantage of the notifyClients
approach is that you do not have to write a (possibly lengthy) processor function. The downside is that you also notify clients that are already connected; so in this approach you are creating unnecessary network traffic.
What are your thoughts on the notifyClients
approach?
Suggestion 1:
The usage of SPIFFS seems to be deprecated, see https://randomnerdtutorials.com/install-esp8266-filesystem-uploader-arduino-ide/. Would it be a good idea to replace SPIFFS by LittleFS in your tutorial to keep it up to date?
Suggestion 2:
The latest ArduinoJson version (version 7) one does no longer need to specify the size, see: https://arduinojson.org/v7/how-to/upgrade-from-v6/. Would it be a good idea to update the code in your tutorial accordingly?
By the way, using the old version still works, but produces a deprecation warning.