more delays - works with feather fona nicely
This commit is contained in:
parent
72b3ce172e
commit
f8518bc6bd
@ -1,4 +1,5 @@
|
||||
#include <Adafruit_SleepyDog.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include "Adafruit_FONA.h"
|
||||
|
||||
#define halt(s) { Serial.println(F( s )); while(1); }
|
||||
@ -7,7 +8,6 @@ extern Adafruit_FONA fona;
|
||||
extern SoftwareSerial fonaSS;
|
||||
|
||||
boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *username, const __FlashStringHelper *password) {
|
||||
Watchdog.enable(8000);
|
||||
Watchdog.reset();
|
||||
|
||||
Serial.println(F("Initializing FONA....(May take 3 seconds)"));
|
||||
@ -25,6 +25,9 @@ boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *u
|
||||
while (fona.getNetworkStatus() != 1) {
|
||||
delay(500);
|
||||
}
|
||||
|
||||
Watchdog.reset();
|
||||
delay(5000); // wait a few seconds to stabilize connection
|
||||
Watchdog.reset();
|
||||
|
||||
fona.setGPRSNetworkSettings(apn, username, password);
|
||||
@ -33,6 +36,9 @@ boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *u
|
||||
fona.enableGPRS(false);
|
||||
|
||||
Watchdog.reset();
|
||||
delay(5000); // wait a few seconds to stabilize connection
|
||||
Watchdog.reset();
|
||||
|
||||
Serial.println(F("Enabling GPRS"));
|
||||
if (!fona.enableGPRS(true)) {
|
||||
Serial.println(F("Failed to turn GPRS on"));
|
||||
@ -42,4 +48,3 @@ boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *u
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -88,22 +88,28 @@ uint8_t txfailures = 0;
|
||||
void setup() {
|
||||
while (!Serial);
|
||||
|
||||
// Watchdog is optional!
|
||||
//Watchdog.enable(8000);
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println(F("Adafruit FONA MQTT demo"));
|
||||
|
||||
|
||||
mqtt.subscribe(&onoffbutton);
|
||||
|
||||
Watchdog.reset();
|
||||
delay(5000); // wait a few seconds to stabilize connection
|
||||
Watchdog.reset();
|
||||
|
||||
// Initialise the FONA module
|
||||
while (! FONAconnect(F(FONA_APN), F(FONA_USERNAME), F(FONA_PASSWORD))) {
|
||||
halt("Retrying FONA");
|
||||
Serial.println("Retrying FONA");
|
||||
}
|
||||
|
||||
Serial.println(F("Connected to Cellular!"));
|
||||
|
||||
Watchdog.reset();
|
||||
delay(3000); // wait a few seconds to stabilize connection
|
||||
delay(5000); // wait a few seconds to stabilize connection
|
||||
Watchdog.reset();
|
||||
}
|
||||
|
||||
@ -118,6 +124,8 @@ void loop() {
|
||||
// function definition further below.
|
||||
MQTT_connect();
|
||||
|
||||
Watchdog.reset();
|
||||
|
||||
// this is our 'wait for incoming subscription packets' busy subloop
|
||||
Adafruit_MQTT_Subscribe *subscription;
|
||||
while ((subscription = mqtt.readSubscription(5000))) {
|
||||
@ -127,6 +135,7 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
Watchdog.reset();
|
||||
// Now we can publish stuff!
|
||||
Serial.print(F("\nSending photocell val "));
|
||||
Serial.print(x);
|
||||
@ -139,10 +148,10 @@ void loop() {
|
||||
txfailures = 0;
|
||||
}
|
||||
|
||||
// ping the server to keep the mqtt connection alive
|
||||
if(! mqtt.ping()) {
|
||||
Serial.println(F("MQTT Ping failed."));
|
||||
}
|
||||
// ping the server to keep the mqtt connection alive, only needed if we're not publishing
|
||||
//if(! mqtt.ping()) {
|
||||
// Serial.println(F("MQTT Ping failed."));
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user