shmuelzon / esp32-ble2mqtt

A BLE to MQTT bridge running on an ESP32
MIT License
682 stars 108 forks source link

System looses WiFi connection and can not reconnect again. (WiFi AP is stable) #165

Closed mkohns closed 2 years ago

mkohns commented 2 years ago

I tested the below with esp-idf v.4.4 (readme.md) and v.4.4.1 and v.4.4.2. All behave the same

Describe the bug The system does loose WiFi connection although AP is in same room and is functional. After WiFi disconnect, the system does not recover and connect WiFi again. The below log starts with working system (publishing).

I (2938766) BLE2MQTT: Publishing: 24:6f:28:a1:60:56/91bad492-b950-4226-aa2b-4ede9fa42f59/ca73b3ba-39f6-4ab3-91ae-186dc9577d99 = 235,2,0,0
I (2939966) BLE2MQTT: Publishing: 24:6f:28:a1:60:56/91bad492-b950-4226-aa2b-4ede9fa42f59/ca73b3ba-39f6-4ab3-91ae-186dc9577d99 = 236,2,0,0
I (2941166) BLE2MQTT: Publishing: 24:6f:28:a1:60:56/91bad492-b950-4226-aa2b-4ede9fa42f59/ca73b3ba-39f6-4ab3-91ae-186dc9577d99 = 237,2,0,0
I (2942366) BLE2MQTT: Publishing: 24:6f:28:a1:60:56/91bad492-b950-4226-aa2b-4ede9fa42f59/ca73b3ba-39f6-4ab3-91ae-186dc9577d99 = 238,2,0,0
I (2948346) wifi:bcn_timout,ap_probe_send_start
lld_pdu_get_tx_flush_nb HCI packet count mismatch (0, 1)
W (2948356) BT_HCI: DiscCmpl evt: hdl=0, rsn=0x8
W (2948356) BT_APPL: gattc_conn_cb: if=1 st=0 id=1 rsn=0x8
I (2948366) BLE: Connection closed, reason = 0x8
I (2948366) BLE2MQTT: Disconnected from device: 24:6f:28:a1:60:56
I (2950856) wifi:ap_probe_send over, resett wifi status to disassoc
I (2950856) wifi:state: run -> init (c800)
I (2950856) wifi:pm stop, total sleep time: 1723819488 us / 2085223552 us

I (2950856) wifi:new:<7,0>, old:<7,0>, ap:<255,255>, sta:<7,0>, prof:1
I (2950866) WiFi: Disconnected
E (2950866) TRANSPORT_BASE: poll_read select error 113, errno = Software caused connection abort, fd = 57
E (2950876) MQTT_CLIENT: Poll read error: 119, aborting connection
I (2950886) BLE2MQTT: Disconnected from the network, stopping MQTT
I (2950896) MQTT: MQTT client disconnected
I (2950896) MQTT: Disconnecting MQTT client
I (2954006) WiFi: Disconnected
I (2955906) BLE2MQTT: Disconnected from MQTT, stopping BLE
I (2955906) BLE2MQTT: Disconnected from the network, stopping MQTT
I (2955906) MQTT: Disconnecting MQTT client
I (2956536) WiFi: Disconnected
I (2956536) BLE2MQTT: Disconnected from the network, stopping MQTT
I (2956536) MQTT: Disconnecting MQTT client
W (2957136) wifi:m f probe req l=0

W (2957256) wifi:m f probe req l=0

W (2957376) wifi:m f probe req l=0

W (2957496) wifi:m f probe req l=0

W (2957626) wifi:m f probe req l=0

W (2957746) wifi:m f probe req l=0

I (2958106) WiFi: Disconnected
I (2958106) BLE2MQTT: Disconnected from the network, stopping MQTT
I (2958106) MQTT: Disconnecting MQTT client
W (2958106) wifi:m f probe req l=0

W (2958236) wifi:m f probe req l=0

W (2958356) wifi:m f probe req l=0

To Reproduce Steps to reproduce the behaviour:

  1. Flash BLE2MQTT on your device (I used WEMOS Mini ESP32)
  2. Run it and have a notifying BLE device around (I use a self written (KISS) BLE Server with notifications)
  3. Let i run. Error will occur within 1 hour.
  4. WiFi AP, BLE Server are all in one room

Expected behavior WiFi reconnects, MQTT reconnects, BLE reconnects, everything is working again.

Configuration and logs

{
  "network": {
    "wifi": {
      "ssid": "my_sid",
      "password": "my_pass"
    }
  },
  "mqtt": {
    "server": {
      "host": "192.168.178.xxx",
      "port": 1883,
      "username": "my_user",
      "password": "my_pass",
      "client_id": "ESP32_BLE"
    },
    "publish": {
      "retain": false
    },
    "topics": {
      "prefix": "",
      "get_suffix": "/Get",
      "set_suffix": "/Set"
    }
  },
  "ble": {
    "whitelist": ["f0:a1:21:eb:e6:14", "24:6f:28:a1:60:56"]
  }
}
shmuelzon commented 2 years ago

Hey,

Unfortunately, this is one of those issues that plagued this project since the very start. I still have no idea why it's happening but, at some point, I stop getting events from the ESP Wi-Fi library. It seems to be stuck somehow/somewhere. The only thing I have noticed is that it happens more often when Wi-Fi reception is low. Does it also happen within an hour if the ESP32 is closer to the access point?

I'm closing this ticket a duplicate of #68 but feel free to add more information here or there if you think it might help.

Thanks!