[BLE] Add support for decrypting PVVX, BTHome v2 and Victron BLE frames (#2219)

* Changing WebUI to include display device name, and change it to select drop down rather than checkbox

* Fix mqttDiscovery to require WebUI and ESP32 for displayDeviceName

* Fix mqttDiscovery to require WebUI and ESP32 and ESP8266 for displayDeviceName and ForceDeviceName

* Changing WebUI to include display device name, and change it to select drop down rather than checkbox

* Fixes for WebUI and BT for supporting custom setting Display name

* Fixes for WebUI and BT for supporting custom setting Display name

* Move DISPLAY_DEVICE_NAME to User_config.h

* Update docs to include change for Display temperature

* Update docs to include change for Display temperature

* Fix minor cosmetic bug where devices were not linking in HA to the gateway using via_device as it should be the gateway mac address not name

* Add support for decrypting BTHome v2 frames

* Add support for decrypting BTHome v2 frames

* Add support for decrypting BTHome v2 frames

* BTHome fix issue with theengs-plug

* BTHome fix issue with theengs-plug

* Adding support for all BLE encrypted methods, support in UI and gatewayBT for specific MACAddress AES Keys

* Fix lint

* Fix build issue with theengs-bridge-v11 and esp32dev-all-test and revert the documentation to Units of measurement displayed

* Revert docs

* Revert displayDeviceName and Units of measurement

* Revert displayDeviceName and Units of measurement

* Revert displayDeviceName and Units of measurement

* Revert minor typo

* Revert minor typo

* Revert minor typo

* Bug in Victron as nonce should be 16 bytes

* Shortened the client side javascript for BLE key validation that is commented out due to image constrains on theengs-bridge-v11
This commit is contained in:
Peter Lambrechtsen authored and GitHub committed 2025-08-06 19:59:33 -05:00
1 parent a0d5b7d181
commit 2d29ee4524
7 files changed
+399 -1

No files matched your search

+39
View File
@@ -94,6 +94,12 @@ bool ethConnected = false;
char mqtt_topic[parameters_size + 1] = Base_Topic;
char gateway_name[parameters_size + 1] = Gateway_Name;
unsigned long lastDiscovery = 0;
#ifdef BLEDecryptor
char ble_aes[parameters_size] = BLE_AES;
StaticJsonDocument<JSON_BLE_AES_CUSTOM_KEYS> ble_aes_keys;
#endif
#if !MQTT_BROKER_MODE
ss_cnt_parameters cnt_parameters_array[cnt_parameters_array_size] = CNT_PARAMS_ARR;
#endif
@@ -2022,6 +2028,10 @@ void saveConfig() {
# endif
json["gateway_name"] = gateway_name;
json["ota_pass"] = ota_pass;
# ifdef BLEDecryptor
json["ble_aes"] = ble_aes;
json["ble_aes_keys"] = ble_aes_keys;
# endif
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
@@ -2169,6 +2179,16 @@ bool loadConfigFromFlash() {
}
# endif
}
# ifdef BLEDecryptor
if (json.containsKey("ble_aes")) {
strcpy(ble_aes, json["ble_aes"]);
Log.trace(F("loaded default BLE AES key %s" CR), ble_aes);
}
if (json.containsKey("ble_aes_keys")) {
ble_aes_keys = json["ble_aes_keys"];
Log.trace(F("loaded %d custom BLE AES keys" CR), ble_aes_keys.size());
}
# endif
result = true;
} else {
Log.warning(F("failed to load json config" CR));
@@ -3441,6 +3461,25 @@ void XtoSYS(const char* topicOri, JsonObject& SYSdata) { // json object decoding
mqttSetupPending = true; // trigger reconnect in loop using the new topic/name
}
#ifdef BLEDecryptor
if (SYSdata.containsKey("ble_aes") || SYSdata.containsKey("ble_aes_keys")) {
if (SYSdata.containsKey("ble_aes")) {
strncpy(ble_aes, SYSdata["ble_aes"], parameters_size);
}
if (SYSdata.containsKey("ble_aes_keys")) {
Log.warning(F("Contains ble_aes_keys" CR));
ble_aes_keys = SYSdata["ble_aes_keys"];
} else {
// If no keys are passed clear the object.
StaticJsonDocument<JSON_BLE_AES_CUSTOM_KEYS> jsonBLEBuffer;
ble_aes_keys = jsonBLEBuffer.to<JsonObject>();
}
# ifndef ESPWifiManualSetup
saveConfig();
# endif
}
#endif
#if !MQTT_BROKER_MODE
# ifdef MQTTsetMQTT