Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
refactor device value rendering (to Web, Console or MQTT) to base cla…
Browse files Browse the repository at this point in the history
…ss #632
  • Loading branch information
proddy committed Dec 13, 2020
1 parent f72e549 commit ffa313e
Show file tree
Hide file tree
Showing 60 changed files with 2,587 additions and 3,375 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- WM10 switch telegrams
- boiler information (#633)
- maintenance message and command
- thermostat program, reducemode, controlmode

### Fixed
- mixer IPM pumpstatus
Expand Down
48 changes: 37 additions & 11 deletions interface/src/mqtt/MqttSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@ class MqttSettingsForm extends React.Component<MqttSettingsFormProps> {
onChange={handleValueChange('max_topic_length')}
margin="normal"
/>
<SelectValidator name="mqtt_format"
label="Format"
value={data.mqtt_format}
fullWidth
variant="outlined"
onChange={handleValueChange('mqtt_format')}
margin="normal">
<MenuItem value={1}>Single</MenuItem>
<MenuItem value={2}>Nested</MenuItem>
<MenuItem value={3}>Home Assistant</MenuItem>
</SelectValidator>
<SelectValidator name="mqtt_qos"
label="QoS"
value={data.mqtt_qos}
Expand Down Expand Up @@ -149,6 +138,43 @@ class MqttSettingsForm extends React.Component<MqttSettingsFormProps> {
label="Retain Flag"
/>
<br></br>
<Typography variant="h6" color="primary" >
Formatting
</Typography>
<SelectValidator name="dallas_format"
label="Dallas Sensor Payload Grouping"
value={data.dallas_format}
fullWidth
variant="outlined"
onChange={handleValueChange('dallas_format')}
margin="normal">
<MenuItem value={1}>by Sensor ID</MenuItem>
<MenuItem value={2}>by Number</MenuItem>
</SelectValidator>
<BlockFormControlLabel
control={
<Checkbox
checked={data.ha_enabled}
onChange={handleValueChange('ha_enabled')}
value="ha_enabled"
/>
}
label="Home Assistant MQTT Discovery"
/>
{ data.ha_enabled &&
<SelectValidator name="ha_climate_format"
label="Thermostat Room Temperature"
value={data.ha_climate_format}
fullWidth
variant="outlined"
onChange={handleValueChange('ha_climate_format')}
margin="normal">
<MenuItem value={1}>use Current temperature (default)</MenuItem>
<MenuItem value={2}>use Setpoint temperature</MenuItem>
<MenuItem value={3}>Fix to 0</MenuItem>
</SelectValidator>
}
<br></br>
<Typography variant="h6" color="primary" >
Publish Intervals
</Typography>
Expand Down
4 changes: 3 additions & 1 deletion interface/src/mqtt/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export interface MqttSettings {
publish_time_mixer: number;
publish_time_other: number;
publish_time_sensor: number;
mqtt_format: number;
dallas_format: number;
mqtt_qos: number;
mqtt_retain: boolean;
ha_enabled: boolean;
ha_climate_format: number;
}
6 changes: 3 additions & 3 deletions interface/src/project/EMSESPDevicesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ class EMSESPDevicesForm extends Component<
<TableHead></TableHead>
<TableBody>
{deviceData.data.map((item, i) => {
if (i % 2) {
if (i % 3) {
return null;
} else {
return (
<TableRow key={i}>
<TableCell component="th" scope="row">{deviceData.data[i]}</TableCell>
<TableCell align="right">{deviceData.data[i + 1]}</TableCell>
<TableCell component="th" scope="row">{deviceData.data[i+2]}</TableCell>
<TableCell align="right">{deviceData.data[i]}{deviceData.data[i + 1]}</TableCell>
</TableRow>
);
}
Expand Down
22 changes: 4 additions & 18 deletions interface/src/project/EMSESPStatusForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,16 @@ class EMSESPStatusForm extends Component<EMSESPStatusFormProps> {
<TableBody>
<TableRow>
<TableCell>
Received telegrams
# Telegrams Received
</TableCell>
<TableCell align="right">{formatNumber(data.rx_received)}
<TableCell align="right">{formatNumber(data.rx_received)}&nbsp;({data.rx_quality}%)
</TableCell>
</TableRow>
<TableRow>
<TableCell >
Rx line quality
</TableCell>
<TableCell align="right">{data.rx_quality}&nbsp;%
</TableCell>
</TableRow>
<TableRow>
<TableCell >
Sent telegrams
# Telegrams Sent
</TableCell >
<TableCell align="right">{formatNumber(data.tx_sent)}
</TableCell>
</TableRow>
<TableRow>
<TableCell >
Tx line quality
</TableCell>
<TableCell align="right">{data.tx_quality}&nbsp;%
<TableCell align="right">{formatNumber(data.tx_sent)}&nbsp;({data.tx_quality}%)
</TableCell>
</TableRow>
</TableBody>
Expand Down
6 changes: 3 additions & 3 deletions interface/src/project/ProjectRouting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { Redirect, Switch } from 'react-router';

import { AuthenticatedRoute } from '../authentication';

import EMSESP from './EMSESP';
import EMSESPDashboard from './EMSESPDashboard';
import EMSESPSettings from './EMSESPSettings';

class ProjectRouting extends Component {

render() {
return (
<Switch>
<AuthenticatedRoute exact path="/ems-esp/status/*" component={EMSESP} />
<AuthenticatedRoute exact path="/ems-esp/status/*" component={EMSESPDashboard} />
<AuthenticatedRoute exact path="/ems-esp/settings" component={EMSESPSettings} />
<AuthenticatedRoute exact path="/ems-esp/*" component={EMSESP} />
<AuthenticatedRoute exact path="/ems-esp/*" component={EMSESPDashboard} />
{
/*
* The redirect below caters for the default project route and redirecting invalid paths.
Expand Down
25 changes: 19 additions & 6 deletions lib/framework/MqttSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
root["publish_time_mixer"] = settings.publish_time_mixer;
root["publish_time_other"] = settings.publish_time_other;
root["publish_time_sensor"] = settings.publish_time_sensor;
root["mqtt_format"] = settings.mqtt_format;
root["mqtt_qos"] = settings.mqtt_qos;
root["mqtt_retain"] = settings.mqtt_retain;
root["dallas_format"] = settings.dallas_format;
root["ha_climate_format"] = settings.ha_climate_format;
root["ha_enabled"] = settings.ha_enabled;
}

StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & settings) {
Expand All @@ -205,23 +207,34 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
newSettings.keepAlive = root["keep_alive"] | FACTORY_MQTT_KEEP_ALIVE;
newSettings.cleanSession = root["clean_session"] | FACTORY_MQTT_CLEAN_SESSION;
newSettings.maxTopicLength = root["max_topic_length"] | FACTORY_MQTT_MAX_TOPIC_LENGTH;
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
newSettings.mqtt_retain = root["mqtt_retain"] | EMSESP_DEFAULT_MQTT_RETAIN;

newSettings.publish_time_boiler = root["publish_time_boiler"] | EMSESP_DEFAULT_PUBLISH_TIME;
newSettings.publish_time_thermostat = root["publish_time_thermostat"] | EMSESP_DEFAULT_PUBLISH_TIME;
newSettings.publish_time_solar = root["publish_time_solar"] | EMSESP_DEFAULT_PUBLISH_TIME;
newSettings.publish_time_mixer = root["publish_time_mixer"] | EMSESP_DEFAULT_PUBLISH_TIME;
newSettings.publish_time_other = root["publish_time_other"] | EMSESP_DEFAULT_PUBLISH_TIME;
newSettings.publish_time_sensor = root["publish_time_sensor"] | EMSESP_DEFAULT_PUBLISH_TIME;
newSettings.mqtt_format = root["mqtt_format"] | EMSESP_DEFAULT_MQTT_FORMAT;
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
newSettings.mqtt_retain = root["mqtt_retain"] | EMSESP_DEFAULT_MQTT_RETAIN;

newSettings.dallas_format = root["dallas_format"] | EMSESP_DEFAULT_DALLAS_FORMAT;
newSettings.ha_climate_format = root["ha_climate_format"] | EMSESP_DEFAULT_HA_CLIMATE_FORMAT;
newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED;

if (newSettings.mqtt_qos != settings.mqtt_qos) {
emsesp::EMSESP::mqtt_.set_qos(newSettings.mqtt_qos);
}

if (newSettings.mqtt_format != settings.mqtt_format) {
emsesp::EMSESP::mqtt_.set_format(newSettings.mqtt_format);
if (newSettings.dallas_format != settings.dallas_format) {
emsesp::EMSESP::mqtt_.dallas_format(newSettings.dallas_format);
}

if (newSettings.ha_climate_format != settings.ha_climate_format) {
emsesp::EMSESP::mqtt_.ha_climate_format(newSettings.ha_climate_format);
}

if (newSettings.ha_enabled != settings.ha_enabled) {
emsesp::EMSESP::mqtt_.ha_enabled(newSettings.ha_enabled);
}

if (newSettings.mqtt_retain != settings.mqtt_retain) {
Expand Down
8 changes: 6 additions & 2 deletions lib/framework/MqttSettingsService.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ static String generateClientId() {
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
#endif

#define EMSESP_DEFAULT_MQTT_FORMAT 2 // nested
#define EMSESP_DEFAULT_DALLAS_FORMAT 1 // sensorid
#define EMSESP_DEFAULT_HA_CLIMATE_FORMAT 1 // current temp
#define EMSESP_DEFAULT_MQTT_QOS 0
#define EMSESP_DEFAULT_MQTT_RETAIN false
#define EMSESP_DEFAULT_HA_ENABLED false
#define EMSESP_DEFAULT_PUBLISH_TIME 10

class MqttSettings {
Expand Down Expand Up @@ -91,9 +93,11 @@ class MqttSettings {
uint16_t publish_time_mixer;
uint16_t publish_time_other;
uint16_t publish_time_sensor;
uint8_t mqtt_format; // 1=single, 2=nested, 3=ha, 4=custom
uint8_t mqtt_qos;
bool mqtt_retain;
uint8_t dallas_format;
uint8_t ha_climate_format;
bool ha_enabled;

static void read(MqttSettings & settings, JsonObject & root);
static StateUpdateResult update(JsonObject & root, MqttSettings & settings);
Expand Down
71 changes: 71 additions & 0 deletions lib/uuid-common/src/compare_flash_string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* EMS-ESP - https://github.com/proddy/EMS-ESP
* Copyright 2020 Paul Derbyshire
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <uuid/common.h>

// #ifdef ESP8266
// #include <pgmspace.h>
// #else
// #include <avr/pgmspace.h>
// #endif

#include <Arduino.h>

namespace uuid {

// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
// optimizing for 4-byte alignment here.

// class __FlashStringHelper;

int compare_flash_string(const __FlashStringHelper * a, const __FlashStringHelper * b) {
const char * aa = reinterpret_cast<const char *>(a);
const char * bb = reinterpret_cast<const char *>(b);

while (true) {
uint8_t ca = pgm_read_byte(aa);
uint8_t cb = pgm_read_byte(bb);
if (ca != cb)
return (int)ca - (int)cb;
if (ca == 0)
return 0;
aa++;
bb++;
}
}

int compare_flash_string(const __FlashStringHelper * a, const __FlashStringHelper * b, size_t n) {
const char * aa = reinterpret_cast<const char *>(a);
const char * bb = reinterpret_cast<const char *>(b);

while (n > 0) {
uint8_t ca = pgm_read_byte(aa);
uint8_t cb = pgm_read_byte(bb);
if (ca != cb)
return (int)ca - (int)cb;
if (ca == 0)
return 0;
aa++;
bb++;
n--;
}
return 0;
}

} // namespace uuid
17 changes: 17 additions & 0 deletions lib/uuid-common/src/uuid/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// compare_flash_string added by Proddy

#ifndef UUID_COMMON_H_
#define UUID_COMMON_H_

Expand All @@ -32,6 +34,21 @@
*/
namespace uuid {

/**
* String compare two flash strings
*
* The flash string must be stored with appropriate alignment for
* reading it on the platform.
*
* @param[in] a Pointer to string stored in flash.
* @param[in] b Pointer to string stored in flash.
* @param[in] n optional max length
* @return 0 for match, otherwise diff
* @since 1.0.0
*/
int compare_flash_string(const __FlashStringHelper * a, const __FlashStringHelper * b);
int compare_flash_string(const __FlashStringHelper * a, const __FlashStringHelper * b, size_t n);

/**
* Read a string from flash and convert it to a std::string.
*
Expand Down
37 changes: 21 additions & 16 deletions lib_standalone/ESP8266React.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@

class DummySettings {
public:
uint8_t tx_mode = 1;
uint8_t ems_bus_id = 0x0B;
bool syslog_enabled = false;
int8_t syslog_level = 3; // uuid::log::Level
uint32_t syslog_mark_interval = 0;
String syslog_host = "192.168.1.4";
uint8_t master_thermostat = 0;
bool shower_timer = false;
bool shower_alert = false;
bool hide_led = false;
bool api_enabled = true;
uint16_t publish_time = 10; // seconds
uint8_t mqtt_format = 3; // 1=single, 2=nested, 3=ha, 4=custom
uint8_t mqtt_qos = 0;
bool mqtt_retain = false;
bool enabled = true; // MQTT
uint8_t tx_mode = 1;
uint8_t ems_bus_id = 0x0B;
bool syslog_enabled = false;
int8_t syslog_level = 3; // uuid::log::Level
uint32_t syslog_mark_interval = 0;
String syslog_host = "192.168.1.4";
uint8_t master_thermostat = 0;
bool shower_timer = true;
bool shower_alert = false;
bool hide_led = false;
bool api_enabled = true;

// MQTT
uint16_t publish_time = 10; // seconds
uint8_t mqtt_qos = 0;
bool mqtt_retain = false;
bool enabled = true;
uint8_t dallas_format = 1;
uint8_t ha_climate_format = 1;
bool ha_enabled = false;

String hostname = "ems-esp";
String jwtSecret = "ems-esp";
String ssid = "ems-esp";
Expand Down
Loading

0 comments on commit ffa313e

Please sign in to comment.