Hello everyone,
Really sorry if this post wont be well formatted or even written, but it's the first time I open a post here.
I started using the WebSerial library, currently version 2.0.8, in order to print some stuff there. But the main issue is with the "callbacks". The first callbacks are not being printed in the WebSerial UI.
The code I'm using is the official one, and from what I see, everything is fine, but something is wrong.
The callback code from the official site and it's precisely the same than mine:
Official code
WebSerial.onMessage([&](uint8_t *data, size_t len) {
Serial.printf("Received %u bytes from WebSerial: ", len);
Serial.write(data, len);
Serial.println();
WebSerial.println("Received Data...");
String d = "";
for(size_t i=0; i < len; i++){
d += char(data[i]);
}
WebSerial.println(d);
});
My code
WebSerial.onMessage([](uint8_t *data, size_t len) {
Serial.printf("Received %u bytes from WebSerial: ", len);
Serial.write(data, len);
Serial.println();
WebSerial.println("Received Data...");
String d = "";
for(size_t i=0; i < len; i++){
d += char(data[i]);
}
WebSerial.println(d);
});
If you see the serial prints that are printed, you see that I clicked 9 times, from 1 to 9:
14:37:06.433 -> Received 2 bytes from WebSerial: 1
14:37:07.729 -> Received 2 bytes from WebSerial: 2
14:37:08.309 -> Received 2 bytes from WebSerial: 3
14:37:09.056 -> Received 2 bytes from WebSerial: 4
14:37:10.087 -> Received 2 bytes from WebSerial: 5
14:37:10.680 -> Received 2 bytes from WebSerial: 6
14:37:11.075 -> Received 2 bytes from WebSerial: 7
14:37:11.613 -> Received 2 bytes from WebSerial: 8
14:37:12.097 -> Received 2 bytes from WebSerial: 9
If I see the webserial, which should have barely the same information, the first two entries somehow seem to remain on some sort of "cache", because they are printed later on
So, the order of this was:
In Webserial, I clicked 1 and nothing was printed;
In Webserial, I clicked 2 and nothing was printed;
In Webserial, I clicked 3 and it printed 1;
In Webserial, I clicked 4 and it printed 2;
And so on and so on.
Is there an issue with the library itself?
Can someone help out on this, since this is a pretty weird behavior?
I believe my code is fine, since it's precisely the official one

