question

Bruno avatar image
Bruno asked

Reading Victron BLE broadcasts with Arduino / ESP32

Hi,

Anyone tried to listen to BLE announcements with and Arduino device like ESP32 ?

I've read about GATT service but can't find any library or demo to start with.

I'd like to read basic indicators from a BMV712 device, or Smartsolar chargers.

Thank you !

Bluetooth Low Energy - BLEarduino
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

7 Answers
theterminalman avatar image
theterminalman answered ·

My first post here!

I've put together a simple (well... kinda) example bit of ESP32 code that receives, decrypts, and decodes the Bluetooth Low Energy advertising beacons from Victron SmartSolar charge controllers. Thanks go to Victron for enabling these beacons and being nice enough to document the data in them.

This doesn't involve GATT services. They might contain more data, but getting to it involves making an actual connection to the SmartSolar - vs just listening to the beacons being broadcast - and I don't know how well the services are documented.

I've posted my sample code on GitHub. Feel free to give it a try to see if it works for you. I'm currently running this on a basic three-for-$20 ESP32 dev module from Amazon.

https://github.com/hoberman/Victron_BLE_Advertising_example

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

theterminalman avatar image
theterminalman answered ·

Extending on this... I've also written code for the very nice M5StickC and M5StickCPlus modules that uses their integrated graphics hardware to display the data obtained from the SmartSolar BLE beacons.

https://github.com/hoberman/Victron_BLE_Scanner_Display

If you don't have an M5 device then you can likely adapt this to work with your favorite ESP32 module and graphics display.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

VAN THUAN avatar image
VAN THUAN answered ·

Bonjour,

I tried your sketch (Victron_BLE_Advertising_example), and I added the reception of data from the Victron Smart BMV712. I managed to obtain the State Of Charge (SOC) encoded on 16 bits, but I can't obtain the battery current (A) encoded on 22 bits. Do you have any ideas ?

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

theterminalman avatar image
theterminalman answered ·

I'm glad to hear you've been able to adapt my code to a different Victron device. I don't have a BMV712 so I'm not able to give you a definitive answer or example code.

Is the problem that you're getting data but are having trouble decoding it? If so, it's often helpful to print out hex dumps of the bytes with your data and then see if you can manually see how to extract the bits you need and combine them to a value you can use.

If the decoding of the data is indeed what's tripping you up, let me know here and I'll try to come up with something that might help.



1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

theterminalman avatar image theterminalman commented ·

Assuming you're having difficulty unpacking the 22-bit value from the decrypted extra manufacturer data sent by the Victron BMV, I've written some example code that demonstrates one way you might be able to make that work. You'll have to integrate that into your general BMV receiver code, but I'm hoping it'll help. Good luck!

https://github.com/hoberman/Victron_BMV_bit_unpacking_example

0 Likes 0 ·
VAN THUAN avatar image
VAN THUAN answered ·

Thank you for this very well-documented response.

I was starting to get a bit desperate about not being able to finish this project. So I will include this code in my sketch to test it. I am hoping to go to the boat next weekend to test it out. I will give you the result.

Kind Regards,

FX

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

VAN THUAN avatar image
VAN THUAN answered ·

Bonjour,

I've adapted your code and inserted it into my sketch, but it's not working; we still get inconsistent data for the Ampères (Current).

11:32:51.472 -> byte0=10100

11:32:51.472 -> byte1=100101

11:32:51.472 -> byte2=0

11:33:02.184 -> byte0=1000100

11:33:02.184 -> byte1=100101

11:33:02.184 -> byte2=0

11:33:06.335 -> byte0=1110100

11:33:06.335 -> byte1=100101

11:33:06.335 -> byte2=0

11:33:14.350 -> byte0=10111100

11:33:14.350 -> byte1=100010

11:33:14.350 -> byte2=0

11:33:17.022 -> byte0=1001100

11:33:17.022 -> byte1=100000

11:33:17.022 -> byte2=0

11:33:25.037 -> byte0=1000000

11:33:25.037 -> byte1=100101

11:33:25.037 -> byte2=0

11:33:34.505 -> byte0=10110100

11:33:34.505 -> byte1=100011

11:33:34.505 -> byte2=0

11:33:38.442 -> byte0=11000100

11:33:38.442 -> byte1=100110

11:33:38.442 -> byte2=0

11:33:39.895 -> byte0=111000

11:33:39.895 -> byte1=100011

11:33:39.895 -> byte2=0

11:33:41.114 -> byte0=11001100

11:33:41.114 -> byte1=100101

11:33:41.114 -> byte2=0


It always gives huge values in Amperes, sometimes positive, sometimes negative.

The explanation probably lies in the details provided by "ashdash" on the Victron forum:

https://community.victronenergy.com/questions/187303/victron-bluetooth-advertising-protocol.html?childToView=278451#comment-278451

I'm not sure I understand everything he indicated, but I'll try to look into it.


Best Regards

FX

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

theterminalman avatar image
theterminalman answered ·

My apologies for taking such a long time to reply to your questions. I don't get notified when someone posts to this thread so I have to remember to check it periodically. But... there are so many projects to work on these days!

Yes, I suspect the problem here is that I misunderstood the way the bytes are laid out (i.e., a big-endian vs little-endian problem) so I have them ordered wrong when I put them together. That, coupled with the way Victron is packing its bits - where things don't line up neatly along 8-bit boundaries - makes things more difficult. And... I don't have a BMV to be able to test out my code.

Assuming that's the case, I've created a revised version of this example code. See:

https://github.com/hoberman/Victron_BMV_bit_unpacking_example_revised

Let me know if that works!

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Related Resources

Additional resources still need to be added for this topic