AnthonyKNorman / Xiaomi_LYWSD03MMC_for_HA

Collecting data via Bluetooth from the Xiaomi LYWSD03MMC Temperature Display using ESP32 running Micropython
52 stars 7 forks source link

I need to restart ESP 32 #3

Open carlosriosg opened 4 years ago

carlosriosg commented 4 years ago

I have been testing the board for a few days and I have realized that at least once a day I have to restart the board because it is not sending a signal, … if you find a solution to that, tell me

regards

amovilar commented 4 years ago

Hi, First of all thanks for your work. It´s amazing.

I have the same problem, in max 24 hours dont recieve data, and have to manual reset the board.

It´s possible to implement a board reset every 12 hours (for example)?

Thanks in advance

JABIoT commented 4 years ago

Same here, after setup, following super clear instructions it lasted about 18 hours before I needed to restart the board. ESP32 DEVKIT. Other than that, it works great, awesome job!

AnthonyKNorman commented 4 years ago

Please can you all try the versions now uploaded and let me know how you get on. Thanks

carlosriosg commented 4 years ago

Hi Anthony, I congratulate you on the work you have done yesterday I reloaded the files to ESP32, and it was working correctly for 14 hours, then I stopped sending information, While it was working I found that the information sending was more constant than the previous configuration, but something happens that the system crashes after a few hours

If you need more proof, here we are Thank you

AnthonyKNorman commented 4 years ago

Are you able to copy information from the REPL that shows any errors after the crash?

carlosriosg commented 4 years ago

I think that I will not be able to do it, since it is connected only in a 5v connector.

There is a way to see your device in the ESP Home of HA, It would be great, so you could see the LOG

carlosriosg commented 4 years ago

Anthony, leave running esp32 from the raspberry, now to wait for it to mark an error and send the report

regards

JABIoT commented 4 years ago

I had it working for 48 hours before the need to reset, it is back now. Before the update, it never lasted more than 24 hours.

carlosriosg commented 4 years ago

Hi Anthony, it worked perfect for more than 48 hours connected directly to the Raspberry, but connected to a normal cell phone charging socket only reached 14 hours. What will be the ideal power source for an ESP32?

In some parts of the script I frame some errors like this:

What can be?

thanks for your work

Trying to connect to a4:c1:38:50:6e:17 GAP procedure initiated: connect; peer_addr_type=0 peer_addr=a4:c1:38:50:6e:17 scan_itvl=16 scan_window=16 itvl_min=24 itvl_max=40 latency=0 supervision_timeout=256 min_ce_len=16 max_ce_len=768 own_addr_type=0 self.connected False Trying to connect to a4:c1:38:50:6e:17 Error: Connect [Errno 114] EALREADY self.connected False connected peripheral has disconnected. 65535 255 00:00:00:00:00:00 Trying to connect to a4:c1:38:50:6e:17 GAP procedure initiated: connect; peer_addr_type=0 peer_addr=a4:c1:38:50:6e:17 scan_itvl=16 scan_window=16 itvl_min=24 itvl_max=40 latency=0 supervision_timeout=256 min_ce_len=16 max_ce_len=768 own_addr_type=0 self.connected False Trying to connect to a4:c1:38:50:6e:17 Error: Connect [Errno 114] EALREADY self.connected False connected peripheral has disconnected. 65535 255 00:00:00:00:00:00

carlosriosg commented 4 years ago

Hi Anthony I have been testing your programming for several days with the integration of Xiaomi thermometers in an ESP32, As a conclusion, the device behaves correctly connected directly to the Raspberry but if the ESP32 connected it directly to the same power source of the 2 amp Raspberry, for some reason it loses connection and stops sending data to the mqtt after 24 hours of functioning, It's very strange I wonder if an automatic restart can be integrated into the programming after 20 hours of operation, for example

is this possible to do? The same thing happens to the rest of the chat? stay tuned

Thank you very much for your work WhatsApp Image 2020-08-01 at 19 47 27

JABIoT commented 4 years ago

