HeimdallMidgard / ESP-32-BLE-Scanner

ESP 32 BLE Scanner for Home Assistant to report Room Presence
GNU General Public License v3.0
38 stars 7 forks source link

Stability issues #9

Closed andriensis closed 3 years ago

andriensis commented 3 years ago

@HeimdallMidgard No core panic with those changes but I haven't tested it for longer than 15-20 minutes.

HeimdallMidgard commented 3 years ago

I just compiled. First 5 scans did work than my ESP paniced again. I didn't see results. Just telemtry beeing send via MQTT and Serial. Now every scan fails. Weird.

andriensis commented 3 years ago

Can you post some logs?

HeimdallMidgard commented 3 years ago

Just deleted my settings from the log. The startup here is chaotic. MQTT starts before Wifi is even connected (We had this fixed earlier on - same for the wifi SSID missing error). But the scanner doesn't show a result most of the time. I guess we are leaking memory somewhere.

Starting...
Loaded /settings.json: [...]
Loaded /devices.json: [...]

Setting up MQTT • 192.168.1.3:1883 • mqtt_user@[...]

WiFi connected

Wifi Errors: 1
Disconnected from WiFi access point
Trying to Reconnect
[E][WiFiSTA.cpp:125] begin(): SSID too long or missing!
WiFi connected successfuly • IP: 192.168.1.43
Scanning...
_____________________________________
Connecting to MQTT
Connected to MQTT
Scanning...
_____________________________________
{ "results_last_scan": "5", "free_heap": "153828", "uptime": "18" }
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x400d2c5d  PS      : 0x00060f30  A0      : 0x800d5f34  A1      : 0x3ffe2850  
A2      : 0x3ffc933c  A3      : 0x3ffe3168  A4      : 0x00000001  A5      : 0x3ffe3dd0
A6      : 0x00000000  A7      : 0x3ffde651  A8      : 0x800d2c5d  A9      : 0x3ffe2810  
A10     : 0x00000000  A11     : 0x00000001  A12     : 0x3ffc29c8  A13     : 0x00000001
A14     : 0x3ffc29c8  A15     : 0x3ff4e0c4  SAR     : 0x00000018  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400012c5  LEND    : 0x400012d5  LCOUNT  : 0xfffffffe

ELF file SHA256: 0000000000000000

Backtrace: 0x400d2c5d:0x3ffe2850 0x400d5f31:0x3ffe28f0 0x400d907e:0x3ffe2930 0x400ddb75:0x3ffe29a0 0x400ddc21:0x3ffe29e0 0x400dde6d:0x3ffe2a00 0x400dc731:0x3ffe2a20 0x400e385a:0x3ffe2a40 0x400d571b:0x3ffe2a60 0x400907d6:0x3ffe2a80

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
andriensis commented 3 years ago

I don't see MQTT connecting before getting the WiFi IP address. But yeah, I guess the SSID being empty and the memory leak issue could be caused by the new variables

andriensis commented 3 years ago

Just an update: I've been doing some tests and today I've left my 3 ESPs at home without any "paired" device and they worked for 10 hours straight (I was checking their uptime on MQTT). As soon as I came home (so they found the paired devices) it started rebooting (core panic). So I guess it could happen for some reason when publishing the found device MQTT data.

I'll test more tomorrow and try to come up with a viable solution.

nashant commented 3 years ago

I think the problem is if(mqttClient.connected()). Everything up to there runs (checked with Serial.println()s) but it doesn't make it past that conditional

Edit: Nope, that's not right.

void sendDeviceMqtt(const char *uuid, const char *name, float distance) {
  Serial.println("Creating mqtt device message");
  char msg[120];
  sprintf(msg, "{ \"id\": \"%s\", \"name\": \"%s\", \"distance\": %f }", uuid, name, distance);
  Serial.println("Created mqtt device message");

Leads to

WiFi connected
WiFi connected successfuly • IP: 172.16.0.195
Setting up MQTT • 172.16.0.23:1883 • @ 

No MQTT User set
Scanning...
_____________________________________
getDeviceName(8959efd0-d362-4983-aa04-4a041dfb7424)
Preparing to send MQTT message
Guru Meditation Error: Core  0 panic'ed (LoadStoreError). Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c3f5  PS      : 0x00060f30  A0      : 0x80126354  A1      : 0x3ffe3160  
A2      : 0x3f400862  A3      : 0x3ffe3600  A4      : 0x0000000b  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3f400862  
A10     : 0x00000041  A11     : 0x3f410f34  A12     : 0x3f410f34  A13     : 0x00000000  
A14     : 0x00000000  A15     : 0xff000000  SAR     : 0x0000001d  EXCCAUSE: 0x00000003  
EXCVADDR: 0x3f400862  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  
nashant commented 3 years ago

Fixed I think.

    if (mqtt.connected())
      sendDeviceMqtt(uuid, name, distance);
    else
      sprintf("Found device %s but MQTT is not connected", name.c_str());

->

    if (mqtt.connected()) {
      sendDeviceMqtt(uuid, name, distance);
    } else {
      char msg[100];
      sprintf(msg, "Found device %s but MQTT is not connected", name.c_str());
      write_to_logs(msg);
    }
nashant commented 3 years ago

Still getting occasional panics. Investigating