ESP32 BLE gateway dying every X days

Hi, I’ve been having issues with an ESP32 OMG running only a BLE gateway(0.92 release). We have a few Bluetooth devices transmitting in the house and a couple of xiaomi temperature sensors (one classic round, and one square e-ink version), and the gateway keeps dying every 1 – 1.5 days. A reset of the esp32 always solves it but it’s not manageable (is the internal watchdog not supposed to take care of such issue?).

Anyway, since keeping a computer connected to it for dozens of hours to debug the issue isn’t an option, I adapted a little program on an esp8266 to listen on a software serial pin, and write the data from that pin to a log file on an SD card which is accessible through a web server.

It isnt perfect since it missed a character here and there I guess due to timing issues of the software serial, but its readable.

Anyway, I attached this device to the TX pin on the esp32 and let it run until it died after about a day and a half, and then looked at the resulting logs.

First of all, right from the start I see a lot of disconnection messages pretty consistently every ~15 seconds or so:

5/11/2019 23:09:39 abort() was called at PC 0x401d1327 on core 0

Backtrace: 0x4

5/11/2019 23:09:39 mounti·2M¹…

E (31) SPIFFS: mount failed, -10025

failed to m

5/11/2019 23:09:43 *WM: [2] Connection result: WL_CONNECTED

*WM: [3] lastconxresu

……

5/11/2019 23:10:02 Guru Meditation Error: Core 0 panic’ed (LoadProhibited). Excep

5/11/2019 23:10:02 mounting FS…

E (31) SPIFFS: mount failed, -10025

failed to

5/11/2019 23:10:02 *WM: [2] ESP32 event handler enabled

*WM: [2] Connecting as w

5/11/2019 23:10:06 *WM: [2] Connection result: WL_CONNECTED

*WM: [3] lastconxre

………

75/11/2019 23:10:17 mounting FS…

E (31) SPIFFS: mount failed, -10025

failed to

5/11/2019 23:10:17 *WM: [2] ESP32 event handler enabled

*WM: [2] Connecting as w

5/11/2019 23:10:20 *WM: [2] Connection result: WL_CONNECTED

*WM: [3] lastconxresu

Second of all, this is the last record I got on my serial logger before the esp32 stopped working that time:

7/11/2019 14:41:17 Get services data :

1

Pub json into:

home/OpenMQTTGateway_BT

7/11/2019 14:41:27 Processing BLE device data

mi jia data reading

Creating BLE b

So not much to go on there… I can send the entire 9MB log if that helps. I’ve tried this on 2 different esp32 devices – one wemos D1 mini style esp32, and one regular Geekcreit dev board esp32, with the exact same results.

1 Like

Hello,

thanks for this detailled report, from v0.9.2 there was several improvment done on BLE and wifi stability,
would it be possible to test with v0.9.3beta:

Absolutely, I’m on it. Is 10 seconds between scans too frequent? Because decreasing the frequency was going to be my next thing to try

I suggest to begin by the default one 55555s, check the stability, and if OK going down

Hello,

Do you get better stability with v0.9.3 beta and 55s interval ?

Unfortunately i cant get platform.io to work with this release, and arduino IDE isnt working either. probably an issue with the wrong wifi manager library being used but for the life of me i can figure it out. I dont know why theres so much hype over platform.io, it seems to work intermittently.
this is the message i get:

