Black Lives Matter - Action and Equality.
0

Feed randomly offline using MQTT publish
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.

Feed randomly offline using MQTT publish

by Systembolaget on Fri May 01, 2020 4:50 pm

I am using the MQTT library to publish to one of my two test feeds every 20 seconds. I am using a Metro Mini with an AirLift FeatherWing. I am using the MQTT library because the Adafruit IO library does not want work with the AirLift FeatherWing (see other unresolved thread) and Metro or Feather M0 products.

The feed went offline three times over a 24h period and I had to press the Metro Mini's reset button. I received an email alert for the final incident after enabling notifications during the day. I have a signal LED trigger in the code below in case mqtt.connected() fails, but it was not triggered. My WiFi router system log shows no WiFi or ISP interruption. I could not leave my laptop connected to my set-up the whole day to watch the serial output.

What is the best systematic way to troubleshoot this? Ultimately, if I can get this to work, I want to use a Feather M0 RFM69HCW as a packet radio to WiFi bridge to relay remote packet radio node data for tree monitoring to Adafruit IO using the annual subscription.

Many thanks in advance!

Skärmbild 22.17.26.png
Screenshot
Skärmbild 22.17.26.png (80.61 KiB) Viewed 41 times


Code: Select all | TOGGLE FULL SIZE
void MQTT_connect()
{
  // Return to loop() if already connected with MQTT
  if (mqtt.connected())
  {
    return;
  }

  // Store the error message and set the number of retry attempts
  int8_t ret; uint8_t retries = 3;

  // mqtt.connect will return 0 when connected, so if the connection is
  // lost, it retries in five-second intervals
  while ((ret = mqtt.connect()) != 0)
  {
    Serial.println(mqtt.connectErrorString(ret));
    Serial.println("Retry three times five seconds to connect with MQTT");
    mqtt.disconnect();
    delay(5000);
    retries--;

    // Wait here forever; good practice: implement a watchdog timer reset
    if (retries == 0)
      // Indicate MQTT reconnection failure; GRB colour order
      WiFi.setLEDs(0, 128, 0);
    {
      while (1)
        ;
    }
  }

  Serial.println("Connection with MQTT successful");
}

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Re: Feed randomly offline using MQTT publish

by brubell on Mon May 04, 2020 10:48 am

What does your entire code look like?

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

Re: Feed randomly offline using MQTT publish

by Systembolaget on Sun May 10, 2020 4:26 am

Problem seems solved, has run a couple of days without interruption.

Systembolaget
 
Posts: 227
Joined: Wed Mar 08, 2017 1:01 pm

Please be positive and constructive with your questions and comments.