I have developed a small board using an ESP32 CYD to monitor my RV levels etc . I am reading the TPMS sensors, Gas level, water level and battery voltage via BLE. I am battling with the Victron charger though. I would like to read the voltage, current and status. I know the data is encrypted, and I have my AES key, but the data seems to be garbage. Has anyone managed to read and decrypt the advertised data from rhe Blue Smart charger, or is their any were I can get more info on the BSC. I know its has been done for other products, but cannot find anything on the smart charger.
Hi,
Do you have some example data, the AES key and some simplified code that you are using to decode the data? I can then take a look at what is going wrong.
With kind regards,
Thiemo van Engelen
Good Day Thiemo
Thank you for your reply.
I have in the meantime managed to decode the data, and get the voltage, status and error bytes, but the current seems to be a problem still.
(I used some sample code from another Victron Project for the decoding)
Below are a few decrypted strings(I am not sure if this is 100% correct, but I get the correct voltage in bytes 2 and 3. I assume but 0 is the status and byte 1 is the error code.
Byte 4 I think is the current, but is looks as if it is using byte 3 and 4 – but I am still trying to figure this out.
HEX: 6 0 46 45 0 FF FF FF FF FF FF FF FF 0 0 0 44 52 0 0 0 0 0
HEX: 6 0 46 45 0 FF FF FF FF FF FF FF FF 0 0 0 45 52 0 0 0 0 0
HEX: 6 0 49 45 3 FF FF FF FF FF FF FF FF 0 0 0 47 52 0 0 0 0 0
HEX: 6 0 48 45 4 FF FF FF FF FF FF FF FF 0 0 0 48 52 0 0 0 0 0
HEX: 6 0 48 45 4 FF FF FF FF FF FF FF FF 0 0 0 48 52 0 0 0 0 0
HEX: 6 0 45 5 0 FF FF FF FF FF FF FF FF 0 0 0 4A 52 0 0 0 0 0
I have attached a file with my AES key, as well as my call back function –
Please let me know should you need any additional information. If you need the full compiled sketch, please let me know.
Best Regards
Erie
(attachments)
Victron BSC IP22.docx (17.6 KB)
Hi,
Let me take the third line of data as example:
6 0 49 45 3 FF FF FF FF FF FF FF FF 0 0 0 47 52 0 0 0 0 0
What I find useful myself when analyzing the data by hand is to write the bytes right to left and then start taking data from the right. The reason is that data is taken from the lowest bit of the first byte, moving towards the highest bit of the last byte.
In this case, the reverse byte array becomes:
00 00 00 00 00 52 47 00 00 00 FF FF FF FF FF FF FF FF 03 45 49 00 06
Then start taking data from the right of this byte array.
- 8 bits Device State =>
x06 - 8 bits Charger Error =>
x00 - 13 bits Battery Voltage 1 =>
x0549(the right most 13 bits ofb0100010101001001 / x4549) = 1353 = 13.53V - 11 bits Battery current 1 =>
b00000011010 = x01C(the left most 11 bits ofb0000001101000101 / 0x0345= 28 = 2.8A
Everything else is 0xFF, so that means that it does not have a valid value, which makes sense for this charger.
So looking into the code, the voltage calculation is missing 1 bit. You mask outputData[3] with 0x0F00, while it should be 0x1F00 to use all 13 bits. The following is a bit more clear on which bits are used in total for calculating the voltage:
(((outputData[3] << 8) | outputData[2]) & 0x1FFF) * 0.01
Then the current. This can be calculated using:
((((outputData[4] << 8) | outputData[3]) >> 5) & 0x7FF) * 0.1
Another thing in the code is that you say that the BLE spec has a max of 31 bytes, but this is for the complete advertisement, including the vendorID, beaconType and so on. The victronEncryptedData can only be 16 bytes long. This also removes some nonsense data at the end.
I hope this makes it a bit more clear.
With kind regards,
Thiemo van Engelen
Thank you so much Thiemo
That makes prefect sense. I had a suspicion that the voltage and current is using part of the 3rd byte each but could not figure it out yet. I am sure this will also sort the nonsense data I get every now and then.
Thank you for making it clear.
Best Regards
Erie