Help trying to Serial.Print Chars

I’m adapting some code that was built for the ESP32 and I only have these 2 compile errors left that I need to tackle and I’m needing some help.

Here is the error I’m getting which also has to do with trying to serial print a Char:

Here is the Char Variable:

Here is the function that pushes data into the Char Variable:

Is there an easy way to just Serial Print the Char and String? I looked and I know I’ve gotten over this before but it’s been a while so It’s escaping my mind right now.

What would you guys recommend?

Thanks :spark:

For the first error, before you edited your post, you are using std::string instead of a Particle String. Changing to a String should resolve the error with the Serial.println.

For the second error, the compiler is informing you that there isn’t a form of Serial.println that takes in (char*, int) which is what you’ve got on lines 352 and 355.

Changing the call to Serial.println to just passing in the char array will work, provided that the string is null terminated.

So on lines like 355, simply do the following to print the char array:

Serial.println(tcv_timer);

Also, snprintf is safer than sprintf because you have to specify the maximum number of chars to write, preventing you from accidentally writing beyond the bounds of an array.

1 Like

Yes your right on both counts :grinning:

I figured both of them out before your reply by looking back at my previous project code where I knew I had dealt with this before.

I added .c_str() to Serial.print String variables.

And just as you recommended I removed the 2nd piece of data when trying to Serial.print the Char variables and it works fine now.

All working now thanks to you! :+1:

Your Macro is working perfectly so thanks because that solution was over my head at the moment and allowed me to keep pushing forward vs getting stuck on that one part of the conversion.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.