First of - welcome to the Spark world
Next, if you want to add a code block to your post, try to enclose your code with a line only containing three `
characters before and after the code (see here for more)
Next you need to know that the Core normally needs to keep in touch with the cloud, so you shouldnât have any loops or other actions in your code that may stop the Core from communicating with the cloud for more than five (max. ten) seconds.
So you may rewrite your while
like this
...
while(!Serial1.available())
SPARK_WLAN_Loop(); // ensure to keep in touch with cloud
...
// or better not stay inside loop() at all
...
while (Serial1.available())
{ // only read if there is something available
float val = Serial1.parseFloat();
Serial1.println(val, 2);
Serial1.flush(); // to get rid of any remaining bytes
}
...
But since your serial communication is running async you might get âhalf-transferedâ readings if you only check for the presence of any byte.
To make things safer you should apply some way of start-count-stop checking in addition, to ensure that you actually catch the first and all following bytes of one float but no more than that.
BTW: @BulldogLowell, never check for Serial.available() == 1
! In standard situations youâll have most the time zero or more than one byte in the buffer. Your code should never assume to get only a fix count of bytes - always expect the unexpected or at least be prepared for it.