@@ -28,9 +28,6 @@ int count = 0;
28
28
29
29
// set up the 'counter' feed
30
30
AdafruitIO_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");
34
31
35
32
void setup () {
36
33
@@ -44,6 +41,8 @@ void setup() {
44
41
}
45
42
46
43
void 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
47
46
Serial.print (" Connecting to Adafruit IO" );
48
47
49
48
// connect to io.adafruit.com -- must be called before any other io calls!
@@ -74,36 +73,35 @@ void handleMessage(AdafruitIO_Data *data) {
74
73
}
75
74
76
75
void 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
82
77
if (millis ()%60000 > 30000 ){
83
78
WiFi.disconnect (); // Wifi will die in the top half of every minute
84
79
delay (300 ); // wait a while for the disaster to show...
85
80
}
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 " );
91
87
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.
92
92
// 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
-
99
93
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
+ }
101
99
Serial.print (" Done\n " );
102
100
103
101
// save count to the 'counter' feed on Adafruit IO
104
102
Serial.print (" sending -> " );
105
103
Serial.print (count);
106
- if (counter->save (count)) Serial.print (" sent!" );
104
+ if (counter->save (count)) Serial.print (" sent! (no proof of receipt) " );
107
105
else Serial.print (" failed to send!" );
108
106
109
107
// Adafruit IO is rate limited for publishing, so a delay is required in
0 commit comments