At the ESP8266 side I had a function named "handleUpdateData" that I used both in server handler declaration with this declaration
server->on("/updatedata", handleUpdateData);
and called asynchronously when i got some variation of the status that i would to be check.
In the "handleUpdateData" function i builded the JSON string with "page" variable using the data stream syntax like
id: 12345
data: { "code": "123",
data: "status": "xxxx" }
and sended it by this instruction
server->send(200, "text/event-stream", page);
At the webpage side i had this declaration in javascript first
var eventSource = new EventSource("/updatedata");
and after that with
eventSource.onmessage = function(e) {
debug("onmessage: "+e.data);
}
OR (without differences)
eventSource.addEventListener("message", function(e) {
debug("received message: "+e.data);
}
In both cases, i received data every 5 seconds regulary.
In case of some exception, when ESP8266 side i builded a new send, at the webpage side I had nothing out synch of 5 seconds, despite i used the id in the message frame that was not verified by web browser.
What's wrong?