maximkulkin / esp-homekit

Apple HomeKit accessory server library for ESP-OPEN-RTOS
MIT License
1.12k stars 170 forks source link

Problem after power outage #125

Closed mgoeller closed 3 years ago

mgoeller commented 4 years ago

Hi, I'm using your library for a lot of devices - thank you very much for that great piece of coding!

However now after a power outage for the whole house (stormy days in Switzerland ;)) I have three problematic devices (all of the ~20 devices are running exactly the same firmware), that show "no response" in Homekit, are not connected to the WiFi anymore (no ping) and when hooked up to serial show the following continues error message every .5 sec after booting up:

_task_hdl : 3fff0040, prio:14, stack:512
pm_task_hdl : 3ffef930, prio:1, stack:176
frc2_timer_task_hdl:0x3fff3ff8, prio:12, stack:200

ESP-Open-SDK ver: 0.0.1 compiled @ Dec 27 2019 16:32:39
phy ver: 273, pp ver: 8.3

>>> wifi_config: Initializing WiFi config
>>> wifi_config: Connecting to EGHome //EGHome is my WiFi SSID
[W]sec 510 error
[W]sec 510 error
[W]sec 510 error
[W]sec 510 error
[W]sec 510 error
[W]sec 510 error
maximkulkin commented 4 years ago

The error seem to be coming from libmain: looks like it is trying to save wifi data to flash (with verification) and verification fails and then it gets stuck in this loop. Seems like something is wrong with flash chip (or particularly one of last three sectors).

mgoeller commented 4 years ago

Ok thank you, so I guess the flash was damaged with the power outage and there is no possibility then to replace (or write wifi data to another sector?).

EDIT: Very strange, I just erased (!) the flash and reuploaded the same firmware. Now it works and somehow still has the HomeKit pairing and WiFi SSID saved:

`Last login: Mon Feb 17 10:49:58 on ttys000
mailgoe@iMac-5K ~ % esptool.py -p /dev/tty.usbserial-A5XK3RJT erase_flash 
esptool.py v2.7
Serial port /dev/tty.usbserial-A5XK3RJT
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:xxxxxx
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 0.0s
Hard resetting via RTS pin...
mailgoe@iMac-5K ~ % cd ~/Documents/Firmware 
mailgoe@iMac-5K Firmware % esptool.py -p /dev/tty.usbserial-A5XK3RJT --baud 115200 write_flash -fs detect -fm dout -ff 40m 0x0 rboot.bin 0x1000 blank_config.bin 0x2000 main.bin 
esptool.py v2.7
Serial port /dev/tty.usbserial-A5XK3RJT
Connecting......
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:xxxxxx
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 2MB
Flash params set to 0x0330
Compressed 3104 bytes to 2169...
Wrote 3104 bytes (2169 compressed) at 0x00000000 in 0.2 seconds (effective 119.4 kbit/s)...
Hash of data verified.
Compressed 2048 bytes to 23...
Wrote 2048 bytes (23 compressed) at 0x00001000 in 0.0 seconds (effective 1042.3 kbit/s)...
Hash of data verified.
Compressed 465952 bytes to 326248...
Wrote 465952 bytes (326248 compressed) at 0x00002000 in 28.8 seconds (effective 129.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
mailgoe@iMac-5K Firmware % miniterm.py /dev/tty.usbserial-A5XK3RJT 115200 
--- Miniterm on /dev/tty.usbserial-A5XK3RJT  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
�n�␄�|l`␛�pp_task_hdl : 3fff0040, prio:14, stack:512
pm_task_hdl : 3ffef930, prio:1, stack:176
frc2_timer_task_hdl:0x3fff3ff8, prio:12, stack:200

ESP-Open-SDK ver: 0.0.1 compiled @ Dec 27 2019 16:32:39
phy ver: 273, pp ver: 8.3

>>> wifi_config: Initializing WiFi config
>>> wifi_config: Connecting to EGHome
>>> loading settings
mode : sta(cc:xxxxx)
add if0
scandone
add 0
aid 1
cnt 

connected with EGHom�D����␚����с�х�ѹrrj��ip:10.0.1.3,mask:255.255.255.0,gw:10.0.1.1
>>> wifi_config: Connected to WiFi network
>>> Connected to WiFi, starting homekit and telnet...
>>> HomeKit: Starting server
>>> HomeKit: Using existing accessory ID: F7:xxxxx
>>> HomeKit: Found admin pairing with 350D8BAB-5xxxxx, disabling pair setup
>>> HomeKit: Configuring mDNS
mDNS announcement: Name=Lamp FFC5   md=Lamp1␆pv=1.0␔id=F7:FF:D1:F9:C7:96␄c#=1␄s#=1␄ff=0␄sf=0␄ci=8␋sh=Ig1YXA== Port=5556 TTL=4500
>>> HomeKit: Got new client connection: 4 from 10.0.1.2
>>> HomeKit: [Client 4] Pair Verify Step 1/2
>>> HomeKit: [Client 4] Pair Verify Step 2/2
>>> HomeKit: [Client 4] Found pairing with 0E4CF4xxxxxx1
>>> HomeKit: [Client 4] Verification successful, secure session established
>>> HomeKit: [Client 4] Get Accessories

`
AramVartanyan commented 4 years ago

I am having the same issue on multiple devices. I do not think it is related to damaged hardware. It is always happening if the power supply is not stable or if the device is shut down in improper moment. After reflash than erase_flash and second reflash, the same device is up and running again.

AramVartanyan commented 4 years ago

This issue appeared after the update of esp-wifi-config (around September last year).

mgoeller commented 4 years ago

It's good that I am not the only one. I can gladly provide a device and somehow help debugging, but have unfortunately no idea where to start.

peros550 commented 4 years ago

It has happened to me once a few weeks ago. As mentioned, just reflashing kept the stored pairing.

AramVartanyan commented 4 years ago

It has happened to me once a few weeks ago. As mentioned, just reflashing kept the stored pairing.

Yes. That is true, however I have noticed that you cannot erase_flash directly. (Shows 0.0 s and didn't actually erasing anything.) The flash memory falls in a strange state and the erase isn't working before you flash it at least once. So I prefer to do clean flash.

mgoeller commented 4 years ago

Yes. That is true, however I have noticed that you cannot erase_flash directly. (Shows 0.0 s and didn't actually erasing anything.) The flash memory falls in a strange state and the erase isn't working before you flash it at least once. So I prefer to do clean flash.

Interesting that you see the same behaviour there as well. Which device are you using? A Shelly as well? Did you notice the same problem with other ESP8266 based devices?

AramVartanyan commented 4 years ago

I am using Shelly1 and Shelly 2.5 now. Both have the 510 error. Sonoff basic devices I have are with older FW version and they work fine. Maybe I should try to reproduce the issue with them.

luisjimenez6245 commented 4 years ago

Same with me, i have to reset the device wifi config on every shutdown of the device or of my wifi network.

morphix9 commented 4 years ago

I'm using @RavenSystem's ESP-Homekit-devices and have the exact same problem. Is there something new about that?

morphix9 commented 4 years ago

@maximkulkin can we hope on a fix for this issue? It's really painful to re-flash devices after almost every outage ;(