Basic tcp example always returns connection failed on serial [Solved]

This is my standard approach for starting a Serial Connection on a Windows machine. Following this explanation is my Tip's and Tricks post about it. The SPARK_WLAN_Loop() is the function that's called that processes all background tasks when your user code is not running. You can think of the Spark Core as more or less having 3 functions that run in a main() function that also loops. Not necessarily in this order, those functions are:

main() {
  1) setup() - runs only once, then is prevented from running again.
  2) loop() - runs this, then when this ends, #3 is run...
  3) SPARK_WLAN_Loop() - ...then when this ends, #3 is run...
}

Every time your user loop() ends, the SPARK_WLAN_Loop() runs for 5 to 6 milliseconds to keep your Core connected to the Cloud. Then your user loop() runs again, and so on.

If you have a "blocking" loop within your user code such as the while() loop that will run until it receives a character from the Serial port, you need to still processes your background tasks to keep the Core connected to the Cloud. So we just call that task explicitly instead of letting the system call it for us (because it can't do that right now anyway).


That's a great question, but unfortunately I don't have a detailed answer for this one... yet :wink:

1 Like