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);
}
}
}