Xiaoxiang bluetooth BMS to MQTT with ESP32

Bazz0847

100 µW
Joined
Nov 14, 2018
Messages
8
I created a piece of software that might be useful for some of you. It is able to read the status of Xiaoxiang BMSes (www.lithiumbatterypcb.com) via Bluetooth Low Energy, and then send its status via WiFi to an MQTT broker. You can then use something like Node-RED to have an up to date status of your scooter or e-bike when it is parked in your bike shed or garage, even when you're not near it.

The repository can be found here: https://github.com/BeaverUI/ESP32-BluetoothBMS2MQTT
The software is based on work of others (see README.MD), but there are many fixes and improvements included.

Hardware-wise you will need a board with an ESP32 with Bluetooth and WiFi, and you're good to go. I used this board: https://github.com/LilyGO/T-Koala. Software-wise you will need to have an MQTT broker (e.g. mosquitto) and something to display MQTT messages (e.g. Node-RED). Both can run on a Raspberry Pi. I recommend to use the "node-red-dashboard" library to display status on a nice web-based dashboard.

The code is running stably for a few days now. If I find bugs, I'll update the repository with their fixes.

I hope you like it :D Let me know if you have comments or questions.
 
You are welcome! I hope it finds good use. I updated some minor things on the code today, especially regarding reconnecting.

By the way, my ESP module experiences brown-out sometimes (i.e. undervoltage of the chip). It reboots when its detects a brown out. I removed the reverse polarity protection on the T-Koala ESP board, let's see if this fixes it.
 
Update: yesterday I pushed some updates to GitHub with various improvements and fixes.
 
Hi Bazz, it looks great but the issue I'm having atm is that I cannot find where to put the mqtt username and password.
How do I do this?
Thanks
 
Hi, did you find the solution already? If not, try this:

In main.ino change line 255 from

"if (mqttclient.connect(NODE_NAME)) {"

to

"if (mqttclient.connect(NODE_NAME, "MQTTUSERNAME", "MQTTPASSWORD", false)) {"

Let me know if it works :)
 
Hi I was trying the new version of your code.
I get this error while trying to compile the code.
Are you able to help? Let me know if you need more info from me.

Thanks
Jono

D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino:176:23: error: expected initializer before 'WatchDogTimeoutHandler'
void ARDUINO_ISR_ATTR WatchDogTimeoutHandler()
^
D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino: In function 'void enableWatchdogTimer()':
D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino:169:35: error: 'WatchDogTimeoutHandler' was not declared in this scope
timerAttachInterrupt(wd_timer, &WatchDogTimeoutHandler, true);
^
D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino: At global scope:
D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino:176:23: error: expected initializer before 'WatchDogTimeoutHandler'
void ARDUINO_ISR_ATTR WatchDogTimeoutHandler()
^

exit status 1

Compilation error: expected initializer before 'WatchDogTimeoutHandler'
 
Hi I was trying the new version of your code.
I get this error while trying to compile the code.
Are you able to help? Let me know if you need more info from me.

Thanks
Jono

D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino:176:23: error: expected initializer before 'WatchDogTimeoutHandler'
void ARDUINO_ISR_ATTR WatchDogTimeoutHandler()
^
D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino: In function 'void enableWatchdogTimer()':
D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino:169:35: error: 'WatchDogTimeoutHandler' was not declared in this scope
timerAttachInterrupt(wd_timer, &WatchDogTimeoutHandler, true);
^
D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino: At global scope:
D:\Jono\Downloads\bms\ESP32-BluetoothBMS2MQTT-main\main\main.ino:176:23: error: expected initializer before 'WatchDogTimeoutHandler'
void ARDUINO_ISR_ATTR WatchDogTimeoutHandler()
^

exit status 1

Compilation error: expected initializer before 'WatchDogTimeoutHandler'
I'm getting the same error. Any suggestions? @jonology could you fix the issue?
 
Back
Top