Closed benpeart closed 2 months ago
I don't know where is exactly the bug yet, but I would suggest to not use such method for this use case. If you look how it is implemented, it does twice the formatting to detect the string length. I don't know why this method was added to the library but it is IMO not the best move that was done,
Also, they do not check if the return from vsnprintf is negative, and they put that in a size_t (unsigned), so if the return is negative, you'll end up with a huge unsigned number.
I would suggest:
String payload;
payload.reserve(2+10); // 10, depending on your PID Kp acceptable values
payload.concat("kp");
payload.concat(String(f, 4));
client.text(payload)
Will open a PR to try fix these methods... I saw at least 3 issues... I really encourage you to not use these printf variants: they are slow.
@benpeart : I have opened PR #95 and I've tested it locally with the SimpleServer.ino
example and websocat
sending each 100 ms: ws.printfAll("kp%.4f", (10.0 / 3.0));
.
it works fine now, will merge and release soon.
But I still advise you to not use this method because it is far from being efficient...
v3.2.4 released
Thank you for your suggestion. I have switched my code over as recommended and now it works correctly. That was an amazingly fast fix!
I have an application that successfully opens a AsyncWebSocket connection to a web page. The web page can successfully send messages to my application but my application does not successfully send messages to the web page.
In my OnEvent handler for the WS_EVT_CONNECT event, calling:
generates a corrupt heap crash. If I switch it to:
it doesn't crash but the web page doesn't get the message. If I continue attempting to send messages, I will get a "too many messages queued" error and then the connection will be closed:
Board
esp32dev
Stack trace
Additional notes
I'm currently using:
in my platform.ini in hopes it will help (but it doesn't appear to).
Complete source for my project is here.
The onEvent handler in question is here.
The corresponding code in the web page is here