ESP WebThing Disconnects

Hi,
I designed a webthing in arduino ide with two DS18B20 temperature sensors, they run on one-wire.

The device works fine both on ESP8266 and ESP32 until it suddenly disconnects after circa 3 minutes.

I’m trying to solve this issue for a while now, there is nothing in the gatway logs when the device disconnects. I suspect json buffers maybe? Any input or experience with running multiple sensors on an ESP would be great.

Code Attached:

Temperature_WebThing_Two_Property_March_2020.zip (1.6 KB)

Similar threads:

Thank you, mrstegeman. I checked both of those threads. Seems dead end.

It hangs a minute longer on the new V12 gateway. Disconnects eventualy

Hi Godzilla,

At the beginning I had the same problem and I realized that the problem was in the code, I was able to test several sensors on the same electronic board and the assembly was like this.

  1. PCB 1: 2 relays and a DHT22 sensor
  2. PCB 2: 2 relays and two DHT22 sensors
  3. PCB 3: 4 relays and two DHT22 sensor
  4. PCB 4: 4 relays and a DHT22 sensor

They have been running for 1 month and I have not had any disconnection on the platform.

You can try at the beginning of your code put this line:

#define LARGE_JSON_BUFFERS 1

Maybe it’s a buffers problem, I’m waiting for you to tell me if your problem has been solved.

Hi Crack3r ,
I appreciate you reply so much! I didn’t have much time to work on this project, but this gave me new wind in the sails.
I was suspecting adjusting the JSON buffers, as is sugested somwhere in a WebThing Tutorial. I hope I am using the right libraries.

I tried your suggestion but the device still disconnects

Would you share your code?

Thank you

Hi Godzilla,

Here is the code I am using. I thank “Mrstegeman” for helping me with this when I had problems.


Code:

#define LARGE_JSON_BUFFERS 1

#include <Arduino.h>
#include “Thing.h”
#include “WebThingAdapter.h”
#include “DHT.h”

const char* ssid = “";
const char
password = "
**”;

// minimal change from last sensor reading to
// update our values
const double threshold = 0.1;

const int Rele1 = 2;
const int Rele2 = 4;
// Pin to connect DHT sensor’s data wire (yellow)
const int sensorPin = 14;
DHT dht;
int samplingPeriod = dht.getMinimumSamplingPeriod();

double lastTemperatureValue = 0;

WebThingAdapter *adapter = NULL;

const char* sensorDeviceTypes[] = {“MultiLevelSensor”, “Sensor”, nullptr};
ThingDevice sensor(“device:esp32:DHTSensor”, “Temperatura Comedor”, sensorDeviceTypes);
ThingProperty temperature(“temperature”, “Input pin”, NUMBER, “LevelProperty”);

const char *switchDeviceTypes[] = {“OnOffSwitch”, nullptr};
ThingDevice switch1(“device:esp32:Rele1”, “Rele1”, switchDeviceTypes);
ThingProperty rele1On(“Rele1On”, “Rele1”, BOOLEAN, “OnOffProperty”);
ThingDevice switch2(“device:esp32:Rele2”, “Rele2”, switchDeviceTypes);
ThingProperty rele2On(“Rele2On”, “Rele2”, BOOLEAN, “OnOffProperty”);

void setup(void) {
pinMode(Rele1, OUTPUT);
pinMode(Rele2, OUTPUT);
digitalWrite(Rele1, LOW);
digitalWrite(Rele2, LOW);
Serial.begin(115200);

//sensor type
dht.setup(sensorPin);
Serial.print("Sensor model: ");
Serial.println(dht.getModel());

// Connect to WiFi access point
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay(500);
Serial.print(”.”);
}

// Show connection details
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: “);
Serial.println(WiFi.localIP());
Serial.println(” ");

// create adapter instance
adapter = new WebThingAdapter(“esp32”, WiFi.localIP());

// set up devices and properties
temperature.title = “Temperatura”;
temperature.minimum = dht.getLowerBoundTemperature();
temperature.maximum = dht.getUpperBoundTemperature();
temperature.multipleOf = dht.getNumberOfDecimalsTemperature() == 1 ? 0.1 : 1;
temperature.unit = “degree celsius”;
temperature.readOnly = true;
sensor.addProperty(&temperature);
adapter->addDevice(&sensor);

rele1On.title = “Rele1 On”;
switch1.addProperty(&rele1On);
adapter->addDevice(&switch1);

rele2On.title = “Rele2 On”;
switch2.addProperty(&rele2On);
adapter->addDevice(&switch2);

// Start HTTP server
adapter->begin();
Serial.println(“HTTP server started”);
Serial.print(“http://”);
Serial.print(WiFi.localIP());
}

void loop(void) {
delay(samplingPeriod);

// check relay values
bool on1 = rele1On.getValue().boolean;
digitalWrite(Rele1, on1 ? HIGH : LOW);
bool on2 = rele2On.getValue().boolean;
digitalWrite(Rele2, on2 ? HIGH : LOW);

// update temperature value
float temperatureVal = dht.getTemperature();
double temperatureValDouble = (double) temperatureVal;
if (abs(temperatureValDouble - lastTemperatureValue) >= threshold) {
Serial.print("log: Temperature: ");
Serial.print(temperatureValDouble);
Serial.println(“°C”);
ThingPropertyValue temperatureLevelValue;
temperatureLevelValue.number = temperatureValDouble;
temperature.setValue(temperatureLevelValue);
lastTemperatureValue = temperatureValDouble;
}

adapter->update();
}


I hope you can get an idea of ​​how it is written and that it works for you.

I await your answer if it worked for you.