From 58b93fb62dd6c267c00b0b82575e34956120df2d Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 6 Jul 2020 13:27:47 +0200 Subject: [PATCH 1/6] added tank heated and collector on/off - #422 --- src/devices/solar.cpp | 23 +++++++++++++++++++++++ src/devices/solar.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/devices/solar.cpp b/src/devices/solar.cpp index 316489749..63a770e98 100644 --- a/src/devices/solar.cpp +++ b/src/devices/solar.cpp @@ -73,6 +73,9 @@ void Solar::show_values(uuid::console::Shell & shell) { shell.printfln(F(" Pump working time: %d days %d hours %d minutes"), pumpWorkMin_ / 1440, (pumpWorkMin_ % 1440) / 60, pumpWorkMin_ % 60); } + print_value(shell, 2, F("Tank Heated"), tankHeated_, nullptr, EMS_VALUE_BOOL); + print_value(shell, 2, F("Collector"), collectorOnOff_, nullptr, EMS_VALUE_BOOL); + print_value(shell, 2, F("Energy last hour"), energyLastHour_, F_(wh), 10); print_value(shell, 2, F("Energy today"), energyToday_, F_(wh)); print_value(shell, 2, F("Energy total"), energyTotal_, F_(kwh), 10); @@ -87,30 +90,47 @@ void Solar::publish_values() { if (Helpers::hasValue(collectorTemp_)) { doc["collectortemp"] = (float)collectorTemp_ / 10; } + if (Helpers::hasValue(bottomTemp_)) { doc["bottomtemp"] = (float)bottomTemp_ / 10; } + if (Helpers::hasValue(bottomTemp2_)) { doc["bottomtemp2"] = (float)bottomTemp2_ / 10; } + if (Helpers::hasValue(pumpModulation_)) { doc["pumpmodulation"] = pumpModulation_; } + if (Helpers::hasValue(pump_, true)) { doc["pump"] = Helpers::render_value(s, pump_, EMS_VALUE_BOOL); } + if (Helpers::hasValue(valveStatus_, true)) { doc["valvestatus"] = Helpers::render_value(s, valveStatus_, EMS_VALUE_BOOL); } + if (Helpers::hasValue(pumpWorkMin_)) { doc["pumpWorkMin"] = (float)pumpWorkMin_; } + + if (Helpers::hasValue(tankHeated_, true)) { + doc["tankHeated"] = Helpers::render_value(s, tankHeated_, EMS_VALUE_BOOL); + } + + if (Helpers::hasValue(collectorOnOff_, true)) { + doc["collectorOnOff"] = Helpers::render_value(s, collectorOnOff_, EMS_VALUE_BOOL); + } + if (Helpers::hasValue(energyLastHour_)) { doc["energylasthour"] = (float)energyLastHour_ / 10; } + if (Helpers::hasValue(energyToday_)) { doc["energytoday"] = energyToday_; } + if (Helpers::hasValue(energyTotal_)) { doc["energytotal"] = (float)energyTotal_ / 10; } @@ -186,6 +206,9 @@ void Solar::process_SM100Status(std::shared_ptr telegram) { if (pumpmod == 0 && pumpModulation_ == 100) { // mask out boosts pumpModulation_ = 15; // set to minimum } + + telegram->read_bitvalue(tankHeated_, 3, 1); // issue #422 + telegram->read_bitvalue(collectorOnOff_, 3, 0); } /* diff --git a/src/devices/solar.h b/src/devices/solar.h index da51fa907..5a1be5e5b 100644 --- a/src/devices/solar.h +++ b/src/devices/solar.h @@ -56,6 +56,8 @@ class Solar : public EMSdevice { uint32_t energyToday_ = EMS_VALUE_ULONG_NOTSET; uint32_t energyTotal_ = EMS_VALUE_ULONG_NOTSET; uint32_t pumpWorkMin_ = EMS_VALUE_ULONG_NOTSET; // Total solar pump operating time + uint8_t tankHeated_ = EMS_VALUE_BOOL_NOTSET; + uint8_t collectorOnOff_ = EMS_VALUE_BOOL_NOTSET; uint8_t availabilityFlag_ = EMS_VALUE_BOOL_NOTSET; uint8_t configFlag_ = EMS_VALUE_BOOL_NOTSET; From cfce4964bfee8f1253f1285a135645dbb16414e2 Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 6 Jul 2020 13:29:41 +0200 Subject: [PATCH 2/6] fixes to checking bus status --- src/emsesp.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 3c6d30f36..bd81b8147 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -107,8 +107,10 @@ void EMSESP::reset_tx(uint8_t const tx_mode) { txservice_.telegram_read_count(0); txservice_.telegram_write_count(0); txservice_.telegram_fail_count(0); - EMSuart::stop(); - EMSuart::start(tx_mode); // reset the UART + if (tx_mode) { + EMSuart::stop(); + EMSuart::start(tx_mode); // reset the UART + } } // return status of bus: connected, connected but Tx is broken, disconnected @@ -117,8 +119,21 @@ uint8_t EMSESP::bus_status() { return BUS_STATUS_OFFLINE; } - // check if we have Tx issues - if (txservice_.telegram_read_count() < 2) { + // check if we have Tx issues. + uint32_t total_sent = txservice_.telegram_read_count() + txservice_.telegram_write_count(); + + // nothing sent successfully, also no errors - must be ok + if ((total_sent == 0) && (txservice_.telegram_fail_count() == 0)) { + return BUS_STATUS_CONNECTED; + } + + // nothing sent successfully, but have Tx errors + if ((total_sent == 0) && (txservice_.telegram_fail_count() != 0)) { + return BUS_STATUS_TX_ERRORS; + } + + // Tx Failure rate > 5% + if (((txservice_.telegram_fail_count() * 100) / total_sent) >= 5) { return BUS_STATUS_TX_ERRORS; } From 686c51d0c43bf792664f92d2fe65e174f12405ed Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 6 Jul 2020 13:30:00 +0200 Subject: [PATCH 3/6] disabled uart if tx_mode is 0 --- src/system.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/system.cpp b/src/system.cpp index 9750fbe03..2ebe27f32 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -231,7 +231,9 @@ void System::start() { Mqtt::subscribe("cmd", std::bind(&System::mqtt_commands, this, _1)); #ifndef EMSESP_FORCE_SERIAL - EMSuart::start(tx_mode_); // start UART + if (tx_mode_) { + EMSuart::start(tx_mode_); // start UART, if tx_mode is not 0 + } #endif } From 4fb88fbcac920bc89382a7591a60abe68ba06892 Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 6 Jul 2020 13:30:39 +0200 Subject: [PATCH 4/6] fix color of info icons --- interface/src/CustomMuiTheme.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/CustomMuiTheme.tsx b/interface/src/CustomMuiTheme.tsx index 3b4b0cbd6..d2949f334 100644 --- a/interface/src/CustomMuiTheme.tsx +++ b/interface/src/CustomMuiTheme.tsx @@ -2,7 +2,7 @@ import React, { Component } from 'react'; import { CssBaseline } from '@material-ui/core'; import { MuiThemeProvider, createMuiTheme, StylesProvider } from '@material-ui/core/styles'; -import { blueGrey, orange, red, green } from '@material-ui/core/colors'; +import { yellow, orange, red, green } from '@material-ui/core/colors'; const theme = createMuiTheme({ palette: { @@ -14,7 +14,7 @@ const theme = createMuiTheme({ main: '#3d5afe', }, info: { - main: blueGrey[900] + main: yellow[200] }, warning: { main: orange[500] From 85debcbebebb1de2b5e95290d7e003c91d806945 Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 6 Jul 2020 13:31:07 +0200 Subject: [PATCH 5/6] improvements to EMS-ESP web status page --- .../src/project/EMSESPSettingsController.tsx | 6 +- interface/src/project/EMSESPStatus.ts | 6 +- interface/src/project/EMSESPStatusForm.tsx | 284 +++++++++--------- interface/src/project/ProjectMenu.tsx | 21 +- 4 files changed, 167 insertions(+), 150 deletions(-) diff --git a/interface/src/project/EMSESPSettingsController.tsx b/interface/src/project/EMSESPSettingsController.tsx index 08c07a060..7bb2923ca 100644 --- a/interface/src/project/EMSESPSettingsController.tsx +++ b/interface/src/project/EMSESPSettingsController.tsx @@ -52,10 +52,10 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps) status === busConnectionStatus.BUS_STATUS_CONNECTED; +export const isConnected = ({ status }: EMSESPStatus) => status !== busConnectionStatus.BUS_STATUS_OFFLINE; export const busStatusHighlight = ({ status }: EMSESPStatus, theme: Theme) => { + switch (status) { case busConnectionStatus.BUS_STATUS_TX_ERRORS: - return theme.palette.info.main; + return theme.palette.warning.main; case busConnectionStatus.BUS_STATUS_CONNECTED: return theme.palette.success.main; case busConnectionStatus.BUS_STATUS_OFFLINE: @@ -30,6 +31,7 @@ export const busStatus = ({ status }: EMSESPStatus) => { } export const mqttStatusHighlight = ({ mqtt_fails }: EMSESPStatus, theme: Theme) => { + if (mqtt_fails === 0) return theme.palette.success.main; diff --git a/interface/src/project/EMSESPStatusForm.tsx b/interface/src/project/EMSESPStatusForm.tsx index 5dd702a00..4dcc90843 100644 --- a/interface/src/project/EMSESPStatusForm.tsx +++ b/interface/src/project/EMSESPStatusForm.tsx @@ -1,149 +1,161 @@ -import React, { Component, Fragment } from 'react'; +import React, { Component, Fragment } from "react"; -import { WithTheme, withTheme } from '@material-ui/core/styles'; -import { Table, TableBody, TableCell, TableHead, TableRow, Avatar, Divider, List, ListItem, ListItemAvatar, ListItemText } from '@material-ui/core'; +import { WithTheme, withTheme } from "@material-ui/core/styles"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableRow, + Avatar, + Divider, + List, + ListItem, + ListItemAvatar, + ListItemText, +} from "@material-ui/core"; -import BuildIcon from '@material-ui/icons/Build'; -import RefreshIcon from '@material-ui/icons/Refresh'; -import DeviceHubIcon from '@material-ui/icons/DeviceHub'; -import SpeakerNotesOffIcon from '@material-ui/icons/SpeakerNotesOff'; -import TimerIcon from '@material-ui/icons/Timer'; -import BatteryUnknownIcon from '@material-ui/icons/BatteryUnknown'; +import BuildIcon from "@material-ui/icons/Build"; +import RefreshIcon from "@material-ui/icons/Refresh"; +import DeviceHubIcon from "@material-ui/icons/DeviceHub"; +import SpeakerNotesOffIcon from "@material-ui/icons/SpeakerNotesOff"; +import TimerIcon from "@material-ui/icons/Timer"; +import BatteryUnknownIcon from "@material-ui/icons/BatteryUnknown"; -import { RestFormProps, FormActions, FormButton, HighlightAvatar } from '../components'; -import { busStatus, busStatusHighlight, isConnected, mqttStatusHighlight } from './EMSESPStatus'; +import { + RestFormProps, + FormActions, + FormButton, + HighlightAvatar, +} from "../components"; +import { + busStatus, + busStatusHighlight, + isConnected, + mqttStatusHighlight, +} from "./EMSESPStatus"; -import { EMSESPStatus } from './types'; +import { EMSESPStatus } from "./types"; type EMSESPStatusFormProps = RestFormProps & WithTheme; class EMSESPStatusForm extends Component { + createListItems() { + const { data, theme } = this.props; + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {isConnected(data) && ( + + + + + Statistic + # Telegrams + + + + + + + (Rx) Received telegrams + + {data.rx_received} + + + + (Rx) Incomplete telegrams + + {data.crc_errors} + + + + (Tx) Successfully sent telegrams + + {data.tx_sent} + + + + (Tx) Send failures + + {data.tx_errors} + + +
+
+ )} + + +
+ ); + } - createListItems() { - const { data, theme } = this.props; - return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { - isConnected(data) && - - - - - - Statistic - # Telegrams - - - - - - - Rx Received - - - {data.rx_received} - - - - - Tx Sent - - - {data.tx_sent} - - - - - CRC Errors - - - {data.crc_errors} - - - - - Tx Errors - - - {data.tx_errors} - - - - -
- -
- } - - - - - - - - - - - - -
- ); - } - - render() { - return ( - - - {this.createListItems()} - - - } variant="contained" color="secondary" onClick={this.props.loadData}> - Refresh + render() { + return ( + + {this.createListItems()} + + } + variant="contained" + color="secondary" + onClick={this.props.loadData} + > + Refresh - - - ); - } - + + + ); + } } export default withTheme(EMSESPStatusForm); diff --git a/interface/src/project/ProjectMenu.tsx b/interface/src/project/ProjectMenu.tsx index ce3cbd6e0..908b746f0 100644 --- a/interface/src/project/ProjectMenu.tsx +++ b/interface/src/project/ProjectMenu.tsx @@ -1,27 +1,30 @@ -import React, { Component } from 'react'; -import { Link, withRouter, RouteComponentProps } from 'react-router-dom'; +import React, { Component } from "react"; +import { Link, withRouter, RouteComponentProps } from "react-router-dom"; -import { List, ListItem, ListItemIcon, ListItemText } from '@material-ui/core'; -import SettingsRemoteIcon from '@material-ui/icons/SettingsRemote'; +import { List, ListItem, ListItemIcon, ListItemText } from "@material-ui/core"; +import SettingsRemoteIcon from "@material-ui/icons/SettingsRemote"; -import { PROJECT_PATH } from '../api'; +import { PROJECT_PATH } from "../api"; class ProjectMenu extends Component { - render() { const path = this.props.match.url; return ( - + - ) + ); } - } export default withRouter(ProjectMenu); From 2621a51dd2b37f80f56dbf516f2b576fbd2c2e3e Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 6 Jul 2020 13:35:04 +0200 Subject: [PATCH 6/6] updates to things that I need to fix --- TODO.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/TODO.md b/TODO.md index abbf7649e..7731c7ca5 100644 --- a/TODO.md +++ b/TODO.md @@ -1,11 +1,6 @@ - It's slow on ESP8266 - probably due to heap - AP not showing correct wifi SSID -- remove Serial.*s +- remove Serial.print's - add Boiler web page using web sockets -- check Chrome Tab errors -- check if we need to disabled UART during OTA +- check if we need to disabled UART during OTA on an ESP8266 - need to tie into the service - fix Makefile for standalone - -handy git commands -- git pull --tags -f -- git pull upstream master \ No newline at end of file