From f009049016baa7a8219faeeff981a6bf0882a823 Mon Sep 17 00:00:00 2001 From: ladyada Date: Tue, 9 Aug 2016 14:27:30 -0400 Subject: [PATCH] working fona example without progmem --- examples/mqtt_fona/mqtt_fona.ino | 38 ++++++++++++++------------------ 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/examples/mqtt_fona/mqtt_fona.ino b/examples/mqtt_fona/mqtt_fona.ino index ba8f389..183e10c 100644 --- a/examples/mqtt_fona/mqtt_fona.ino +++ b/examples/mqtt_fona/mqtt_fona.ino @@ -25,8 +25,9 @@ /*************************** FONA Pins ***********************************/ -#define FONA_RX 2 -#define FONA_TX 3 +// Default pins for Feather 32u4 FONA +#define FONA_RX 9 +#define FONA_TX 8 #define FONA_RST 4 SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); @@ -52,14 +53,8 @@ Adafruit_FONA fona = Adafruit_FONA(FONA_RST); /************ Global State (you don't need to change this!) ******************/ -// Store the MQTT server, username, and password in flash memory. -// This is required for using the Adafruit MQTT library. -const char MQTT_SERVER[] PROGMEM = AIO_SERVER; -const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME; -const char MQTT_PASSWORD[] PROGMEM = AIO_KEY; - // Setup the FONA MQTT class by passing in the FONA class and MQTT server and login details. -Adafruit_MQTT_FONA mqtt(&fona, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD); +Adafruit_MQTT_FONA mqtt(&fona, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); // You don't need to change anything below this line! #define halt(s) { Serial.println(F( s )); while(1); } @@ -72,11 +67,11 @@ boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *u // Setup a feed called 'photocell' for publishing. // Notice MQTT paths for AIO follow the form: /feeds/ -const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell"; +const char PHOTOCELL_FEED[] = AIO_USERNAME "/feeds/photocell"; Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED); // Setup a feed called 'onoff' for subscribing to changes. -const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff"; +const char ONOFF_FEED[] = AIO_USERNAME "/feeds/onoff"; Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED); /*************************** Sketch Code ************************************/ @@ -124,17 +119,6 @@ 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))) { - if (subscription == &onoffbutton) { - Serial.print(F("Got: ")); - Serial.println((char *)onoffbutton.lastread); - } - } - Watchdog.reset(); // Now we can publish stuff! Serial.print(F("\nSending photocell val ")); @@ -148,6 +132,16 @@ void loop() { txfailures = 0; } + Watchdog.reset(); + // this is our 'wait for incoming subscription packets' busy subloop + Adafruit_MQTT_Subscribe *subscription; + while ((subscription = mqtt.readSubscription(5000))) { + if (subscription == &onoffbutton) { + Serial.print(F("Got: ")); + Serial.println((char *)onoffbutton.lastread); + } + } + // 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."));