@@ -28,9 +28,6 @@ int count = 0;
2828
2929// set up the 'counter' feed
3030AdafruitIO_Feed *counter = io.feed(" counter" );
31- // https://io.adafruit.com/api/docs/mqtt.html#username-errors
32- // AdafruitIO_Feed *throttles = io.feed("throttle");
33- // AdafruitIO_Feed *errors = io.feed("errors");
3431
3532void setup () {
3633
@@ -44,6 +41,8 @@ void setup() {
4441}
4542
4643void setupIO () {
44+ // these operations are specific the AdafruitIO connection and may be repeated
45+ // if the connection fails. https://github.com/adafruit/Adafruit_IO_Arduino/issues/99
4746 Serial.print (" Connecting to Adafruit IO" );
4847
4948 // connect to io.adafruit.com -- must be called before any other io calls!
@@ -74,36 +73,35 @@ void handleMessage(AdafruitIO_Data *data) {
7473}
7574
7675void loop () {
77-
78- // io.run(); is required for all sketches.
79- // it should always be present at the top of your loop
80- // function. it keeps the client connected to
81- // io.adafruit.com, and processes any incoming data.
76+ // for this test we will disconnect the WiFi and watch how statuses change -- not normal operations
8277 if (millis ()%60000 > 30000 ){
8378 WiFi.disconnect (); // Wifi will die in the top half of every minute
8479 delay (300 ); // wait a while for the disaster to show...
8580 }
86- Serial.print (" \n\n Top of Loop!\n io.status: " );Serial.print (io.status ());
87- Serial.print (" : " ); Serial.print (io.statusText ()); Serial.print (" \n " );
88- Serial.print (" io.networkStatus: " ); Serial.print (io.networkStatus ()); Serial.print (" \n " );
89- Serial.print (" io.mqttStatus: " ); Serial.print (io.mqttStatus ()); Serial.print (" \n " );
90- Serial.print (" WiFi.status: " ); Serial.print (WiFi.status ()); Serial.print (" \n " );
81+ Serial.print (" \n\n Top of Loop!\n " );
82+ Serial.print (" io.status(): " ); Serial.print (io.status ());
83+ Serial.print (" -- " ); Serial.print (io.statusText ()); Serial.print (" \n " );
84+ Serial.print (" io.networkStatus(): " ); Serial.print (io.networkStatus ()); Serial.print (" \n " );
85+ Serial.print (" io.mqttStatus(): " ); Serial.print (io.mqttStatus ()); Serial.print (" \n " );
86+ Serial.print (" WiFi.status(): " ); Serial.print (WiFi.status ()); Serial.print (" \n " );
9187
88+ // io.run(); is required for all sketches.
89+ // it should always be present at the top of your loop
90+ // function. it keeps the client connected to
91+ // io.adafruit.com, and processes any incoming data.
9292 // Here's where we check the network and start over if it has lost connection
93- if (io.status () < AIO_NET_CONNECTED){
94- Serial.print (" Not Net Connected to IO!!! Reconnect!!!\n\n " );
95- count++;
96- setupIO (); // Start IO all over again
97- }
98-
9993 Serial.print (" Calling io.run()..." ); // io.run() will hang if network disconnected 2019-11-16
100- io.run (); // process messages and keep connection alive
94+ if (io.run () < AIO_NET_CONNECTED){
95+ Serial.print (" No Network Connection!!! Reconnect!!!\n " );
96+ count++; // count network restarts
97+ setupIO (); // Start IO all over again
98+ }
10199 Serial.print (" Done\n " );
102100
103101 // save count to the 'counter' feed on Adafruit IO
104102 Serial.print (" sending -> " );
105103 Serial.print (count);
106- if (counter->save (count)) Serial.print (" sent!" );
104+ if (counter->save (count)) Serial.print (" sent! (no proof of receipt) " );
107105 else Serial.print (" failed to send!" );
108106
109107 // Adafruit IO is rate limited for publishing, so a delay is required in
0 commit comments