I can say since the last update, it is working better, I had it working for 2 weeks with no need to restart but then it stops publishing and I need to power cycle to get it going again. I see in the code there is a machine.reset() if it fails to connect to MQTT. While it stops publishing the information (I have 4 Xiaomi) it doesn't seem to restart so I presume it is still connected to MQTT. My question is, without any modification of the existing code on the ESP32, is it possible to launch a command to mimic a lost connection from home assistant? This way I could force a restart when it stops publishing. My other solution would be to setup a D1 Mini with a relay that will power cycle the ESP32 when needed but I think this is overkill.

AnthonyKNorman commented 4 years ago

If you can show me what comes up in the REPL then maybe I can understand what is causing the disconnect.

JABIoT commented 4 years ago

I have a small problem, my esp32 is connected to an AC power and my only computer is a laptop that I need to take to work every day. At this time it stays connected for more than 24-48 hours. Unless I have a way to connect to the ESP without disconnecting it from the AC or is there a saved log that is available?

EDIT: I now have the ESP32 connected to a computer, I expect it will run fine for a number of days, will post back when it fails.

isoinh commented 4 years ago

I'm having similar issue with my thingy. My wireless network is currently a bit flimsy and I don't know is it causing the issue or something else. I just got the logs from the esp and here is what I'm seeing from one full days log:

Unfortunately I don't have exact "stuck" time for you but probably it has been somewhere between 02:00 and 10:00 image

JABIoT commented 4 years ago

From my previous posts, I was under the impression that I had to restart the ESP32 after a day and then I found it worked for over a week or two but now I realized, the ESP stops publishing the Xiaomi values and then after a while it starts again without power cycling the ESP. However, out of the four devices I have, one stopped publishing and it's been a few days now. The Xiaomi is about 10 feet away from the ESP32 in the next room. The other 3 are in same room, one floor down and two floors down. Connecting to the ESP via Putty, this is what come out of the one that I am not getting data from: ` Trying to connect to a4:c1:38:6e:19:6b GAP procedure initiated: connect; peer_addr_type=0 peer_addr=a4:c1:38:6e:19:6b scan_itvl=16 scan_window=16 itvl_min=24 itvl_max=40 latency=0 supervision_timeout=256 min_ce_len=16 max_ce_len=768 own_addr_type=0 self.connected False Trying to connect to a4:c1:38:6e:19:6b Error: Connect [Errno 114] EALREADY self.connected False connected peripheral has disconnected. 65535 255 00:00:00:00:00:00 Trying to connect to a4:c1:38:6e:19:6b GAP procedure initiated: connect; peer_addr_type=0 peer_addr=a4:c1:38:6e:19:6b scan_itvl=16 scan_window=16 itvl_min=24 itvl_max=40 latency=0 supervision_timeout=256 min_ce_len=16 max_ce_len=768 own_addr_type=0 self.connected False Trying to connect to a4:c1:38:6e:19:6b Error: Connect [Errno 114] EALREADY self.connected False connected peripheral has disconnected. 65535 255 00:00:00:00:00:00 Trying to connect to a4:c1:38:6e:19:6b GAP procedure initiated: connect; peer_addr_type=0 peer_addr=a4:c1:38:6e:19:6b scan_itvl=16 scan_window=16 itvl_min=24 itvl_max=40 latency=0 supervision_timeout=256 min_ce_len=16 max_ce_len=768 own_addr_type=0 self.connected False Trying to connect to a4:c1:38:6e:19:6b Error: Connect [Errno 114] EALREADY self.connected False IRQ peripheral connect A peripheral has sent a notify request. 0 54 b'\x86\t3\xbc\x0b' GAP procedure initiated: connection parameter update; conn_handle=0 itvl_min=12 itvl_max=24 latency=0 supervision_timeout=90 min_ce_len=16 max_ce_len=768 Reading Data GATT procedure initiated: read; att_handle=3 .False A gattc_read() has completed. 0 3 b'LYWSD03MMC\x00' self.name LYWSD03MMC length 10 Got LYWSD03MMC GAP procedure initiated: terminate connection; conn_handle=0 hci_reason=19 .connected peripheral has disconnected. 0 0 a4:c1:38:6e:19:6b Name: LYWSD03MMC


` EDIT: Moments after posting above, the Xiaomi started publishing its data, it is like connecting to the ESP via Putty triggered something.