-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] Add support for PVVX Encrypted advertising beacon #1555
Comments
+1, I would also like to use the pvvx firmware with encrypted advertising data. I think this would require:
See also #779 |
Hi @ilgrank and @joshuakraemer I assume you are both solely talking about the same above mentioned energy efficient encryption format introduced by PVVX, as there are also two other encrypted formats for these devices. We have just started implementing supporting encrypted formats in Theengs Decoder 1.5.5 , and so far with Theengs Gateway testing the decryption implementation. Would you both mind posting some example encrypted adversing data so I can get started with a decoder, and possibly also allow you to test with Theengs Gateway for verification.? Also stating with which device(s) you are using the PVVX firmware, if not obvious from the data. After the initial testing with Gateway this feature is also planned to be ported to OpenMQTTGateway. Thanks |
That's great news, @DigiH! Yes, I was talking about the encrypted, energy-efficient "custom" format of the pvvx firmware. The format and the decryption algorithm are described here: pvvx/ATC_MiThermometer#94 (comment) I'm using Xiaomi LYWSD03MMC devices. Here is a sample message from Theengs Gateway:
Can you tell me how to enable the advanced data in Theengs Gateway? |
Thanks for the example @joshuakraemer, Theengs Gateway already shows the data when no decoder is found, so all is fine. I'll have a look into it. |
Just to clarify, is your above sample encrypted PVVX format or ATC? Also do you see other messages from your LYWSD03MMC containing
Thanks |
@DigiH, my sample is PVVX format. I'm sorry, it seems the link from above doesn't describe the actual format. The relevant declarations can be found here: https://github.com/pvvx/ATC_MiThermometer/blob/62c246d961dc1bc0e3b23a6087b8ff46c53ac696/src/custom_beacon.h#L49 However, I'm confused by the code. I think the comments giving the byte numbers are wrong. According to the code, the message should consist of 5 bytes header (adv_cust_head_t), 6 bytes data (adv_cust_data_t) and 4 bytes mic. This however doesn't match with the reported service data, which consists of 11 bytes. I only get messages with a uuid of "181a". By the way, I've disabled BLE advertising flags in the firmware configuration. |
That servicedata length difference was confusing me too :) but the uuid part of the header is already being reported separately with Gateway as the servicedatauuid. I was initially still expecting 12 bytes in the actual servicedata to account for that. Possibly I just got distracted by a given example of Therefore I thought you might have had the ATC option plus encrypted selected when flashing, but from what you say you selected PVVX (Custom) with Encrypted Beacon ticked behind, right? So probably best to have a sleep over it and look at it again afresh tomorrow. I'm sure it will all come together :) |
That's exactly what got my in the wrong direction. Looking at it again all is clear now 👍 We'll have more tomorrow … |
Yes, "Advertising type" is "PVVX (Custom)", "AdFlags" is off, "Encrypted beacon" is on. The MiTemperature2 script and the PVVX python interface both decrypt the messages correctly. Relevant code:
However, looking at those sources confuses me even more. There's no counter byte in both, while it's present in the firmware source. @pvvx, could you please clarify the message structure? |
@joshuakraemer I figured out the decryption thanks to your code references, and I was able to decrypt my LYWSD03MMC's advertisements in PVVX custom encrypted beacon format. I'm adding it to Theengs Gateway. After testing we can port this to OpenMQTTGateway too. |
@koenvervloesem That's great, thank you very much! Please keep me informed so I can help with testing. |
So to test this, you need:
Then supply the device address and accompanying bindkey to Theengs Gateway with the --bindkeys argument. This should decrypt and then decode your encrypted advertisements and show your LYWSD03MMC's temperature, humidity and battery percentage. If not, have a look at Theengs Gateway's output for error messages. |
Great, it works for me. I guess the counter byte is not included in the broadcast message? This is an example message from TheengsGateway:
On a side note, it would be nice if development versions of TheengsDecoder and TheengsGateway could be installed directly from git (didn't work for me because setup.py doesn't include a valid version string). |
Thanks for the feedback @joshuakraemer. Do you see any need or advantage for the counter byte being included in the final decrypted and decoded JSON? |
This is actually because decoding decrypted advertisements is implemented as a three-step process:
We could leave the original properties of the encrypted data in the message, or only the counter, but the question is: would you use this counter? Does this have meaning for the unencrypted data? Interesting side note: the other supported encrypted advertisements, from the Shelly Button1, already have a packet ID (which acts as a counter) in their decrypted payload. As for installing the development versions from Git, yes, that's a valid suggestion, I have already been thinking that it would be nice, I'll add it to our roadmap. |
The counter is needed to detect duplicate and counterfeit messages. So yes, I think it would be useful to have it. |
Ok that makes sense. I'll make Gateway publish the properties |
This issue is stale because it has been open for 30 days with no activity. |
This issue was closed because it has been inactive for 7 days since being marked as stale. |
Sorry, I has completely missed this, me bad |
I'd want to avoid telling everyone+their dog what's the temperature in my house 😛
PVVX, the author of the most well-known alternative firmware for the Xiaomi LYWSD03MMC (and most other ATC based sensor) has added some time ago the option to encrypt the advertisement beacons (that have temperature and humidity information among other things),
If I get it correctly, at the moment the encrypted advertising format is not supported by OpenMQTTGateway.. (I've searched all the MD files, but found no mention of it), so I just wanted to ask if there's any chance to add support for it
The text was updated successfully, but these errors were encountered: