Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

AIO Dashboard losing feeds from Particle devices over time
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

AIO Dashboard losing feeds from Particle devices over time

by biod101 on Tue Oct 06, 2020 11:31 am

Hello,

I'm having trouble with Adafruit IO maintaining connections with Particle devices over time. I've already posted details regarding this challenge WRT a Particle Argon (https://forums.adafruit.com/viewtopic.php?f=56&t=170153 , and I'm witnessing having similar issues with the Particle Boron.

Troubleshooting original problem: I tried running the code on a Particle Boron instead of an Argon (LTE vs WiFi). By using a telemetry interval of four minutes, the dashboard registered data succesfully for about 5 hours, and then just stopped working. The hosting Particle device is plugged into USB and a battery backup; is operating from downtown Tucson (good cell coverage), and I can ping the device from the Particle Dashboard successfully.

I figured the issue might be that I'm not hosting the data on an AIO-plus account, so I modified the code to post to my plus account rather than my free work account. Here is the dashboard showing the data started registering at about 4:00 pm yesterday when I fired it up, but then abruptly halting at 9:06 pm : https://io.adafruit.com/biod101/dashboards/adeq-alum. Here is the code for posting data to the associated feeds on the plus account:

Code: Select all | TOGGLE FULL SIZE
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_MQTT_SPARK.h"
#include "Adafruit_MQTT.h"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                   // use 8883 for SSL
#define AIO_USERNAME    "XXXX"
#define AIO_KEY         "XXXX"

/************ Global State (you don't need to change this!) ******************/
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);

/****************************** Feeds ***************************************/

// Setup feeds for publishing data

Adafruit_MQTT_Publish alum_count    = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/adeq-field.alum-count");
Adafruit_MQTT_Publish alum_response = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/adeq-field.alum-response");
Adafruit_MQTT_Publish alum_flow     = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/adeq-field.alum-flow");

String body = "Alum Flowed: https://io.adafruit.com/biod101/dashboards/adeq-alum (Scroll down if on a phone.)";

/*************************** Variables ************************************/

int led2 = D7; // little blue LED on your board.

int x = 0; // loop counter, aka "alum_count" for tracking dropped data
int flowOn = 0;

int analogPin = 19; // pin 19 same as A0 on pinout diagram
int sensor = 0;

SYSTEM_THREAD(ENABLED);

void setup()
{
   
  pinMode(led2, OUTPUT);
   
    Serial.begin(115200);
    delay(10);
   
    Serial.println(F("Setup Complete"));
    delay(1000);
   
}

void loop() {

delay(240000); // if I bump this past 120000, posts to Adafruit IO start to fail on Argon
       
               
sensor = analogRead(analogPin);
// sensor = 700;

 if(sensor > 600) {

    alum_count.publish(x++); //increments after publish
    digitalWrite(led2, HIGH);
    if (flowOn == 0) { // first detection of flow
     // Particle.publish("latzko", body, PRIVATE);
     Particle.publish("huth", body, PRIVATE); // this is my webhook; won't work because upon powering on, sets flowOn immediatley to 1. Set delay at beginning to test.
     flowOn = 1;   
    }
 }
 
  else {
    flowOn = 0; // sensor
    digitalWrite(led2, LOW);
  }
   if( mqtt.Update() )
    {
       if (!alum_count.publish(x++)) {
          Serial.println(F("Failed"));
       }
       else {
          Serial.println(F("OK!"));
       }
 
       if (!alum_response.publish(sensor)) {
          Serial.println(F("Failed"));
       }
       else {
          Serial.println(F("OK!"));
       }
       
       if (!alum_flow.publish(flowOn)) {
          Serial.println(F("Failed"));
       }
       else {
          Serial.println(F("OK!"));
       }
  // delay(60000); // don't break Adafruit's servers-- temper your feed or you will be banned!
   }
}   


So the bottom line is this issue is happening with both Argon and Boron devices irrespective of whether I'm on a free or AIO-plus account. The WiFi and cell-signal strength is good for both devices, and I can ping the devices without issue, so my guess is there is a line of code that's missing to keep the connection between these devices and the dashboard alive (?).

I'd like to migrate my agency away from Thingspeak to Adafruit IO and share my results online. I have a video that shows my hardware setup with promising results (https://youtu.be/cJ5NzbJG5Lw?t=785), but if I can't maintain a connection with AIO over time, then the venue is closed.

Thanks in advance for any ideas.

biod101
 
Posts: 138
Joined: Sun Apr 19, 2015 4:21 pm

Re: AIO Dashboard losing feeds from Particle devices over ti

by brubell on Wed Oct 07, 2020 11:05 am

I figured the issue might be that I'm not hosting the data on an AIO-plus account, so I modified the code to post to my plus account rather than my free work account. Here is the dashboard showing the data started registering at about 4:00 pm yesterday when I fired it up, but then abruptly halting at 9:06 pm : https://io.adafruit.com/biod101/dashboards/adeq-alum. Here is the code for posting data to the associated feeds on the plus account:


Your code calls a MQTT.update procedure towards the end of your loop(). It's possible that the broker is disconnecting the device before the device can send a mqtt.update call (which publishes a CONNACK command to the broker).

For reference, our Adafruit MQTT Library examples follow the notation that mqtt.connect/reconnect.update calls occur at the top of the loop():
https://github.com/adafruit/Adafruit_MQ ... t.ino#L115

You may want to add a mqtt.connect (https://github.com/adafruit/Adafruit_MQ ... t.ino#L136) function to ensure the device can reconnect to the network and the mqtt broker.

brubell
 
Posts: 1061
Joined: Fri Jul 17, 2015 10:33 pm

Re: AIO Dashboard losing feeds from Particle devices over ti

by biod101 on Fri Oct 09, 2020 6:46 pm

Thanks so much— looks like I have some work to do! I appreciate the insight- will investigate and post my results here shortly.

biod101
 
Posts: 138
Joined: Sun Apr 19, 2015 4:21 pm

Please be positive and constructive with your questions and comments.