Hi All,
I have been hacking on the Smart Shunt BLE protocol using Python and now am stuck hoping there might another python person out here whom might be able to lend some insights on where I am going wrong.
I started off looking at victron_ble app code code base and while it has some wonderful things happening in there. It is an overkill for my needs right now. Also I like to keep all 3rd party modules to a minimum in my personal coding projects.
I was able to pull some parts from the victron_ble code base like the decrypt calls into my code.
Where I am stuck is taking the binary string coming back from Bleak scanner and parsing that down into the smart shunt data points.
I hacked the v_ble code to show me output of the raw, and decrypt data points so I know that my code is giving me the same answers as it and the Victron Connect app.
I take those raw data strings and run it through my code but end coming up different numbers than victron_ble's while parsing the bits
The Victron_ble app uses a Python Module called "construct" to parse that raw advertising data from the shunt. Which is great but support for the code base appears to slacking off or it's very stable and not needing much work these days.
My point being is the "construct" code hurts my head and how it works is so far off my radar that is not something I want depend on for this app that I am working on.
Which is why I am trying to parse the the raw bit string based upon the published Victron white paper protocol start stop bit data points.
I've done lots of parsing but never at the bit level like the white paper defines.
I am taking the long bit string and using python string slicing calls to grab those bits and then using int(bit_string[start:stop], 2) to convert that to an int.
Given all the other parts of my code seems to be working it's obvious my final approach is not working yet.
Anyone out here have any insights on what I might be missing?
To sum it up
I am grabbing the raw data using Bleak's scanner calls to grab the adverting data from the smart shunt,
Running that through the Victron_ble app decrypt code to get that raw binary data decrypted
I then convert that into a hex string
and then into a bit string
Using Python string splicing I am grabbing a series of bits using this snippet doing
int(bit_string[start:stop], 2) to get an int back.
But it's not getting the results back like it should be.
Since I've not worked direct with a bit strings like this before
I have no idea if some other kind bit banging tricks are required to get back the correct bits for the correct results back.
Sorry this has post got a bit long but the whole topic of using Python to hack on Victron BLe based items is pretty thin on the internet.
Thanks for any suggestions or ideas of what I might try to do to get this fully working.
To sum it I feel like code alpha code is about 90 to 95% working using some simple bleak calls to grab the smart shunt data points using Python
It's having to parse that encrypted binary data points into bits that has proven to be a bit of challenge.
Thanks
-Kevin