BuilderKit firmware may stuck in connect

The BuilderKit firmware as of May 03, 2016, may stuck in connect() function if WiFi is bad.

  while (WiFi.status() != WL_CONNECTED) {

This code invokes WiFi.begin once, and then waits for WiFi to become connected.
However, per WiFi.status() docs, the status may become WL_CONNECT_FAILED “when the connection fails for all the attempts”.
Arduino example code places the WiFi.begin line inside the loop, so that the WiFi stack can retry connection indefinitely.

  device.connectSecure(wifiClient, LOSANT_ACCESS_KEY, LOSANT_ACCESS_SECRET);
  while(!device.connected()) {

This code starts a connection to Losant, and then wait for it to become connected.
If WiFi becomes disconnected at this point, it’s impossible to get connected to Losant, and the code is stuck in this loop.
To resolve this issue, check for WiFi connectivity inside the loop, and return if WiFi get disconnected. After returning, the next loop() will invoke connect() to try again.

Hi @nguyenvan_caoky,

Thanks for reaching out with this information :smile: This code is a bit out of date as we no longer distribute Losant builder kits, but I will pass this along as it could also be pertinent to other code libraries.

Thank you for your thorough description and links, they are quite helpful!


1 Like