Device Disconnecting every 60 seconds

My device is disconnecting every 60 seconds and then re-establishes connection instantly, this is making bucket data very troublesome, I’m not sure perhaps if there is something wrong in the code so I have posted it below.
The debug output in serial shows only a reconnect after 60 seconds.

#define _DEBUG_
#define _DISABLE_TLS_

#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>
#include <LoRa.h>
#include <SoftwareSerial.h>


#define nss D10
#define rst D14
#define dio0 D2

double DO;
double rtd;
#define USERNAME "**"
#define DEVICE_ID "**"
#define DEVICE_CREDENTIAL "**"

#define SSID "**"
#define SSID_PASSWORD "**"

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {

  LoRa.setPins(nss, rst, dio0);
  Serial.begin(115200);
  while (!Serial);
  if (!LoRa.begin(868E6)) {//914E6
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  thing.add_wifi(SSID, SSID_PASSWORD);
}

void loop() {
  //int lora_rssi;
  int packetSize = LoRa.parsePacket();
  if (packetSize)
  {
    Serial.print("packetSize = ");
    Serial.println(packetSize);

    parseLoRaPacket();
  }

}


void parseLoRaPacket() {
  String lora_data;   // String as local variable

  // READ PACKET -> To test, read from Serial instead from LoRa stream
  while (LoRa.available())
  {
    lora_data = LoRa.readString();
    Serial.print(lora_data);

    int strIndex = lora_data.indexOf("TEMP: ");
    if (strIndex > -1)
    {
      int startPos = strIndex + strlen("TEMP: ");
      rtd = lora_data.substring(startPos).toFloat();
      Serial.println(rtd);
      thing["rtd"] >> outputValue(rtd);
    }

    strIndex = lora_data.indexOf("DO: ");
    if (strIndex > -1)
    {
      int startPos = strIndex + strlen("DO: ");
      DO = lora_data.substring(startPos).toFloat();
      Serial.println(DO);
      thing["DO"] >> outputValue(DO);
    }
  }
  //lora_rssi = LoRa.packetRssi();
  //Serial.print("RSSI:");
  //Serial.println(lora_rssi);
  thing.handle();
}

RHBS TEMP: 21.8421.84
packetSize = 28
RSSI:-105
RHBS DO: 1.541.54
[_SOCKET] Connecting to iot.thinger.io:25200
[_SOCKET] Using secure TLS/SSL connection: no
[_SOCKET] Connected!
[THINGER] Authenticating. User: RBS Device: ESPTest
[THINGER] Writing bytes: 39 [OK]
[THINGER] Authenticated
[THINGER] Writing bytes: 19 [OK]
packetSize = 31
RSSI:-105
RHBS TEMP: 21.8421.84
packetSize = 28
RSSI:-105
RHBS DO: 1.541.54
[THINGER] Available bytes: 82
[THINGER] Writing bytes: 8 [OK]
packetSize = 31
RSSI:-105
RHBS TEMP: 21.8421.84
packetSize = 28
RSSI:-106
RHBS DO: 1.551.55
[THINGER] Available bytes: 60
[THINGER] Writing bytes: 8 [OK]
packetSize = 31
RSSI:-106
RHBS TEMP: 21.8321.83
packetSize = 28
RSSI:-106
RHBS DO: 1.541.54
[THINGER] Available bytes: 39
[THINGER] Writing bytes: 8 [OK]
[THINGER] Writing bytes: 20 [OK]
packetSize = 31
RSSI:-106
RHBS TEMP: 21.8321.83
packetSize = 28
RSSI:-106
RHBS DO: 1.551.55
[THINGER] Available bytes: 19
[THINGER] Writing bytes: 8 [OK]
[THINGER] Writing bytes: 20 [OK]
packetSize = 31
RSSI:-106
RHBS TEMP: 21.8221.82
packetSize = 28
RSSI:-108
RHBS DO: 1.551.55
[THINGER] Writing bytes: 20 [OK]
packetSize = 31
RSSI:-108
RHBS TEMP: 21.8221.82
packetSize = 28
RSSI:-107
RHBS DO: 1.551.55
[THINGER] Writing bytes: 20 [OK]
packetSize = 31
RSSI:-106
RHBS TEMP: 21.8121.81
packetSize = 28
RSSI:-106
RHBS DO: 1.551.55
[THINGER] Writing bytes: 20 [OK]
packetSize = 31
RSSI:-107
RHBS TEMP: 21.8121.81
packetSize = 28
RSSI:-106
RHBS DO: 1.541.54
[_SOCKET] Connecting to iot.thinger.io:25200
[_SOCKET] Using secure TLS/SSL connection: no
[_SOCKET] Connected!
[THINGER] Authenticating. User: RBS Device: ESPTest
And repeats this format every 60 seconds.

EDIT: I tried another WiFi connection and it’s now stable, anyone seen this before with specific routers etc?

Hi, you need to call the thing.handle() inside the loop, otherwise it will only connect/reconnect when lora packet arrived.

Moreover, thing["rtd"] >> outputValue(rtd); and thing["DO"] >> outputValue(DO); should be defined in the setup, not in your parseLoraPacket.

No worries, I’ll make the changes you suggested. Appreciate the help :slight_smile:

OK! Let us know how it works after the updates!

I had the same situation… What I did to make the data in the bucket more regular is to code the device so it will upload the data every 5 mins (ie), so it doesnt matter if it renegotiates and connects again, it will try to upload the info every 5 mins, the fact that the bucket is asking for the data to the device is that every time it connects, the bucket ask the values and wil ask again every integer value of the device's online time / data time lapse, but if the device gets reconnected, will ask again and will restart the device's online time.

I hope explained myself.

PD: Please post all related to code and console responses as code, thanks in advance.

Regards