use host time to calculate the real event time

This commit is contained in:
lukas 2020-12-12 15:58:05 +01:00
parent 747e7bbbf8
commit 0817fcf492
3 changed files with 77 additions and 68 deletions

View File

@ -13,7 +13,10 @@ before_script:
build: build:
stage: build stage: build
script: "platformio run -e esp12e" script:
- "platformio run -e esp12e"
- vers=$(grep -Po '[0-9]*\.[0-9]*\.[0-9]*(?=\")' ./src/Pins.h)
- mv .pio/'build/esp12e/*.bin Pumpensteuerung-${vers}.bin
artifacts: artifacts:
paths: paths:
- .pio/build/esp12e/*.bin - ./*.bin

View File

@ -1,12 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {Box, List, ListItem, ListItemText} from '@material-ui/core'; import {Box, List, ListItem, ListItemText} from '@material-ui/core';
import { import {FormButton, restController, RestControllerProps, RestFormLoader, SectionContent} from '../components';
FormButton,
restController,
RestControllerProps,
RestFormLoader,
SectionContent
} from '../components';
import {ENDPOINT_ROOT} from "../api"; import {ENDPOINT_ROOT} from "../api";
import {GeneralInformaitonState} from "./types"; import {GeneralInformaitonState} from "./types";
import RefreshIcon from "@material-ui/icons/Refresh"; import RefreshIcon from "@material-ui/icons/Refresh";
@ -21,12 +15,6 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
componentDidMount() { componentDidMount() {
this.props.loadData(); this.props.loadData();
// this.intervalhandler = window.setInterval(() => {
// this.props.loadData();
// console.log("refreshing data");
// console.log(this.props.data)
// }, 10000);
} }
componentWillUnmount() { componentWillUnmount() {
@ -39,58 +27,62 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
<RestFormLoader <RestFormLoader
{...this.props} {...this.props}
render={props => ( render={props => (
<> <>
<List> <List>
<ListItem> <ListItem>
<ListItemText <ListItemText
primary="Chip läuft seit:" primary="Chip läuft seit:"
secondary={this.stringifyTime(props.data.runtime)} secondary={this.stringifyTime(props.data.runtime) + ' / ' + this.getRealTimeString(props.data.runtime)}
/> />
</ListItem> </ListItem>
<ListItem> <ListItem>
<ListItemText <ListItemText
primary="Zuletzt zu wenig Wasser:" primary="Zuletzt zu wenig Wasser:"
secondary={props.data.lastWaterOutage !== 0 ? "vor " + this.stringifyTime(props.data.lastWaterOutage) : "noch nie!"} secondary={props.data.lastWaterOutage !== 0 ? "vor " +
/> this.stringifyTime(props.data.lastWaterOutage) + ' / ' +
</ListItem> this.getRealTimeString(props.data.lastWaterOutage) : "noch nie!"}
<ListItem> />
<ListItemText </ListItem>
primary="Letzer Pumpenzyklus" <ListItem>
secondary={props.data.lastpumptime !== 0 ? "vor " + this.stringifyTime(props.data.lastpumptime) : "noch nie!"} <ListItemText
/> primary="Letzer Pumpenzyklus"
</ListItem> secondary={props.data.lastpumptime !== 0 ? "vor " +
<ListItem> this.stringifyTime(props.data.lastpumptime) + ' / ' +
<ListItemText this.getRealTimeString(props.data.lastpumptime) : "noch nie!"}
primary="Letze Pumpdauer:" />
secondary={props.data.lastPumpDuration !== 0 ? this.stringifyTime(props.data.lastPumpDuration) : "-"} </ListItem>
/> <ListItem>
</ListItem> <ListItemText
<ListItem> primary="Letze Pumpdauer:"
<ListItemText secondary={props.data.lastPumpDuration !== 0 ? this.stringifyTime(props.data.lastPumpDuration) : "-"}
primary="Temperatur/Luftfeuchtigkeit:" />
secondary={(props.data.temp !== -1 ? props.data.temp + "C" : "Auslesefehler!") + " / " + (props.data.hum !== -1 ? props.data.hum + "%" : "Auslesefehler!")} </ListItem>
/> <ListItem>
</ListItem> <ListItemText
<ListItem> primary="Temperatur/Luftfeuchtigkeit:"
<ListItemText secondary={(props.data.temp !== -1 ? props.data.temp + "C" : "Auslesefehler!") + " / " + (props.data.hum !== -1 ? props.data.hum + "%" : "Auslesefehler!")}
primary="WasserSensor / DruckSensor" />
secondary={(props.data.watersensor ? "EIN" : "AUS!") + " / " + (props.data.pressuresensor ? "EIN" : "AUS")} </ListItem>
/> <ListItem>
</ListItem> <ListItemText
</List> primary="WasserSensor / DruckSensor"
<Box display="flex" flexWrap="wrap"> secondary={(props.data.watersensor ? "EIN" : "AUS!") + " / " + (props.data.pressuresensor ? "EIN" : "AUS")}
<Box flexGrow={1} padding={1}> />
<FormButton startIcon={<RefreshIcon/>} variant="contained" color="secondary" </ListItem>
onClick={this.props.loadData}> </List>
Refresh <Box display="flex" flexWrap="wrap">
</FormButton> <Box flexGrow={1} padding={1}>
</Box> <FormButton startIcon={<RefreshIcon/>} variant="contained" color="secondary"
<Box flexWrap="none" padding={1} whiteSpace="nowrap"> onClick={this.props.loadData}>
Version: {props.data.version} Refresh
</Box> </FormButton>
</Box> </Box>
</> <Box flexWrap="none" padding={1} whiteSpace="nowrap">
)} Version: {props.data.version}
</Box>
</Box>
</>
)}
/> />
</SectionContent> </SectionContent>
); );
@ -100,7 +92,7 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
* stringify seconds to a pretty format * stringify seconds to a pretty format
* @param sec number of seconds * @param sec number of seconds
*/ */
stringifyTime(sec: number): string { private stringifyTime(sec: number): string {
if (sec >= 86400) { if (sec >= 86400) {
// display days // display days
return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec"); return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec");
@ -115,6 +107,20 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
return (sec + "sec"); return (sec + "sec");
} }
} }
private getRealTimeString(runtime: number): string {
const timestamp = Date.now();
const a = new Date(timestamp - (runtime * 1000));
const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
const year = a.getFullYear();
const month = months[a.getMonth()];
const date = a.getDate();
const hour = a.getHours();
const min = "0" + a.getMinutes();
const sec = "0" + a.getSeconds();
return '[' + date + ' ' + month + ' ' + year + ' ' + hour + ':' + min.substr(-2) + ':' + sec.substr(-2) + ']';
}
} }
export default restController(GENERALINFORMATION_SETTINGS_ENDPOINT, GeneralInformation); export default restController(GENERALINFORMATION_SETTINGS_ENDPOINT, GeneralInformation);

View File

@ -16,6 +16,6 @@
#define TempSensorPin D4 #define TempSensorPin D4
// version info // version info
#define VERSION "v1.2.1" #define VERSION "v1.2.2"
#endif //PUMPENSTEUERUNG_PINS_H #endif //PUMPENSTEUERUNG_PINS_H