theengs / decoder

Efficient, portable and lightweight library for Internet of Things payload decoding.
https://decoder.theengs.io
GNU General Public License v3.0
122 stars 41 forks source link

B2M encrypted data - Could be decoded? I has the AES Key #559

Closed ayasystems closed 2 months ago

ayasystems commented 2 months ago

Describe the solution you'd like A clear and concise description of what you want to happen.

{
  "id": "C8:FD:19:7C:2E:0F",
  "mac_type": 0,
  "adv_type": 0,
  "name": "Battery Monitor",
  "manufacturerdata": "4c000215655f83caae16a10a702e31f30d58dd82f6415bc164",
  "rssi": -86,
  "txpower": 0,
  "distance": 16.54559,
  "brand": "GENERIC",
  "model": "BM2 Battery Monitor",
  "model_id": "BM2",
  "type": "BATT",
  "track": true,
  "batt": 100,
  "device": "BM2 Tracker"
}

ESPHome is able to decode it with the follow code

        mbedtls_aes_context aes;
        mbedtls_aes_init(&aes);
        unsigned char output[16];
        unsigned char key[16] = { 108, 101, 97, 103, 101, 110, 100, 255, 254, 49, 56, 56, 50, 52, 54, 54, };
        unsigned char iv[16] = {};
        mbedtls_aes_setkey_dec(&aes, key, 128);
        mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_DECRYPT, 16, iv, (uint8_t*)&x[0], output);
        mbedtls_aes_free(&aes);
        if(isnan(((output[2] | (output[1] << 8)) >> 4) / 100.0f)){
        return false;
        }else{
        return ((output[2] | (output[1] << 8)) >> 4) / 100.0f;
        }

Could be used by this decoder in order to be used by mqttopenwateway?

Regards!!

mhaberler commented 2 months ago

that would be absolutely fabulous!

DigiH commented 2 months ago

I assume you are talking about the additional voltage in addition to the current battery level, decoded by Decoder.

The voltage needs to be acquired by connection to the BM6, whereas Decoder can only use and decode freely broadcast advertising data as it currently stands.

The new key already seems to have been posted in a link mentioned in the OpenMQTTGateway thread

https://github.com/1technophile/OpenMQTTGateway/issues/1792

and fetching the voltage for the BM6 would need to be implemented there, the same as the voltage for the BM2 currently is.

Closing as not applicable to Theengs Decoder.

ayasystems commented 2 months ago

I've BM2 not BM6

Seems like data is brodcasted , i'm not sure... some time manufacturerdata exposes diferents values

image

DigiH commented 2 months ago

@ayasystems What are you using Theengs Decoder with to decode the current battery level?

If you are using the latest development version of OpenMQTTGateway you should also already get the voltage of your BM2, but since it is fetched by connection only, the interval it is being fetched is defined by the setting of intervalacts, which defaults to once an hour, so you might just need to wait a bit, or reduce intervalacts.

And you can see that only the lower manufacturerdata is being decoded with the battery level of your BM2 indicating 100 %.