homieiot / homie-esp8266

πŸ’‘ ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
http://homieiot.github.io/homie-esp8266
MIT License
1.36k stars 306 forks source link

"Early" crashes with H801 #475

Open luebbe opened 6 years ago

luebbe commented 6 years ago

Hi Folks,

I'm trying to get a H801 up and running with Homie. Using the follwing minimal firmware with current homie developer branch, Homie usually crashes once or twice within the first 20 seconds after a reboot.

#define FW_NAME "homie-minimal"
#define FW_VERSION "1.0.0"

#include <Homie.h>

#define RED_LED_PIN 5

void setup() {
  Homie_setFirmware(FW_NAME, FW_VERSION);

  // H801 is using Serial1
  Serial1.begin(SERIAL_SPEED);
  Homie.setLoggingPrinter(&Serial1);

  Homie.getLogger()
      << endl
      << endl
      << "Device: " << WiFi.hostname() << endl
      << "ChipID: " << ESP.getChipId() << endl
      << "Last reset reason: " << ESP.getResetReason() << endl
      << "Memory size: " << ESP.getFlashChipSize() << " bytes" << endl
      << "Free heap: " << ESP.getFreeHeap() << " bytes" << endl;

  // The green LED on the board is connected to Pin 1, which is also the serial port
  // So we use the red LED for feedback
  Homie.setLedPin(RED_LED_PIN, LOW);
  // Homie.disableLedFeedback();
  Homie.disableResetTrigger();

  Homie.setup();
}

void loop() {
  Homie.loop();
}

Once the firmware "survives" the first 60 seconds, it runs stable from then on. I think it must be an initialization problem, but I have no idea how to track it down.

The typical log output looks like this:

ets Jan  8 2013,rst cause:2, boot mode:(3,3)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v4ceabea9
~ld

Device: ESP_422440
ChipID: 4334656
Last reset reason: External System
Memory size: 1048576 bytes
Free heap: 36528 bytes
πŸ’‘ Firmware homie-minimal (1.0.0)
πŸ”Œ Booting into normal mode πŸ”Œ
{} Stored configuration
  β€’ Hardware device ID: 600194422440
  β€’ Device ID: dg_h801
  β€’ Name: Initial Config
  β€’ Device Stats Interval: 60 sec
  β€’ Wi-Fi:
    β—¦ SSID: onklan
    β—¦ Password not shown
  β€’ MQTT:
    β—¦ Host: 192.168.0.10
    β—¦ Port: 1883
    β—¦ Base topic: homie/
    β—¦ Auth? no
  β€’ OTA:
    β—¦ Enabled? yes
↕ Attempting to connect to Wi-Fi...
βœ” Wi-Fi connected, IP: 192.168.0.122
Triggering WIFI_CONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
βœ” MQTT ready
Triggering MQTT_READY event...
Calling setup function...
γ€½ Sending statistics...
  β€’ Wi-Fi signal quality: 56%
  β€’ Uptime: 3s
β–’@*r*rA(β–’β–’K5β–’Pvβ–’β–’β–’+Pβ–’juβ–’[
                         XMβ–’.β–’β–’v'β–’β–’β–’*E,β–’β–’1β–’β–’Pβ–’β–’!β–’~Aβ–’β–’β–’β–’nβ–’*eβ–’β–’β–’β–’nA,P'β–’β–’nA,P'β–’TrrKβ–’/β–’β–’

Device: ESP_422440
ChipID: 4334656
Last reset reason: Hardware Watchdog
Memory size: 1048576 bytes
Free heap: 36696 bytes
πŸ’‘ Firmware homie-minimal (1.0.0)
πŸ”Œ Booting into normal mode πŸ”Œ
{} Stored configuration
  β€’ Hardware device ID: 600194422440
  β€’ Device ID: dg_h801
  β€’ Name: Initial Config
  β€’ Device Stats Interval: 60 sec
  β€’ Wi-Fi:
    β—¦ SSID: xxxxxxxx
    β—¦ Password not shown
  β€’ MQTT:
    β—¦ Host: 192.168.0.10
    β—¦ Port: 1883
    β—¦ Base topic: homie/
    β—¦ Auth? no
  β€’ OTA:
    β—¦ Enabled? yes
↕ Attempting to connect to Wi-Fi...
βœ” Wi-Fi connected, IP: 192.168.0.122
Triggering WIFI_CONNECTED event...
↕ Attempting to connect to MQTT...
Sending initial information...
βœ” MQTT ready
Triggering MQTT_READY event...
Calling setup function...
γ€½ Sending statistics...
  β€’ Wi-Fi signal quality: 68%
  β€’ Uptime: 1s
γ€½ Sending statistics...
  β€’ Wi-Fi signal quality: 68%
  β€’ Uptime: 61s

my platformio.ini:

[platformio]
env_default = esp01_1m

[common]
serial_speed= 74880
lib_deps =
  https://github.com/marvinroger/homie-esp8266.git

[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
lib_deps = ${common.lib_deps}
build_flags = -Wl,-Tesp8266.flash.1m64.ld -D SERIAL_SPEED=${common.serial_speed}
upload_speed = 230400
monitor_baud = ${common.serial_speed}
monitor_rts = 0
monitor_dtr = 0

This doesn't happen with the same sketch on a D1 mini or an ESP12F. The only difference is serial vs. serial1 and that I call 'Homie.disableLedFeedback()' on the other devices.

Any pointers are greatly appreciated. I can try to backtrack if this doesn't happen with older revisions of Homie.

luebbe commented 6 years ago

And now something weird. When I change loop to print a dot every second, the firmware doesn't crash. (At least it didn't in ten tries). When I comment the "dotty" part out, it crashes again at least once within 20 seconds.

void loop()
{
  Homie.loop();
  unsigned long ms = millis();
  if (ms - lastdot >= 1000UL || lastdot == 0)
  {
    Homie.getLogger() << ".";
    lastdot = ms;
  }
}
luebbe commented 6 years ago

OK, now it crashed once in 20 tries, but without the dots it crashes every time.