I am trying to store a string in an array. So, basically, I'm using C to receive data from an esp32 and send data to an esp32. Because an array is three-dimensional, I'll send a data like this:
so this programme output will be like this 00005e0053af| 59_ 1]
and data will be continuously received. I have added a _,|,] for a reference.
While receiving this, I am getting it in char, so every char is coming as a single data.
So I'm using a while loop to store the data I'm getting in a variable. -
char a = char(SerialPort.read());
However, I want to save this character, which is receiving a single piece of data, on a variable as a string .
something like this
00005e0053af
59
1
All the references (_, |,]) I have used for this are to identify when this occurs, stop, and store the result as a string, but I am not getting how to do it. I was doing this, but it wasn't working.
This code is from the receiving end.
String maclist[20][3];
for (int i =0 ;i<20;++i) {
char a = char(SerialPort.read());
if (!(a== '|')) {
datamacuser+=a;
maclist[i][0] = datamacuser;
}else {
break;
}
}
First problem is that you need to use Serial.available() (instead of your for loop), to make sure there are characters to be read from the input buffer