I have a MKR1010 connected to IoT Cloud. I have some sensors connected to it which will give a 'true' or 'false' on my dashboard.
Problem is, if I lose my internet connection or it loses connection to cloud the true/false on my dashboard will be the one that was last active. Then I can't trust the result. I would like to have an alert or a opportunity to see if it is connected or not. Is this possible?
Why not use the network connection callback to determine if network connected and do the thing when disconnected?
For instance the WiFi API has all these things it can detect:
void WiFiEvent(WiFiEvent_t event)
{
log_i( "[WiFi-event] event: %d\n", event );
switch (event) {
case SYSTEM_EVENT_WIFI_READY:
log_i("WiFi interface ready");
break;
case SYSTEM_EVENT_SCAN_DONE:
log_i("Completed scan for access points");
break;
case SYSTEM_EVENT_STA_START:
log_i("WiFi client started");
break;
case SYSTEM_EVENT_STA_STOP:
log_i("WiFi clients stopped");
break;
case SYSTEM_EVENT_STA_CONNECTED:
log_i("Connected to access point");
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
log_i("Disconnected from WiFi access point");
break;
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
log_i("Authentication mode of access point has changed");
break;
case SYSTEM_EVENT_STA_GOT_IP:
log_i ("Obtained IP address: %s", WiFi.localIP() );
break;
case SYSTEM_EVENT_STA_LOST_IP:
log_i("Lost IP address and IP address is reset to 0");
// vTaskDelay( 5000 );
// ESP.restart();
break;
case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
log_i("WiFi Protected Setup (WPS): succeeded in enrollee mode");
break;
case SYSTEM_EVENT_STA_WPS_ER_FAILED:
log_i("WiFi Protected Setup (WPS): failed in enrollee mode");
// ESP.restart();
break;
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
log_i("WiFi Protected Setup (WPS): timeout in enrollee mode");
break;
case SYSTEM_EVENT_STA_WPS_ER_PIN:
log_i("WiFi Protected Setup (WPS): pin code in enrollee mode");
break;
case SYSTEM_EVENT_AP_START:
log_i("WiFi access point started");
break;
case SYSTEM_EVENT_AP_STOP:
log_i("WiFi access point stopped");
// WiFi.mode( WIFI_OFF);
// esp_sleep_enable_timer_wakeup( 1000000 * 2 ); // 1 second times how many seconds wanted
// esp_deep_sleep_start();
break;
case SYSTEM_EVENT_AP_STACONNECTED:
log_i("Client connected");
break;
case SYSTEM_EVENT_AP_STADISCONNECTED:
log_i("WiFi client disconnected");
break;
case SYSTEM_EVENT_AP_STAIPASSIGNED:
log_i("Assigned IP address to client");
break;
case SYSTEM_EVENT_AP_PROBEREQRECVED:
log_i("Received probe request");
break;
case SYSTEM_EVENT_GOT_IP6:
log_i("IPv6 is preferred");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
log_i("Obtained IP address");
break;
default: break;
}
}
for which code could be written to respond to those things.
wildbill:
You need the smarts on your dashboard - show true or false unless the data is too old, then grey the thing out.
I'm not sure I understand.
Will it have something to do with this?
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
If the MKR1010 has lost access to the internet, the only place you can do anything about it is on the dashboard. I was suggesting that you make the dashboard smart enough to notice that the data it has is old and therefore cannot be trusted.