Snprintf - Data Formatting Question/Help

I need to format a Payload before I send it out via a UDP Broadcast.

I’ve used the Snprintf function before in the past with good success but on this new project I’m feeding the Snprintf function with data being held in a char array and I think it needs formatted maybe to work correctly.

The Array I’m pulling Data from is shown below.

Here is a note from the Library creator about pulling the data stored in this array which is in char format and not numbers or floats.

I’m creating a formatted Payload using code like shown below:

I’m wondering if I can just use the snprintf function and the %s formatting code to just use the Char data stored in the Array without needing to convert the data using the ATOI() & ATOF() functions? I do not need to do any math on the data before sending it out so not sure if the conversion from Char to Number is needed if I only need to send it out via a UDP Broadcast message.

So I’m thinking of formatting the payload using the %s for data stored in the Char format but I’m not sure just yet. Wanted some professional feedback on this if possible.


Yes, you can. But a simple try would have provided that answer too :wink:

However, for your massive snprintf() statement in your screenshot above if you were sending that via UDP I’d rather push the data into a struct and transfer that binary.


Great! Thanks for the confirmation.

I didn’t have time to test it before going to bed but wanted some feedback as to if it was recommended or not. I had a good feeling it would work.

1 Like

It worked perfectly just inserting the Char data using %s

Using a Photon and Control Everythings Wiznet Ethernet board I am able to UDP Broadcast the system’s status data.

This is the first time I have ever needed to use Ethernet & UDP so it was a learning experience.