I'm having a moment here. I want to do the same thing with a character array as i'm doing with a string. In the following code snip the string works but how do I get the char array to work?
String allin = "";
char mine[20] = "";
int z = 321;
int x = 546;
int y = 978;
allin = "";
allin = allin + String(" ") + String(z);
allin = allin + String(" ") + String(x);
allin = allin + String(" ") + String(y);
Serial.println(allin);
strcpy(mine,z);
strcat(mine," ");
strcat(mine,x);
strcat(mine," ");
strcat(mine,y);
Serial.println(mine);
I've tried String() and atoi() but can't get it right.
The atoi() function converts a C style string to an integer. Do you perhaps mean the itoa() function that does the reverse ?
Not that by using the sprintf() function no extra conversion is needed. Some Arduino boards support an even easier way to print multiple values using a single function.
My goal is to learn how to use character arrays. I ran into some of the inevitable (so they say) problems of using Strings while porting some code from a Mega to an ESP32. So, my move away from Strings has begun.
Not quite, the integer will only be as many digits as needed (10 will display as "10", not "010"). You will get the same variable-length numbers using atoi() or String.
For a fixed number of digits you need to specify leading 0's and 3 digits:
With the attention I can give it just now, it does seem odd that you would run into problems moving in the direction you did.
So it makes me request that you post as little code as you can write, in the form of a complete we can upload and try it ourselves sketch, that crashes the Esp.
Without context, it is not possible from out here to conclude that you have grabbed the right tiger by the tail.
The one thing I can think of, from that particular code, is if the text is anywhere near 500 characters long and the baud rate is particularly slow the watchdog timer may be timing out. That really would not make sense anyway, since client on an ESP32 shouldn't be going through a serial port.