This commit is contained in:
MichaelDvP
2022-05-04 16:04:46 +02:00
15 changed files with 86 additions and 37 deletions

View File

@@ -38,6 +38,8 @@
- Added Shower Alert trigger time and cold shot time [#436](https://github.com/emsesp/EMS-ESP32/issues/436) - Added Shower Alert trigger time and cold shot time [#436](https://github.com/emsesp/EMS-ESP32/issues/436)
- Improved Table layout in Web UI (searching, filtering, sorting, exporting to CSV) - Improved Table layout in Web UI (searching, filtering, sorting, exporting to CSV)
- API fetch individual attributes from an entity [#462](https://github.com/emsesp/EMS-ESP32/issues/462) - API fetch individual attributes from an entity [#462](https://github.com/emsesp/EMS-ESP32/issues/462)
- Option to disable mDNS
- Option for rendering booleans on dashboard [#456](https://github.com/emsesp/EMS-ESP32/issues/456)
### Fixed ### Fixed

View File

@@ -56,7 +56,8 @@ const WiFiSettingsForm: FC = () => {
enableIPv6: false, enableIPv6: false,
bandwidth20: false, bandwidth20: false,
tx_power: 20, tx_power: 20,
nosleep: false nosleep: false,
enableMDNS: true
}); });
} }
setInitialized(true); setInitialized(true);
@@ -153,6 +154,11 @@ const WiFiSettingsForm: FC = () => {
label="Use Lower WiFi Bandwidth" label="Use Lower WiFi Bandwidth"
/> />
<BlockFormControlLabel
control={<Checkbox name="enableMDNS" checked={data.enableMDNS} onChange={updateFormValue} />}
label="Enable mDNS Service"
/>
<Typography sx={{ pt: 2 }} variant="h6" color="primary"> <Typography sx={{ pt: 2 }} variant="h6" color="primary">
General General
</Typography> </Typography>

View File

@@ -402,10 +402,27 @@ const SettingsApplication: FC = () => {
Formatting Options Formatting Options
</Typography> </Typography>
<Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start"> <Grid container spacing={1} direction="row" justifyContent="flex-start" alignItems="flex-start">
<Grid item xs={6}> <Grid item xs={4}>
<ValidatedTextField
name="bool_dashboard"
label="Boolean Format Dashboard"
value={data.bool_dashboard}
fullWidth
variant="outlined"
onChange={updateFormValue}
margin="normal"
select
>
<MenuItem value={1}>on/off</MenuItem>
<MenuItem value={2}>ON/OFF</MenuItem>
<MenuItem value={3}>true/false</MenuItem>
<MenuItem value={5}>1/0</MenuItem>
</ValidatedTextField>
</Grid>
<Grid item xs={4}>
<ValidatedTextField <ValidatedTextField
name="bool_format" name="bool_format"
label="Boolean Format" label="Boolean Format API/MQTT"
value={data.bool_format} value={data.bool_format}
fullWidth fullWidth
variant="outlined" variant="outlined"
@@ -421,10 +438,10 @@ const SettingsApplication: FC = () => {
<MenuItem value={6}>1/0</MenuItem> <MenuItem value={6}>1/0</MenuItem>
</ValidatedTextField> </ValidatedTextField>
</Grid> </Grid>
<Grid item xs={6}> <Grid item xs={4}>
<ValidatedTextField <ValidatedTextField
name="enum_format" name="enum_format"
label="Enum Format" label="Enum Format API/MQTT"
value={data.enum_format} value={data.enum_format}
fullWidth fullWidth
variant="outlined" variant="outlined"

View File

@@ -26,6 +26,7 @@ export interface Settings {
trace_raw: boolean; trace_raw: boolean;
board_profile: string; board_profile: string;
bool_format: number; bool_format: number;
bool_dashboard: number;
enum_format: number; enum_format: number;
fahrenheit: boolean; fahrenheit: boolean;
phy_type: number; phy_type: number;

View File

@@ -47,6 +47,7 @@ export interface NetworkSettings {
subnet_mask?: string; subnet_mask?: string;
dns_ip_1?: string; dns_ip_1?: string;
dns_ip_2?: string; dns_ip_2?: string;
enableMDNS: boolean;
} }
export interface WiFiNetworkList { export interface WiFiNetworkList {

View File

@@ -38,6 +38,7 @@ class NetworkSettings {
bool bandwidth20; bool bandwidth20;
int8_t tx_power; int8_t tx_power;
bool nosleep; bool nosleep;
bool enableMDNS;
// optional configuration for static IP address // optional configuration for static IP address
IPAddress localIP; IPAddress localIP;
@@ -56,6 +57,7 @@ class NetworkSettings {
root["bandwidth20"] = settings.bandwidth20; root["bandwidth20"] = settings.bandwidth20;
root["tx_power"] = settings.tx_power; root["tx_power"] = settings.tx_power;
root["nosleep"] = settings.nosleep; root["nosleep"] = settings.nosleep;
root["enableMDNS"] = settings.enableMDNS;
// extended settings // extended settings
JsonUtils::writeIP(root, "local_ip", settings.localIP); JsonUtils::writeIP(root, "local_ip", settings.localIP);
@@ -74,6 +76,7 @@ class NetworkSettings {
settings.bandwidth20 = root["bandwidth20"] | false; settings.bandwidth20 = root["bandwidth20"] | false;
settings.tx_power = root["tx_power"] | 20; settings.tx_power = root["tx_power"] | 20;
settings.nosleep = root["nosleep"] | false; settings.nosleep = root["nosleep"] | false;
settings.enableMDNS = root["enableMDNS"] | true;
// extended settings // extended settings
JsonUtils::readIP(root, "local_ip", settings.localIP); JsonUtils::readIP(root, "local_ip", settings.localIP);

View File

@@ -35,6 +35,7 @@ class DummySettings {
bool notoken_api = false; bool notoken_api = false;
bool readonly_mode = false; bool readonly_mode = false;
uint8_t bool_format = 1; // using "on" and "off" uint8_t bool_format = 1; // using "on" and "off"
uint8_t bool_dashboard = 1;
uint8_t enum_format = 1; uint8_t enum_format = 1;
bool nosleep = false; bool nosleep = false;
bool fahrenheit = false; bool fahrenheit = false;

View File

@@ -670,12 +670,8 @@ void EMSdevice::generate_values_web(JsonObject & output) {
// handle Booleans (true, false), use strings, no native true/false) // handle Booleans (true, false), use strings, no native true/false)
if (dv.type == DeviceValueType::BOOL) { if (dv.type == DeviceValueType::BOOL) {
auto value_b = (bool)*(uint8_t *)(dv.value_p); auto value_b = (bool)*(uint8_t *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
obj["v"] = value_b ? 1 : 0;
} else {
char s[7]; char s[7];
obj["v"] = Helpers::render_boolean(s, value_b); obj["v"] = Helpers::render_boolean(s, value_b, true);
}
} }
// handle TEXT strings // handle TEXT strings
@@ -748,8 +744,8 @@ void EMSdevice::generate_values_web(JsonObject & output) {
} else if (dv.type == DeviceValueType::BOOL) { } else if (dv.type == DeviceValueType::BOOL) {
JsonArray l = obj.createNestedArray("l"); JsonArray l = obj.createNestedArray("l");
char result[10]; char result[10];
l.add(Helpers::render_boolean(result, false)); l.add(Helpers::render_boolean(result, false, true));
l.add(Helpers::render_boolean(result, true)); l.add(Helpers::render_boolean(result, true, true));
} }
// add command help template // add command help template
else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) { else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) {
@@ -789,12 +785,8 @@ void EMSdevice::generate_values_web_all(JsonArray & output) {
// handle Booleans (true, false), use strings, no native true/false) // handle Booleans (true, false), use strings, no native true/false)
if (dv.type == DeviceValueType::BOOL) { if (dv.type == DeviceValueType::BOOL) {
auto value_b = (bool)*(uint8_t *)(dv.value_p); auto value_b = (bool)*(uint8_t *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
obj["v"] = value_b ? 1 : 0;
} else {
char s[7]; char s[7];
obj["v"] = Helpers::render_boolean(s, value_b); obj["v"] = Helpers::render_boolean(s, value_b, true);
}
} }
// handle TEXT strings // handle TEXT strings

View File

@@ -176,8 +176,8 @@ char * Helpers::smallitoa(char * result, const uint16_t value) {
// work out how to display booleans // work out how to display booleans
// for strings only // for strings only
char * Helpers::render_boolean(char * result, bool value) { char * Helpers::render_boolean(char * result, const bool value, const bool dashboard) {
uint8_t bool_format_ = EMSESP::system_.bool_format(); uint8_t bool_format_ = dashboard ? EMSESP::system_.bool_dashboard() : EMSESP::system_.bool_format();
if (bool_format_ == BOOL_FORMAT_ONOFF_STR) { if (bool_format_ == BOOL_FORMAT_ONOFF_STR) {
strlcpy(result, value ? read_flash_string(F_(on)).c_str() : read_flash_string(F_(off)).c_str(), 5); strlcpy(result, value ? read_flash_string(F_(on)).c_str() : read_flash_string(F_(off)).c_str(), 5);
} else if (bool_format_ == BOOL_FORMAT_ONOFF_STR_CAP) { } else if (bool_format_ == BOOL_FORMAT_ONOFF_STR_CAP) {

View File

@@ -37,7 +37,7 @@ class Helpers {
static char * render_value(char * result, const uint32_t value, const int8_t format, const uint8_t fahrenheit = 0); static char * render_value(char * result, const uint32_t value, const int8_t format, const uint8_t fahrenheit = 0);
static char * render_value(char * result, const int16_t value, const int8_t format, const uint8_t fahrenheit = 0); static char * render_value(char * result, const int16_t value, const int8_t format, const uint8_t fahrenheit = 0);
static char * render_value(char * result, const int32_t value, const int8_t format, const uint8_t fahrenheit = 0); static char * render_value(char * result, const int32_t value, const int8_t format, const uint8_t fahrenheit = 0);
static char * render_boolean(char * result, bool value); static char * render_boolean(char * result, const bool value, const bool dashboard = false);
static char * hextoa(char * result, const uint8_t value); static char * hextoa(char * result, const uint8_t value);
static char * hextoa(char * result, const uint16_t value); static char * hextoa(char * result, const uint16_t value);

View File

@@ -334,6 +334,7 @@ void System::reload_settings() {
fahrenheit_ = settings.fahrenheit; fahrenheit_ = settings.fahrenheit;
bool_format_ = settings.bool_format; bool_format_ = settings.bool_format;
bool_dashboard_ = settings.bool_dashboard;
enum_format_ = settings.enum_format; enum_format_ = settings.enum_format;
readonly_mode_ = settings.readonly_mode; readonly_mode_ = settings.readonly_mode;
@@ -1016,6 +1017,7 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
node["fahrenheit"] = settings.fahrenheit; node["fahrenheit"] = settings.fahrenheit;
node["dallas_parasite"] = settings.dallas_parasite; node["dallas_parasite"] = settings.dallas_parasite;
node["bool_format"] = settings.bool_format; node["bool_format"] = settings.bool_format;
node["bool_dashboard"] = settings.bool_dashboard;
node["enum_format"] = settings.enum_format; node["enum_format"] = settings.enum_format;
node["analog_enabled"] = settings.analog_enabled; node["analog_enabled"] = settings.analog_enabled;
node["telnet_enabled"] = settings.telnet_enabled; node["telnet_enabled"] = settings.telnet_enabled;

View File

@@ -115,6 +115,10 @@ class System {
return bool_format_; return bool_format_;
} }
uint8_t bool_dashboard() {
return bool_dashboard_;
}
// see default_settings.h // see default_settings.h
// BOOL_FORMAT_ONOFF_STR = 1, // BOOL_FORMAT_ONOFF_STR = 1,
// BOOL_FORMAT_ONOFF_STR_CAP = 2 // BOOL_FORMAT_ONOFF_STR_CAP = 2
@@ -126,6 +130,10 @@ class System {
bool_format_ = format; bool_format_ = format;
} }
void bool_dashboard(uint8_t format) {
bool_dashboard_ = format;
}
uint8_t enum_format() { uint8_t enum_format() {
return enum_format_; return enum_format_;
} }
@@ -250,6 +258,7 @@ class System {
String syslog_host_; String syslog_host_;
uint16_t syslog_port_; uint16_t syslog_port_;
bool fahrenheit_; bool fahrenheit_;
uint8_t bool_dashboard_;
uint8_t bool_format_; uint8_t bool_format_;
uint8_t enum_format_; uint8_t enum_format_;
bool readonly_mode_; bool readonly_mode_;

View File

@@ -66,6 +66,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
root["board_profile"] = settings.board_profile; root["board_profile"] = settings.board_profile;
root["fahrenheit"] = settings.fahrenheit; root["fahrenheit"] = settings.fahrenheit;
root["bool_format"] = settings.bool_format; root["bool_format"] = settings.bool_format;
root["bool_dashboard"] = settings.bool_dashboard;
root["enum_format"] = settings.enum_format; root["enum_format"] = settings.enum_format;
root["weblog_level"] = settings.weblog_level; root["weblog_level"] = settings.weblog_level;
root["weblog_buffer"] = settings.weblog_buffer; root["weblog_buffer"] = settings.weblog_buffer;
@@ -225,6 +226,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT; settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT;
EMSESP::system_.bool_format(settings.bool_format); EMSESP::system_.bool_format(settings.bool_format);
settings.bool_dashboard = root["bool_dashboard"] | EMSESP_DEFAULT_BOOL_FORMAT;
EMSESP::system_.bool_dashboard(settings.bool_dashboard);
settings.enum_format = root["enum_format"] | EMSESP_DEFAULT_ENUM_FORMAT; settings.enum_format = root["enum_format"] | EMSESP_DEFAULT_ENUM_FORMAT;
EMSESP::system_.enum_format(settings.enum_format); EMSESP::system_.enum_format(settings.enum_format);

View File

@@ -57,6 +57,7 @@ class WebSettings {
uint8_t solar_maxflow; uint8_t solar_maxflow;
String board_profile; String board_profile;
uint8_t bool_format; uint8_t bool_format;
uint8_t bool_dashboard;
uint8_t enum_format; uint8_t enum_format;
int8_t weblog_level; int8_t weblog_level;
uint8_t weblog_buffer; uint8_t weblog_buffer;

View File

@@ -190,6 +190,8 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
void WebStatusService::mDNS_start() const { void WebStatusService::mDNS_start() const {
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
MDNS.end(); MDNS.end();
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (networkSettings.enableMDNS) {
if (!MDNS.begin(EMSESP::system_.hostname().c_str())) { if (!MDNS.begin(EMSESP::system_.hostname().c_str())) {
EMSESP::logger().warning(F("Failed to start mDNS responder service")); EMSESP::logger().warning(F("Failed to start mDNS responder service"));
return; return;
@@ -202,9 +204,17 @@ void WebStatusService::mDNS_start() const {
MDNS.addServiceTxt("http", "tcp", "version", EMSESP_APP_VERSION); MDNS.addServiceTxt("http", "tcp", "version", EMSESP_APP_VERSION);
MDNS.addServiceTxt("http", "tcp", "address", address_s.c_str()); MDNS.addServiceTxt("http", "tcp", "address", address_s.c_str());
#endif
EMSESP::logger().info(F("mDNS responder service started")); EMSESP::logger().info(F("mDNS responder service started"));
} }
});
#else
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (networkSettings.enableMDNS) {
EMSESP::logger().info(F("mDNS responder service started"));
}
});
#endif
}
} // namespace emsesp } // namespace emsesp