[SOLVED] Issue converting a string to a buffer for UDP messaging

So, I’m trying to write a program that utilizes UDP (I am aware of the problems), but I am having trouble converting a string to a buffer so I can send the message.

Currently, I have something that looks like this:

String msgS = String(value, ", tempF");
char msgB[512];          ^ 
msgS.getBytes(msgB, 512) |
                (this is an integer)

And then I get this error:

33:28: error: invalid conversion from 'char*' to 'unsigned char*' [-fpermissive]

Any help would be great!

The String getBytes method takes an unsigned char buffer type to copy into. Also 512 is very large and uses probably 10-25% of your available RAM.

1 Like

To add to @bko’s comment, you’d need to alter your declaration to unsigned char msgB[512]; or you’ll need a type cast msgS.getBytes((unsigned char*)msgB, 512);

1 Like

Thanks so much! I did try to make it an unsigned char, but for some reason that didn’t work, but typecasting did! I really appreciate the help, this has been eating at me for a while.

1 Like