-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary data not working #32
Comments
I will look into it. EDIT: I was unable to reproduce with the information you gave here. Thanks. |
Sorry for the short and misleading text ... Arduino ESP32 1.0.2 with ArduinoWebsockets 0.4.10 :
Webbrowser:
Serial log:
Hope you can reconstruct it now ;-) |
Sadly I still can't see any crashes.. Is it possible that you forget to call Let me know if you have any more info regarding what you see (some sort of crash?) or what you expect to happen that isn't happening. |
There are no crashes ;-) its working really stable! Yes I only need one connection at a time. Only one client is planned. But data().length() is not giving the right information. Or do I do something completely wrong? |
Oh, I see now! I understood you completely wrong, sorry. The issue seems to be that Arduino's In order to work around that, I'm consider adding a The reason I chose Arduino's String is in order for users to be able to print the strings directly to Serial. But it seems like I should provide a pro feature to access the raw string directly. Will something like that be helpful to you? Gil. |
Yes exactly. You got it ;-) Yes accessing the raw buffer ist ok for me. I'm planing to send jpegs over the WS in the browser you can convert them to to blobs and easily send them. I'm just worrying that there will be a problem with memory not freed. Arduino and Strings are really dangerous on this topic. |
Ok, I have the |
Thanks! Still need the internal buffer :-( I think the Problem is in ws_common.cpp: fromInternalString() std::string::c_str const char* c_str() const; This array includes the same sequence of characters that make up the value of the string object plus an additional terminating null-character ('\0') at the end. so if 0 char is in the internal string then it will be interpreted as terminating null-character ... |
I mad a temp fix for me: |
Yes please re raw :-) in a char array perhaps ? |
A char array is not good in my opinion. It has ownership and memory issues. Regarding your solution guys, I'm thinking about what can be done.. I want to make a change that won't break anyone's code but I'm not sure what can be done other than spending memory on duplicate of the data in it's raw form. I'm thinking about it, and it is an open bug and issue. If you guys have any idea, please let me know! |
The solution I'm considering now is:
Alternative 1:
|
As an opinion: However, if you remove the Arduino's Strings completely a lot of code will be broken as soon as users start to update their library... I would suggest adding a configuration value to the library, by which we could select the output type format we'd like to have for messages... (a method to be called in setup or so). Just my two cents. 😁 |
Why working with strings is "way more heavier" than with chars? I don't think moving to a char* will give users any kind of noticeable efficiency benefit. Anyways, if you use an esp32 or esp8266 with Arduino you probably not doing any super heavy work or anything that makes char* handling worth the effort. A configuration is a great idea. I've tried implementing a |
It's not really about the efficiency from processing perspective, but from memory. When I said heavier, I was referring to the fact that - though String class is easy to use, takes a lot of RAM. But - Gil - don't get me wrong, I love the library the way it is; I love the library and I want the best for it. 😀 All the best, |
You are definitely right, and I appreciate all the help and support 😃 I think breaking the interface might be the right thing to do in this case. Anyways, I'm keeping this issue open for any discussion. Best wishes, |
An idea: Serial.println(msg); Most users could just: auto data = msg.data(); and work with it without actually knowing what it contains (similar enough interface as Arduino's String) |
I have the same issue. Personal opinion: |
Thanks for all the feedback, I'm on it guys. |
A solution was merged to master a few moments ago. I will appreciate if any of you could check if your issues are solved by using I also documented the change here: https://github.com/gilmaimon/ArduinoWebsockets#binary-data |
I published release 0.4.14 which solves this issue. I mark this as solved, and will close this soon (unless anyone can reproduce the bug with the new interfaces, which shouldn't happen 😄 ) Thank you everyone for helping and contributing. (I'm keeping this issue open for few days) |
The bug with the ArduinoWebSockets library's code has been fixed. See gilmaimon/ArduinoWebsockets#32
Looks like 0 chars in binary package terminats packed.
Or msg.data().length() is not working ...
The text was updated successfully, but these errors were encountered: