[SOLVED] Uint8_t Buffer To String - Arduino Forum
Maybe your like
May Peace and Blessings be upon you!
I've been looking around for some reference to convert my whole buffer of uint8_t to use as a String. The reason was the String class offers us much easy to use and diverse methods or functions to process the data. This thing usually comes across to us when we are using some library and the library processes and gives you some data into a char* or uint8_t type of buffer. After getting the data in the buffer new comers usually don't know how to handle and process it. I had a similar scenario, but when I try to use google and this forum I didn't find much reliable solution to do it, and then I figured out some other way to achieve it using type casting.
Here is my solution:
if you have some kind of data buffer of uint8_t e.g:
uint8_t buff[700] = {0};and you want to convert all the buffer to the String. Then just call this code below and you will have your buffer as a String object.
String str = (char*)buff;and now you can use this String object to use any of its methods e.g:
char L = str.length();OR
String new_str = str.substring(8, 15);easy han?
Warning: Strings takes some more memory on your Arduino than uint8_t, So, be sure that what you are going to do otherwise your Arduino might keep on resetting again and again if the memory bloats.
I hope it will help you.
Regards, Dexterous.
2 Likes ESP32 UDP read data system August 17, 2015, 10:25am 2I hope it will help you.
Learning to not use Strings would be even more helpful.
1 Like gjntn November 26, 2015, 4:55pm 3Hi! ![]()
Learning to not use Strings would be even more helpful.
Learning to really help others, would be even more useful to everyone. Bring up some richer arguments, with sources, recommendations or whatever supports your comments around forums.
Everyone at programming world knows that handling integers is better, the lower memory elements the better, maybe, but just maybe, that's why...
Warning: Strings takes some more memory on your Arduino than uint8_t, So, be sure that what you are going to do otherwise your Arduino might keep on resetting again and again if the memory bloats.
So, for the record. This recipe posted by @Dexterous comes very in handy when working with HTTP responses when working with C at another microcontroller solution, but well, I suppose that even with that case of use, the String class doesn't seem to have any sense of existing... ![]()
Dexterous, thanks for this straightforward recipe and for your blessings!
Good vibes to all!
Jon.
acoolfrood May 15, 2016, 10:28am 4Most useful post I found in days of trawling the net! Thanks for this, I can now convert uin8_t to strings which has been causing me trouble for days ![]()
Hmm... self-SOLVED pseudo-questions and praise from newbies? Be warned. Don't use String™. Using the String class will cause you trouble forever.
Maybe the OP should read this recent discussion, this summary of the issues from all over the innertubes, and this cautionary tale. If you still wonder if String is useful, read this.
OP, if you want "to really help others", ask a useful question or provide a useful answer. Don't claim to solve the wrong problem for your 3rd post. If you have a 700-byte array and you convert it to a String, that allocates another 700 bytes. Using 1400 bytes for an HTTP response to extract one uint8_t is no solution -- it's unbelievably wasteful. The HTTP response should have been parsed as it was received.
And if you don't understand how to do that, ASK a question that may help others.
1 Like acoolfrood May 15, 2016, 7:57pm 6Good to know. It's fair to say that after posting the praise above I fell at the next hurdle in my code. Learning this stuff is difficult and there seems to be multiple ways to do each thing. I was trying to convert to a string as I needed to reference individual characters in the uinit8_t. It seemed that charAt could only parse strings from the references I read. I later tried it on the uinit8_t and it worked! The string reference pages could use a big "do not use" header, as when beginig to learn I'm sure most people will follow these reference instructions before trawling forums and asking questions.
dev_1 May 15, 2016, 8:10pm 7The string reference pages could use a big "do not use" header
Now THAT's a useful post!
Since it wasn't clear, I edited my post to address it to the OP. But thanks for adding your experience. That's so much more convincing than "don't do that."
Cheers, /dev
Related topics
| Topic | Replies | Views | Activity |
|---|---|---|---|
| How to convert uint8_t buffer to a propper String Programming | 9 | 3946 | May 6, 2021 |
| ASCII Char array in uint8 wandeln --> Hex to uint Deutsch | 25 | 190 | November 7, 2025 |
| Conversion from 'uint8_t' {aka 'unsigned char'} to 'String' is ambiguous Programming | 4 | 431 | June 16, 2024 |
| How to convert a substring to uint8_t or int8_t Programming | 5 | 661 | April 9, 2024 |
| Uint8_t to string Programming | 37 | 17413 | February 3, 2023 |
Tag » Arduino Uint8_t Buffer To String
-
How To Convert Uint8_t Buffer To A Propper String - Arduino Forum
-
Convert Uint8_t To String - Programming Questions - Arduino Forum
-
Converting A Uint8_t Buffer To Char Array - Arduino Forum
-
Conversion From ASCII Uint8_t To String - Arduino Stack Exchange
-
Converting Uint8_t To String - Unexpected Result
-
Arduino: Uint8_t Array To String - Stack Overflow
-
Converting Uint8_t Byte Data To A String (ESP-NOW) | All About Circuits
-
Cannot Convert 'string' To 'uint8_t
-
tBytes() | Arduino Reference
-
How To Convert Byte Array To Hexstring Arduino Platform · GitHub
-
Guide To PROGMEM On ESP8266 And Arduino IDE
-
How To Convert A String Into An Uint8_t Array On Arduino?
-
Method That Converts Uint8_T To String - ADocLib
-
Convert Char To Uint8_t Arduino Code Example - Code Grepper