Processing esp32dev-ble (platform: espressif32@1.11.1; board: esp32dev; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Espressif 32 1.11.1 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: toolchain-xtensa32 2.50200.80 (5.2.0), framework-arduinoespressif32 2.10004.191002 (1.0.4), tool-esptoolpy 1.20600.0
(2.6.0)
Converting main.ino
LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF Modes: Finder ~ chain, Compatibility ~ soft
LibraryManager: Installing WiFiManager
UserSideException: Please install Git client from https://git-scm.com/downloads:
File “C:\users\idan.platformio\penv\lib\site-packages\platformio\builder\main.py”, line 151:
env.SConscript(“$BUILD_SCRIPT”)
File “C:\Users\IDAN.platformio\packages\tool-scons\script..\engine\SCons\Script\SConscript.py”, line 541:
return _SConscript(self.fs, *files, **subst_kw)
File “C:\Users\IDAN.platformio\packages\tool-scons\script..\engine\SCons\Script\SConscript.py”, line 250:
exec file in call_stack[-1].globals
File “C:\users\idan.platformio\platforms\espressif32\builder\main.py”, line 210:
target_elf = env.BuildProgram()
File “C:\Users\IDAN.platformio\packages\tool-scons\script..\engine\SCons\Environment.py”, line 224:
return self.method(*nargs, **kwargs)
File “C:\users\idan.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py”, line 140:
_build_project_deps(env)
File “C:\users\idan.platformio\penv\lib\site-packages\platformio\builder\tools\platformio.py”, line 48:
project_lib_builder = env.ConfigureProjectLibBuilder()
File “C:\Users\IDAN.platformio\packages\tool-scons\script..\engine\SCons\Environment.py”, line 224:
return self.method(*nargs, **kwargs)
File “C:\users\idan.platformio\penv\lib\site-packages\platformio\builder\tools\piolib.py”, line 1027:
project.install_dependencies()
File “C:\users\idan.platformio\penv\lib\site-packages\platformio\builder\tools\piolib.py”, line 859:
lm.install(uri)
File “c:\users\idan.platformio\penv\lib\site-packages\platformio\managers\lib.py”, line 301:
force=force,
File “c:\users\idan.platformio\penv\lib\site-packages\platformio\managers\package.py”, line 696:
pkg_dir = self._install_from_url(name, url, requirements, track=True)
File “c:\users\idan.platformio\penv\lib\site-packages\platformio\managers\package.py”, line 483:
vcs = VCSClientFactory.newClient(tmp_dir, url)
File “c:\users\idan.platformio\penv\lib\site-packages\platformio\vcsclient.py”, line 46:
src_dir, remote_url, tag, silent
File “c:\users\idan.platformio\penv\lib\site-packages\platformio\vcsclient.py”, line 61:
self.check_client()
File “c:\users\idan.platformio\penv\lib\site-packages\platformio\vcsclient.py”, line 127:
“Please install Git client from Git - Downloads
================================================= [FAILED] Took 3.73 seconds =================

For arduino ide I’m now adding the necessary libraries in the release page :

You can download them by taking the name of your environment suffixed by “libraries”.

The docs also could give you some help if you haven’t seen the updated version :
https://docs.openmqttgateway.com/upload/arduino-ide.html

Thanks, but unless there was a change in the libraries which you use in 0.9.3 and haven’t in 0.9.2,my libraries should be fine. Just checked again and 0.9.2 still compiles fine for me.
Anyway I’m on my laptop now and platform.io succeeds in compiling on it for some reason so I’m up and running and will update :+1:

So, just a side note since for now the device is running - it seems it no longer gets a battery state from xiaomi Mijia thermometers

strange, my ESP32 with v0.9.3beta is transmitting the battery from the mi jia of my fridge correctly (every 15 minutes approximately):
{"batt":72}

I checked with another mi jia with the same firmware version and it is also ok:
{"batt":100}

The firmware version of the mi jia is the: 1.0.1_0066
According to the mi home app this is the latest version.

It started coming in a few minutes after I posted, but it is more like every 30 minutes, does that make sense? I decreased the search interval from 10 seconds to the default like you suggested if that makes a difference?
IMG_20191118_235558|606x500

Yes it makes sense.

It could, indeed the device decide itself to broadcast its battery state. With a lower frequency you have less chance to catch the battery info. Nevertheless I m not sure that having the battery frequently is necessary. But maybe you have a use case that need it.

Hello @IRo

With some days of hindsight do you find it more stable with the last version ?

Hi, yes it looks very promising so far. 5 days up and seemingly no outages. I don’t know if it’s related to the changes made in the version or the lower scan interval but the device is also much cooler now

1 Like

Hi,first of all, thanks for this nice ESP32 project,

I’m pretty new to platform.io as well as working with esp32’s but been working since long with Python (in EventGhost and others) as well as with Node-RED (javascript)

Anyway, managed to build and upload to the esp32, worked fine. But is there a specific reason why it stops if you increase the scan rate? Currently testing with, and still running,

#define TimeBtw_Read 5000 //define default time between 2 scans
#define Scan_duration 20 //define the time for a scan

When I lowered the values I got unstable operation, I had to restart the esp32

I’m on
0.9.3 beta
PlatformIO Home 3.0.1 Core 4.0.1
ESP-VROM 32

Hi,

Is there a specific need to going down to 5s.
The scan duration last 20s, if you launch the reading every 5s I think you can have some conflict here.
Could you try with:

#define TimeBtw_Read 20000 //define default time between 2 scans
#define Scan_duration 20 //define the time for a scan

Hi again,
I was just testing your project to see how it works and so far looks very good and powerful, I have noticed the huge support for various protocols, really impressive

Well, regarding scan rate, normally you would like to have as fast detection as possible, typically if you enter into a room and want to have automatic lighting control, you would like to avoid waiting for the lamps to turn on

(I have been running a similar application written in Python using GATT services. This runs on a RPi3 and is very fast in detecting when an iBeacon comes into the range)

Thanks! The goal is to avoid having a gateway per brand/protocol which is a totaly waste of money and energy.

In this use cas maybe we have to find the most suitable values for having some kind of continuous scan.

Fully agree!!

I mean I am really impressed what you have achieved, just thinking for the moment of typical use cases where I currently use other solutions, basically my interest is in home automation and home security solutions
Today I use everything from esp32-cams, usb color cameras, rpi’s, rfxcom for 433 rf stuff, z-wave, odroids xu4 & n2 , “old laptops” running debian and the newest member, the Nvidia jetson nano (great for AI and video analytics)

Thanks to a the community effort and a strong base of libraries!

Plenty of stuff to play with :slight_smile: