Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
70c992f
Changing WebUI to include display device name, and change it to selec…
plambrechtsen Aug 3, 2025
5f20c72
Fix mqttDiscovery to require WebUI and ESP32 for displayDeviceName
plambrechtsen Aug 3, 2025
df1d711
Fix mqttDiscovery to require WebUI and ESP32 and ESP8266 for displayD…
plambrechtsen Aug 3, 2025
90f1360
Changing WebUI to include display device name, and change it to selec…
plambrechtsen Aug 3, 2025
8fb8f41
Fixes for WebUI and BT for supporting custom setting Display name
plambrechtsen Aug 3, 2025
9817461
Fixes for WebUI and BT for supporting custom setting Display name
plambrechtsen Aug 3, 2025
966c234
Move DISPLAY_DEVICE_NAME to User_config.h
plambrechtsen Aug 3, 2025
56f1bb2
Update docs to include change for Display temperature
plambrechtsen Aug 3, 2025
f9df090
Update docs to include change for Display temperature
plambrechtsen Aug 3, 2025
6ff9d61
Fix minor cosmetic bug where devices were not linking in HA to the ga…
plambrechtsen Aug 3, 2025
047cfc3
Merge branch 'development' into displaydevicename
plambrechtsen Aug 6, 2025
51a7525
Roll back displayMetric and gateway_mac to separate this out to just …
plambrechtsen Aug 6, 2025
8654f57
Add displayDeviceName as a config variable.
plambrechtsen Aug 7, 2025
d72ea57
Merge branch 'development' into displaydevicename
plambrechtsen Aug 7, 2025
667c3dc
Disable stateBTMeasures(false) as it casues a segfault
plambrechtsen Aug 9, 2025
d71cef5
Update docs for displayDeviceName
plambrechtsen Aug 9, 2025
d30a59d
Merge branch 'development' into displaydevicename
plambrechtsen Aug 10, 2025
94dda15
Add support to properly decode LYWSD03MMC/MJWSD05MMC, also adding RSSI
plambrechtsen Aug 10, 2025
b838e1b
Disable stateBTMeasures(false)
plambrechtsen Aug 10, 2025
43280c9
Fix typo with entity_name for device discovery
plambrechtsen Aug 10, 2025
5587c49
Add support for LYWSD03MMC as a DiscoveryFromList
plambrechtsen Aug 10, 2025
471839c
Add support for LYWSD03MMC as a DiscoveryFromList
plambrechtsen Aug 10, 2025
f63ccbf
Adjust voltage to not come in PVVX ENCR payloads
plambrechtsen Aug 10, 2025
b350e73
Revert format change
plambrechtsen Aug 10, 2025
66ee03d
Add support for a generic xxWSD0xMMCDiscovery List
plambrechtsen Aug 10, 2025
6b5dd39
Add support for a generic xxWSD0xMMCDiscovery List
plambrechtsen Aug 10, 2025
4cd4a82
Merge branch 'development' into displaydevicename
plambrechtsen Aug 13, 2025
f073611
Adjust stack size and disabled code
plambrechtsen Aug 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/use/displays.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ As the display Metric setting is being defined in the WebUI part of OpenMQTTGate

`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoWebUI/config -m {"displayMetric":false}`

### Display name as advetised Bluetooth name or `model_id`
There is a build property of ForceDeviceName which forces devices when they are added in Home Assistant auto-discovery to be created with their Bluetooth advertised name isntead of their `model_id`. The default naming is `model_id` with `{"displayDeviceName":true}`. If you have enabled auto-discovery then a restart is required.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo instead


This can also be adjusted in the WebUI by switching the Configure WebUI Device naming between `Model ID` (false) or `Device name` (true)

This can also be changed with the runtime command.

`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoWebUI/config -m {"displayDeviceName":true}`

### Rotating the display by 180 degrees

This can be set with the compiler directive `-DDISPLAY_FLIP=false`.
Expand Down
2 changes: 1 addition & 1 deletion docs/use/webui.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Ability to change the mqtt settings, if the change is unsuccessful it will rever

## WebUI

Ability to change the display of sensor to Metric or Imperial, and disable the WebUI Authentication
Ability to change the display of sensor to Metric or Imperial, display the device name as the Bluetooth advertised device name or the model id and disable the WebUI Authentication

## Bluetooth Low Energy - BLE

Expand Down
1 change: 1 addition & 0 deletions main/TheengsCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ extern bool ready_to_sleep;
extern char mqtt_topic[];
extern char gateway_name[];
extern unsigned long lastDiscovery; // Time of the last discovery to trigger automaticaly to off after DiscoveryAutoOffTimer
extern bool displayDeviceName;

#if BLEDecryptor
extern char ble_aes[];
Expand Down
5 changes: 5 additions & 0 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ extern ss_cnt_parameters cnt_parameters_array[];
# define LOG_LEVEL LOG_LEVEL_NOTICE
#endif

/*-------------------DEFINE DISPLAY NAME-------------------*/
#ifndef DISPLAY_DEVICE_NAME
# define DISPLAY_DEVICE_NAME false // Set to true to force the device name to be from the name of the device and not the model
#endif

/*-------------------ESP Wifi band and tx power ---------------------*/
//Certain sensors are sensitive to Wifi which can cause interference with their normal operation
//For example it can cause false triggers on a PIR HC-SR501
Expand Down
2 changes: 1 addition & 1 deletion main/config_WebContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const char config_gateway_body[] = body_header "<fieldset class=\"set1\"><legend
#endif
const char config_logging_body[] = body_header "<fieldset class=\"set1\"><legend><span><b>OpenMQTTGateway Logging</b></span></legend><form method='get' action='lo'><p><b>Log Level</b><br><select id='lo'><option %s value='0'>Silent</option><option %s value='1'>Fatal</option><option %s value='2'>Error</option><option %s value='3'>Warning</option><option %s value='4'>Notice</option><option %s value='5'>Trace</option><option %s value='6'>Verbose</option></select></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;

const char config_webui_body[] = body_header "<fieldset class=\"set1\"><legend><span><b>Configure WebUI</b></span></legend><form method='get' action='wu'><p><b>Display Metric</b><br><input id='dm' type='checkbox' %s></p><p><b>Secure WebUI</b><br><input id='sw' type='checkbox' %s></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;
const char config_webui_body[] = body_header "<fieldset class=\"set1\"><legend><span><b>Configure WebUI</b></span></legend><form method='get' action='wu'><p><b>Display Metric</b><br><input id='dm' type='checkbox' %s></p><p><b>Device naming</b><select id='dn'><option %s value='0'>Model ID</option><option %s value='1'>Device Name</option></select></p><p><b>Secure WebUI</b><input id='sw' type='checkbox' %s></p><br><button name='save' type='submit' class='button bgrn'>Save</button></form></fieldset>" body_footer_config_menu;

const char config_rf_body[] = body_header
"<fieldset class=\"set1\">"
Expand Down
21 changes: 13 additions & 8 deletions main/gatewayBT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ void setupBTTasksAndBLE() {
# if defined(USE_ESP_IDF) || defined(USE_BLUFI)
14500,
# else
9500, /* Stack size in bytes */
10500, /* Stack size in bytes */
# endif
NULL, /* Task input parameter */
2, /* Priority of the task (set higher than core task) */
Expand Down Expand Up @@ -955,11 +955,11 @@ void launchBTDiscovery(bool overrideDiscovery) {
Log.trace(F("properties: %s" CR), properties.c_str());
std::string brand = decoder.getTheengAttribute(p->sensorModel_id, "brand");
std::string model = decoder.getTheengAttribute(p->sensorModel_id, "model");
# if ForceDeviceName
if (p->name[0] != '\0') {
model = p->name;
if (displayDeviceName || ForceDeviceName) {
if (p->name[0] != '\0') {
model = p->name;
}
}
# endif
std::string model_id = decoder.getTheengAttribute(p->sensorModel_id, "model_id");

// Check for tracker status
Expand Down Expand Up @@ -1014,7 +1014,12 @@ void launchBTDiscovery(bool overrideDiscovery) {
Log.trace(F("Key: %s"), prop.key().c_str());
Log.trace(F("Unit: %s"), prop.value()["unit"].as<const char*>());
Log.trace(F("Name: %s"), prop.value()["name"].as<const char*>());
String entity_name = String(model_id.c_str()) + "-" + String(prop.key().c_str());
String entity_name = "";
if (displayDeviceName || ForceDeviceName) {
entity_name = String(model.c_str()) + "-" + String(prop.key().c_str());
} else {
entity_name = String(model_id.c_str()) + "-" + String(prop.key().c_str());
}
String unique_id = macWOdots + "-" + String(prop.key().c_str());
String value_template = "{{ value_json." + String(prop.key().c_str()) + " | is_defined }}";
if (p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::SBS1 && strcmp(prop.key().c_str(), "state") == 0) {
Expand Down Expand Up @@ -1436,8 +1441,8 @@ void process_bledata(JsonObject& BLEdata) {
Log.notice(F("Active and continuous scanning required, parameters adapted" CR));
stateBTMeasures(false);
}
} else if (BLEdata.containsKey("cont") && BTConfig.BLEinterval != MinTimeBtwScan) {
if (BLEdata["cont"]) {
} else if (BLEdata.containsKey("acts") && BTConfig.BLEinterval != MinTimeBtwScan) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DigiH Are you okay with this ?

if (BLEdata["acts"]) {
BTConfig.BLEinterval = MinTimeBtwScan;
if ((BLEdata["type"].as<string>()).compare("CTMO") == 0) {
BTConfig.scanDuration = MinScanDuration;
Expand Down
1 change: 1 addition & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ bool failSafeMode = false;
bool ProcessLock = true; // Process lock when we want to use a critical function like OTA for example
bool mqttSetupPending = true;
static int cnt_index = CNT_DEFAULT_INDEX;
bool displayDeviceName = DISPLAY_DEVICE_NAME;

#ifdef ESP32
# include <ArduinoOTA.h>
Expand Down
6 changes: 5 additions & 1 deletion main/mqttDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@ void createDiscovery(const char* sensor_type,

// generate unique device name by adding the second half of the device_id only if device_name and device_id are different and we don't want to use the BLE name
if (device_name[0]) {
if (strcmp(device_id, device_name) != 0 && device_id[0] && !ForceDeviceName) {
#if defined(ZwebUI) && defined(ESP32) // displayDeviceName only applies when running with the WebUI and ESP32
if (strcmp(device_id, device_name) != 0 && device_id[0] && !displayDeviceName) {
#elif !ForceDeviceName // Support ForceDeviceName for esp8266's
if (strcmp(device_id, device_name) != 0 && device_id[0] && !ForceDeviceName) {
#endif
device["name"] = device_name + String("-") + String(device_id + 6);
} else {
device["name"] = device_name;
Expand Down
15 changes: 12 additions & 3 deletions main/webUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,9 @@ void handleCN() {
* @brief /WU - Configuration Page
* T: handleWU: uri: /wu, args: 3, method: 1
* T: handleWU Arg: 0, dm=on - displayMetric
* T: handleWU Arg: 1, sw=on - webUISecure
* T: handleWU Arg: 2, save=
* T: handleWU Arg: 1, dn=1 - displayDeviceName
* T: handleWU Arg: 2, sw=on - webUISecure
* T: handleWU Arg: 3, save=
*/
void handleWU() {
WEBUI_TRACE_LOG(F("handleWU: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
Expand All @@ -521,6 +522,11 @@ void handleWU() {
}
displayMetric = server.hasArg("dm");

if (server.hasArg("dn") && server.arg("dn").toInt() != displayDeviceName) {
displayDeviceName = server.arg("dn").toInt();
update = true;
}

if (webUISecure != server.hasArg("sw")) {
update = true;
}
Expand All @@ -541,7 +547,7 @@ void handleWU() {
response += String(script);
response += String(style);
int logLevel = Log.getLevel();
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_webui_body, jsonChar, gateway_name, (displayMetric ? "checked" : ""), (webUISecure ? "checked" : ""));
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_webui_body, jsonChar, gateway_name, (displayMetric ? "checked" : ""), (!displayDeviceName ? "selected" : ""), (displayDeviceName ? "selected" : ""), (webUISecure ? "checked" : ""));
response += String(buffer);
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
response += String(buffer);
Expand Down Expand Up @@ -1863,6 +1869,7 @@ String stateWebUIStatus() {
StaticJsonDocument<JSON_MSG_BUFFER> WebUIdataBuffer;
JsonObject WebUIdata = WebUIdataBuffer.to<JsonObject>();
WebUIdata["displayMetric"] = (bool)displayMetric;
WebUIdata["displayDeviceName"] = (bool)displayDeviceName;
WebUIdata["webUISecure"] = (bool)webUISecure;
WebUIdata["displayQueue"] = uxQueueMessagesWaiting(webUIQueue);

Expand All @@ -1879,6 +1886,7 @@ bool WebUIConfig_save() {
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject jo = jsonBuffer.to<JsonObject>();
jo["displayMetric"] = (bool)displayMetric;
jo["displayDeviceName"] = (bool)displayDeviceName;
jo["webUISecure"] = (bool)webUISecure;
// Save config into NVS (non-volatile storage)
String conf = "";
Expand Down Expand Up @@ -1912,6 +1920,7 @@ bool WebUIConfig_load() {
}
JsonObject jo = jsonBuffer.as<JsonObject>();
displayMetric = jo["displayMetric"].as<bool>();
displayDeviceName = jo["displayDeviceName"].as<bool>();
webUISecure = jo["webUISecure"].as<bool>();
return true;
} else {
Expand Down