All of my photons publishing to Adafruit.io went down on 4/24/19

All of my Photons stopped publishing to Adafruit.io on 4/24/19. Has anyone else experienced a similar problem?

I believe this may have something to do with the Adafruit.IO broker and the Adafruit MQTT library. Initially I thought it was something on the Particle end, but I notice that one Huzzah (my only non-Photon device) was also not publishing. Following the suggestion of a few Adafruit forum posts, I moved to the Adafruit_IO library from their MQTT library and changed my Huzzah code. It immediately began updating.

Can anyone give me a sense of what I need to do to get my Photons back on Adafruit.io? Included here is a typical code sample for my Photons. I see an Adafruit_IO library in the Particle libraries, but I am not looking forward to updating my software. Any help greatly appreciated. Hoping it’s something simple.

I have a paid adafruit.io account, so I am not data capped.

/*************************************************** 
  Uses the Dallas one-wire temperature sensor connected to D2.  Also connect Vcc to D@ through a 
  4.7k resistor.  3.3V is fine for Vcc. 
 publishes to Adafruit.io
  
 ****************************************************/
#include <OneWire.h>
#include "math.h"
#include "DS18.h"                    // Dallas 1-wire library
#include "Adafruit_MQTT_SPARK.h"
#include "Adafruit_MQTT.h"
SYSTEM_THREAD(ENABLED);
/************************* Adafruit.io Setup *********************************/
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                   // use 8883 for SSL
#define AIO_USERNAME    "xxxomittedxxx"
#define AIO_KEY         "xxxomittedxxx"

/************ Global State ******************/
TCPClient TheClient;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_SPARK   mqtt( &TheClient,   AIO_SERVER,   AIO_SERVERPORT,  AIO_USERNAME,   AIO_KEY);

// Setup data sources
Adafruit_MQTT_Publish   dallasonewiretemperature      =   Adafruit_MQTT_Publish( &mqtt,   AIO_USERNAME "/feeds/dallasonewiretemperature");

DS18 sensor(D2);                      // Dallas One-Wire sensor uses pin D2 with a 4.7k pullup resistor
int newTemp;
int oldTemp = 0;                      // a temperature value that will never be reached
int tempDifferenceNotification = 3;   // the new temperature reading must be at least this different to intiate publishing

// Add "heartbeat" publishing every __ seconds if temperature doesn't change
time_t newTime;
time_t oldTime = 0;                     // January 1, 1970 (in seconds)
int hearbeatTime = 4*60;                // in seconds (delay is four minutes right now)
int x = 5;                              //temporary variable

void setup() {
    mqtt.connect();
}

void MQTT_connect() {
    int8_t ret;
    if (mqtt.connected()) {             // if already connected, return
        return;
    }
    uint8_t retries = 3;                //give it three tries
    while ((ret = mqtt.connect()) != 0) {     // if connected returns 0, NOT 1
        mqtt.disconnect();
        delay(5000);
        retries--; 
        if (retries == 0) {
            //while(1);                   //spin wheels, wait for WDT to take over         
            return;
        }
    }
}

void loop() {
     MQTT_connect();                    //make sure we are connected
     
     if (sensor.read()) {
         // don't publish unless temperature has changed by variable tempDifferenceNotification
         newTemp = int(sensor.fahrenheit());
         
         if (abs(newTemp - oldTemp) >= tempDifferenceNotification) {
            dallasonewiretemperature.publish(newTemp);
            oldTemp = newTemp;
         } else {
             // publish based upon heartbeat if temperature value hasn't changed
             if (abs (int(Time.now()) - int(oldTime)) >= hearbeatTime) {
                 oldTime = Time.now();
                 oldTemp = int(sensor.fahrenheit());   // take a new reading since we are publishing based upon heartbeat
                 dallasonewiretemperature.publish(int(oldTemp));
             }
         }
  // This next block helps debug what's wrong.
  // It's not needed for the sensor to work properly
    } else {
    // Once all sensors have been read you'll get searchDone() == true
    // Next time read() is called the first sensor is read again
    if (sensor.searchDone()) {
           delay(1000);
    }
  }
}

Not sure why you have two MQTT libraries in that code :confused:

What device OS version are you running on your device and which are you targeting with your application?
Since you are using SYSTEM_THREAD(ENABLED) it’s not guaranteed that the WiFi connection is already established when you try to connect to your MQTT broker. Not sure how the library handles that case, but your code should probably consider that case too.
It’s also good practice to free the socket once a loss of connection is detected. Again, this should be done in the library, but double checking with the library and doing it yourself if the library doesn’t would be advisable.

Have you got a link to the Adafruit forum post to get some background on the rationale for their proposed change?

Why do I have two MQTT libraries? Why do I not check for connection establishment or loss? Short answer: I am a terrible programmer and find little joy in the activity. Those are all good questions. Thanks.

My OS? mostly 1.0.1, but also 0.6.2 and 0.6.3. Once I get something working I leave it alone. Probably not the wisest approach.

I don’t have a clear understanding as to what changed in the two Adafruit libraries, the new library Adafruit_IO greatly simplifies the coding requirements, which may have been their motivation. That said, I had to reflash one of their Huzzahs to an earlier firmware version in order to work with their new library. Their recommendation was to connect the photons and electrons to their broker using webhooks.

In the end, powering down and reflashing my photons made them come alive on Adafruit.io. While successful, I am no wiser as to why the problem originated.