BeaverUI / ESP32-BluetoothBMS2MQTT

GNU General Public License v3.0
13 stars 3 forks source link

BLE fails with: The characteristic value is: ⸮ #2

Closed febu93 closed 2 years ago

febu93 commented 2 years ago

Hi,

thanks for publishing this repo. It's exactly what I was looking for in the past month. My goal ist to connect to my two Liontron LiFePo4 Batteries with a Xiaoxiang BMS and push data to Home Assistant.

WiFi and MQTT connection is working fine, but the BLE connection fails with: The characteristic value is: ⸮ You can find the full log at the bottom.

Thanks again for your work!

Attempting to connect to WiFi......
Connected
IP address: 192.168.1.112
Starting BLE... done
BLE is not connected, scannig for devices... BLE: found Name: , Address: 56:6f:ef:12:18:6d, manufacturer data: 4c000f02000010064c1ed19053f5, txPower: 12
BLE: found Name: , Address: 73:fa:1d:94:18:ca, manufacturer data: 4c000c0e0087f16594f0ec86cf99f9a23c4110064b1d03e75c48
BLE: found Name: , Address: 20:8d:57:f9:b2:ee, manufacturer data: 4c000906032ac0a801d0
BLE: found Name: , Address: 66:21:83:5f:8a:4b, manufacturer data: 4c001006451d34125248, txPower: 12
BLE: found Name: , Address: 52:50:3b:b5:93:fe, manufacturer data: 4c001007381fcac04aaf78, txPower: 8
BLE: found Name: , Address: 0f:35:df:cd:68:8a, serviceUUID: 0000fd6f-0000-1000-8000-00805f9b34fb
BLE: found Name: , Address: 31:35:43:e6:97:fe, serviceUUID: 0000fd6f-0000-1000-8000-00805f9b34fb
BLE: found Name: , Address: 26:10:20:da:b5:89, manufacturer data: 4c0009060387c0a8b257
BLE: found Name: , Address: 90:dd:5d:a6:e2:ee, manufacturer data: 4c0010050f14b94106, txPower: 12
BLE: found Name: , Address: 60:32:0e:ef:b2:82, manufacturer data: 4c001006051d38723108, txPower: 12
BLE: found Name: , Address: 4b:3f:f0:10:cc:f4, manufacturer data: 4c0010060319bc16af58, txPower: 12
BLE: found Name: 0221130005, Address: a4:c1:38:d4:d3:8a, manufacturer data: 8ad3d438c1a4, serviceUUID: 0000ff00-0000-1000-8000-00805f9b34fb
BLE: found Name: , Address: 4f:f8:fc:5d:a9:c4, manufacturer data: 4c001006051d39dc9f68, txPower: 12
BLE: found Name: 0221130118, Address: a4:c1:38:18:60:b8, manufacturer data: b8601838c1a4, serviceUUID: 0000ff00-0000-1000-8000-00805f9b34fb
finished.
Attempting MQTT connection...connected
Forming a connection to a4:c1:38:18:60:b8
 - Connected to server
 - Found our service
 - Found our characteristic
The characteristic value is: ⸮
Attempting MQTT connection...connected
Attempting MQTT connection...connected
Attempting MQTT connection...connected
BeaverUI commented 2 years ago

Good to hear you like the concept! I hope we can solve your issue. A few things that might help: 1) Does your BMS work with the Xiaoxiang BMS app on Android? Don't use the playstore version, that one is flawed. Instead, get it here: https://www.lithiumbatterypcb.com/Smart%20BMS%20APP%203.1.1021.2.rar If it doesn't work in the Android app, it is unlikely my library will work out of the box, and you will need to adapt it to the protocol of your specific BMS.

2) I notice that MQTT keeps reconnecting, that should not happen. Is something holding up the mqtt.loop() function call?

3) You can enable more extensive debug messages in Arduino by clicking Tools -> Core debug level -> Verbose. The debug messages will be sent through the serial port, you can see them in the serial monitor.

4) I made some improvements to the memory management and BLE handling in the past weeks, I will push them to GitHub soon.

BeaverUI commented 2 years ago

I just pushed the updated library. Note that the connection details have been extended to ensure it connects to the correct device, so you now also need to set the device name ("0221130118" in your case), the device address ("a4:c1:38:18:60:b8"), and the minimum signal strength to ensure a good quality connection (typically something like -85 dB is OK, -90 dB already gives poor performance).

So have a look to my previous post, and check whether the updated library helps. If not, enable verbose core debugging and post your findings, if you like.

febu93 commented 2 years ago

Thanks for your help! Updating the library seems to have fixed my connection issues. I also fixed the mqtt error and now data gets pushed without any issues. great work! I'm really happy with the solution.

As I have two batteries in my system, do you think it would be possible to use one ESP32 to connect to both of them? Or would it just be easier to use two ESP32?

BeaverUI commented 2 years ago

Great to hear! It is definitely possible, but then you'd need a (quite major) rework of the code:

Then just toggle between both BLE routines to consecutively read each BMS. If you figured it out, I'd be happy to include it in the repository (or you can fork this one).