LaZoark / IOT-sensor

Fast and powerful esp8266 IOT sensor with interactive mechanism based on MQTT.
Apache License 2.0
0 stars 0 forks source link

DHT22 sensor freeze bug, Unable to fix even after the REBOOT! #2

Open LaZoark opened 3 months ago

LaZoark commented 3 months ago

NTP check and OTA check was working fine.

The following topic /data shows error and sensor values at the same time, which is very weird...

{
  "t": 26.4,
  "rh": 39.8,
  "err": "Please check the hardware or use <help> & <info> under </cmd> to debug."
}

Also the /state indicated the "sensor":true all the time.

image

LaZoark commented 3 months ago

It seems like the init problem in the JSON object.

JSON Document: https://github.com/LaZoark/IOT-sensor/blob/6808f192d02ca5fafadfa239d696468ac687e24d/src/main_dht11_mqtt.cpp#L116

Since the snippet here always reuse the object.

String sensor_logger(bool state, float temperature, float humidity) {
  if (state) {
    log_doc["t"] = round2(temperature);
    log_doc["rh"] = round2(humidity);
  } else {
    log_doc["err"] = "Please check the hardware or use <help> & <info> under </cmd> to debug.";
  }
    char json_output[measureJson(log_doc) + 1];   // Account for null-terminator, else trailing garbage is returned
    serializeJson(log_doc, json_output, sizeof(json_output));
  return json_output;
}
LaZoark commented 3 months ago

Further observation:
Althought the err occurred, the sensor still worked fine.

image

{
  "node": "esp8266-sensor-3083988EC133",
  "ssid": "ED716-AP",
  "ip": "192.168.50.26",
  "gw": "192.168.50.1",
  "free_heap": 33480,
  "cpu_mhz": 80,
  "pub_ms": 20000,
  "compile": "Jan 20 2024 00:48:11",
  "model": "esp01s_dht22",
  "ver": "1.8.5",
  "boot_ms": 1540187
}

Before the reboot:

image

After the reboot:

image

The issue seems to be fixed.

Let's see if it will break in the future...