Good morning everyone,
I hope this message finds you well, yesterday a friend and I decided to take incoming strings such as “#L 80 45 23” and parse the data to where 80, 45, and 23 can be saved into variables and can be sent off in the “Particle.variable()” function. I’ve been working on a solution however for some reason, I’m not getting the numbers I’ve planned out to receive. Can someone help me out, or help me feel in the blanks?
My setup: There is an arduino that is sending “#L (random number set) (random number set) (random number set)” and also " #P (random number set) " through serial using the Serial1 port on the photon. I’m currently using the Stream class to parse this data.
My code so far:
while(Serial1.available() > 0) { // The code is now running through TX/RX
if(Serial1.read() == '#') {
delay(10);
char inbyte = Serial1.read(); // This is where the space is being discared
//Serial.print(inbyte);
int cvt;
int cvtt;
String foundData;
int laneSize = 4;
int LANE[laneSize];
switch(inbyte) {
case 'P':
foundData = Serial1.readStringUntil('\r');
cvtt = foundData.toInt();
break;
case 'L':
for(int i = 0; i < 3; ++i) {
foundData = Serial1.readStringUntil('\r');
cvt = foundData.toInt();
LANE[i] = cvt;
}
Serial.println(LANE[0]);
break;
}
}
}