[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:
1 parent
a0d5b7d181
commit
2d29ee4524
7 files changed
+399
-1
No files matched your search
@@ -27,6 +27,7 @@
|
||||
# include <WebServer.h> // Docs for this are here - https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer
|
||||
# include <WiFi.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_WebContent.h"
|
||||
# include "config_WebUI.h"
|
||||
|
||||
@@ -954,6 +955,94 @@ void handleLO() {
|
||||
server.send(200, "text/html", response);
|
||||
}
|
||||
|
||||
# ifdef BLEDecryptor
|
||||
/**
|
||||
* @brief /BL - Config BLE
|
||||
* T: handleBL: uri: /bl, args: 3, method: 1
|
||||
* T: handleBL Arg: 0, dn=on - Force Device Name
|
||||
* T: handleBL Arg: 1, bk=on - BLE AES Key
|
||||
* T: handleBL Arg: 2, save=
|
||||
*/
|
||||
void handleBL() {
|
||||
WEBUI_TRACE_LOG(F("handleBL: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
WEBUI_SECURE
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject WEBtoSYS = jsonBuffer.to<JsonObject>();
|
||||
|
||||
if (server.args()) {
|
||||
for (uint8_t i = 0; i < server.args(); i++) {
|
||||
WEBUI_TRACE_LOG(F("handleBL Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
||||
}
|
||||
bool update = false;
|
||||
|
||||
if (server.hasArg("save")) {
|
||||
|
||||
// Default BLE AES Key
|
||||
if (server.hasArg("bk")) {
|
||||
WEBtoSYS["ble_aes"] = server.arg("bk");
|
||||
update = true;
|
||||
}
|
||||
|
||||
// Split Custom BLE AES key pair string add to config
|
||||
if (server.hasArg("kp")) {
|
||||
String kp = server.arg("kp");
|
||||
while (kp.length() > 0) {
|
||||
int kpindex = kp.indexOf(' ');
|
||||
if (kpindex == -1) {
|
||||
if (kp.indexOf(':') == 12) {
|
||||
WEBtoSYS["ble_aes_keys"][kp.substring(0, 12)] = kp.substring(13, 45);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (kp.indexOf(':') == 12) {
|
||||
WEBtoSYS["ble_aes_keys"][kp.substring(0, 12)] = kp.substring(13, 45);
|
||||
}
|
||||
kp = kp.substring(kpindex+1);
|
||||
}
|
||||
}
|
||||
update = true;
|
||||
}
|
||||
|
||||
if (update) {
|
||||
Log.warning(F("[BLE] Save Config" CR));
|
||||
String topic = String(mqtt_topic) + String(gateway_name) + String(subjectMQTTtoSYSset);
|
||||
XtoSYS((char*)topic.c_str(), WEBtoSYS);
|
||||
} else {
|
||||
Log.warning(F("[BLE] No changes" CR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build BLE Key Pair string
|
||||
std::string aeskeysstring;
|
||||
JsonObject root = ble_aes_keys.as<JsonObject>();
|
||||
for (JsonPair kv : root) {
|
||||
aeskeysstring += kv.key().c_str();
|
||||
aeskeysstring += ":";
|
||||
aeskeysstring += kv.value().as<const char*>();
|
||||
aeskeysstring += " ";
|
||||
}
|
||||
aeskeysstring.pop_back();
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
|
||||
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Configure BLE").c_str());
|
||||
String response = String(buffer);
|
||||
response += String(ble_script);
|
||||
response += String(script);
|
||||
response += String(style);
|
||||
int logLevel = Log.getLevel();
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_ble_body, jsonChar, gateway_name, ble_aes, aeskeysstring.c_str());
|
||||
response += String(buffer);
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||
response += String(buffer);
|
||||
server.send(200, "text/html", response);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewayLORA
|
||||
# include "config_LORA.h"
|
||||
extern void LORAConfig_fromJson(JsonObject& LORAdata);
|
||||
@@ -1688,6 +1777,10 @@ void WebUISetup() {
|
||||
# endif
|
||||
server.on("/lo", handleLO); // Configure Logging
|
||||
|
||||
# ifdef BLEDecryptor
|
||||
server.on("/bl", HTTP_POST, handleBL); // Configure BLE
|
||||
# endif
|
||||
|
||||
server.on("/rt", handleRT); // Reset configuration ( Erase and Restart )
|
||||
server.on("/favicon.ico", handleFavicon); // Information
|
||||
server.begin();
|
||||
|
||||
Reference in new issue
Block a user