Compare commits
	
		
			13 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 5cfd78f942 | |||
| 3a5f1a3a74 | |||
| 39a8ecde85 | |||
| a9671773f3 | |||
| 9c782879a5 | |||
| 2f38947ea4 | |||
| 5351bcb15d | |||
| 983d2b9ce7 | |||
| 62cea9932e | |||
| 3b502ac434 | |||
| 910797adaf | |||
| 72095dbe3e | |||
| c185fb7a8e | 
@@ -16,7 +16,7 @@ build:
 | 
				
			|||||||
  stage: build
 | 
					  stage: build
 | 
				
			||||||
  script:
 | 
					  script:
 | 
				
			||||||
    - "platformio run -e esp12e"
 | 
					    - "platformio run -e esp12e"
 | 
				
			||||||
    - vers=$(grep -Po '[0-9]*\.[0-9]*\.[0-9]*(?=\")' ./src/Pins.h)
 | 
					    - vers=$(grep -Po '[0-9]+\.[0-9]+\.[0-9]+[-0-9A-Za-z]*(?=\")' ./src/Pins.h)
 | 
				
			||||||
    - mv .pio/build/esp12e/*.bin Pumpensteuerung-${vers}.bin
 | 
					    - mv .pio/build/esp12e/*.bin Pumpensteuerung-${vers}.bin
 | 
				
			||||||
  artifacts:
 | 
					  artifacts:
 | 
				
			||||||
    paths:
 | 
					    paths:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,7 @@ build_flags =
 | 
				
			|||||||
    -D FACTORY_AP_LOCAL_IP=\"192.168.4.1\"
 | 
					    -D FACTORY_AP_LOCAL_IP=\"192.168.4.1\"
 | 
				
			||||||
    -D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\"
 | 
					    -D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\"
 | 
				
			||||||
    -D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\"
 | 
					    -D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\"
 | 
				
			||||||
 | 
					    -D FACTORY_AP_VISIBLE=true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ; User credentials for admin and guest user
 | 
					    ; User credentials for admin and guest user
 | 
				
			||||||
    -D FACTORY_ADMIN_USERNAME=\"admin\"
 | 
					    -D FACTORY_ADMIN_USERNAME=\"admin\"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,9 @@ import { TextValidator, ValidatorForm, SelectValidator } from 'react-material-ui
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import MenuItem from '@material-ui/core/MenuItem';
 | 
					import MenuItem from '@material-ui/core/MenuItem';
 | 
				
			||||||
import SaveIcon from '@material-ui/icons/Save';
 | 
					import SaveIcon from '@material-ui/icons/Save';
 | 
				
			||||||
 | 
					import Checkbox from '@material-ui/core/Checkbox';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { PasswordValidator, RestFormProps, FormActions, FormButton } from '../components';
 | 
					import {PasswordValidator, RestFormProps, FormActions, FormButton, BlockFormControlLabel} from '../components';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { isAPEnabled } from './APModes';
 | 
					import { isAPEnabled } from './APModes';
 | 
				
			||||||
import { APSettings, APProvisionMode } from './types';
 | 
					import { APSettings, APProvisionMode } from './types';
 | 
				
			||||||
@@ -91,6 +92,16 @@ class APSettingsForm extends React.Component<APSettingsFormProps> {
 | 
				
			|||||||
              onChange={handleValueChange('subnet_mask')}
 | 
					              onChange={handleValueChange('subnet_mask')}
 | 
				
			||||||
              margin="normal"
 | 
					              margin="normal"
 | 
				
			||||||
            />
 | 
					            />
 | 
				
			||||||
 | 
					              <BlockFormControlLabel
 | 
				
			||||||
 | 
					                  control={
 | 
				
			||||||
 | 
					                      <Checkbox
 | 
				
			||||||
 | 
					                          value="network_visible"
 | 
				
			||||||
 | 
					                          checked={data.network_visible}
 | 
				
			||||||
 | 
					                          onChange={handleValueChange("network_visible")}
 | 
				
			||||||
 | 
					                      />
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                  label="Network visible?"
 | 
				
			||||||
 | 
					              />
 | 
				
			||||||
          </Fragment>
 | 
					          </Fragment>
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        <FormActions>
 | 
					        <FormActions>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,4 +24,5 @@ export interface APSettings {
 | 
				
			|||||||
  local_ip: string;
 | 
					  local_ip: string;
 | 
				
			||||||
  gateway_ip: string;
 | 
					  gateway_ip: string;
 | 
				
			||||||
  subnet_mask: string;
 | 
					  subnet_mask: string;
 | 
				
			||||||
 | 
					  network_visible: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ import {FormButton, restController, RestControllerProps, RestFormLoader, Section
 | 
				
			|||||||
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";
 | 
				
			||||||
 | 
					import {getRealTimeString, stringifyTime} from "./Time";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// define api endpoint
 | 
					// define api endpoint
 | 
				
			||||||
export const GENERALINFORMATION_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "generalinfo";
 | 
					export const GENERALINFORMATION_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "generalinfo";
 | 
				
			||||||
@@ -11,16 +12,10 @@ export const GENERALINFORMATION_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "generalinfo
 | 
				
			|||||||
type GeneralInformationRestControllerProps = RestControllerProps<GeneralInformaitonState>;
 | 
					type GeneralInformationRestControllerProps = RestControllerProps<GeneralInformaitonState>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GeneralInformation extends Component<GeneralInformationRestControllerProps> {
 | 
					class GeneralInformation extends Component<GeneralInformationRestControllerProps> {
 | 
				
			||||||
    intervalhandler: number | undefined;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    componentDidMount() {
 | 
					    componentDidMount() {
 | 
				
			||||||
        this.props.loadData();
 | 
					        this.props.loadData();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    componentWillUnmount() {
 | 
					 | 
				
			||||||
        clearInterval(this.intervalhandler);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    render() {
 | 
					    render() {
 | 
				
			||||||
        return (
 | 
					        return (
 | 
				
			||||||
            <SectionContent title='Information' titleGutter>
 | 
					            <SectionContent title='Information' titleGutter>
 | 
				
			||||||
@@ -32,35 +27,40 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
 | 
				
			|||||||
                                <ListItem>
 | 
					                                <ListItem>
 | 
				
			||||||
                                    <ListItemText
 | 
					                                    <ListItemText
 | 
				
			||||||
                                        primary="Chip läuft seit:"
 | 
					                                        primary="Chip läuft seit:"
 | 
				
			||||||
                                        secondary={this.stringifyTime(props.data.runtime) + ' / ' + this.getRealTimeString(props.data.runtime)}
 | 
					                                        secondary={<>{stringifyTime(props.data.runtime)}
 | 
				
			||||||
 | 
					                                            <br/> {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 " +
 | 
					                                        secondary={props.data.lastWaterOutage !== 0 ?
 | 
				
			||||||
                                            this.stringifyTime(props.data.lastWaterOutage) + ' / ' +
 | 
					                                            <>
 | 
				
			||||||
                                            this.getRealTimeString(props.data.lastWaterOutage) : "noch nie!"}
 | 
					                                                vor {stringifyTime(props.data.lastWaterOutage)}<br/>
 | 
				
			||||||
 | 
					                                                {getRealTimeString(props.data.lastWaterOutage)}
 | 
				
			||||||
 | 
					                                            </> : "noch nie!"}
 | 
				
			||||||
                                    />
 | 
					                                    />
 | 
				
			||||||
                                </ListItem>
 | 
					                                </ListItem>
 | 
				
			||||||
                                <ListItem>
 | 
					                                <ListItem>
 | 
				
			||||||
                                    <ListItemText
 | 
					                                    <ListItemText
 | 
				
			||||||
                                        primary="Letzer Pumpenzyklus"
 | 
					                                        primary="Letzer Pumpenzyklus"
 | 
				
			||||||
                                        secondary={props.data.lastpumptime !== 0 ? "vor " +
 | 
					                                        secondary={props.data.lastpumptime !== 0 ?
 | 
				
			||||||
                                            this.stringifyTime(props.data.lastpumptime) + ' / ' +
 | 
					                                            <>
 | 
				
			||||||
                                            this.getRealTimeString(props.data.lastpumptime) : "noch nie!"}
 | 
					                                                vor {stringifyTime(props.data.lastpumptime)}<br/>
 | 
				
			||||||
 | 
					                                                {getRealTimeString(props.data.lastpumptime)}
 | 
				
			||||||
 | 
					                                            </> : "noch nie!"}
 | 
				
			||||||
                                    />
 | 
					                                    />
 | 
				
			||||||
                                </ListItem>
 | 
					                                </ListItem>
 | 
				
			||||||
                                <ListItem>
 | 
					                                <ListItem>
 | 
				
			||||||
                                    <ListItemText
 | 
					                                    <ListItemText
 | 
				
			||||||
                                        primary="Letze Pumpdauer:"
 | 
					                                        primary="Letze Pumpdauer:"
 | 
				
			||||||
                                        secondary={props.data.lastPumpDuration !== 0 ? this.stringifyTime(props.data.lastPumpDuration) : "-"}
 | 
					                                        secondary={props.data.lastPumpDuration !== 0 ? stringifyTime(props.data.lastPumpDuration) : "-"}
 | 
				
			||||||
                                    />
 | 
					                                    />
 | 
				
			||||||
                                </ListItem>
 | 
					                                </ListItem>
 | 
				
			||||||
                                <ListItem>
 | 
					                                <ListItem>
 | 
				
			||||||
                                    <ListItemText
 | 
					                                    <ListItemText
 | 
				
			||||||
                                        primary="Temperatur/Luftfeuchtigkeit:"
 | 
					                                        primary="Pumpzyklen seit Programmstart"
 | 
				
			||||||
                                        secondary={(props.data.temp !== -1 ? props.data.temp + "C" : "Auslesefehler!") + " / " + (props.data.hum !== -1 ? props.data.hum + "%" : "Auslesefehler!")}
 | 
					                                        secondary={props.data.pumpcycles}
 | 
				
			||||||
                                    />
 | 
					                                    />
 | 
				
			||||||
                                </ListItem>
 | 
					                                </ListItem>
 | 
				
			||||||
                                <ListItem>
 | 
					                                <ListItem>
 | 
				
			||||||
@@ -87,40 +87,6 @@ class GeneralInformation extends Component<GeneralInformationRestControllerProps
 | 
				
			|||||||
            </SectionContent>
 | 
					            </SectionContent>
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * stringify seconds to a pretty format
 | 
					 | 
				
			||||||
     * @param sec number of seconds
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private stringifyTime(sec: number): string {
 | 
					 | 
				
			||||||
        if (sec >= 86400) {
 | 
					 | 
				
			||||||
            // display days
 | 
					 | 
				
			||||||
            return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec");
 | 
					 | 
				
			||||||
        } else if (sec >= 3600) {
 | 
					 | 
				
			||||||
            // display hours
 | 
					 | 
				
			||||||
            return (Math.trunc(sec / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec");
 | 
					 | 
				
			||||||
        } else if (sec >= 60) {
 | 
					 | 
				
			||||||
            // only seconds and minutes
 | 
					 | 
				
			||||||
            return (Math.trunc(sec / 60) + "min " + sec % 60 + "sec");
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            // only seconds
 | 
					 | 
				
			||||||
            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);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										70
									
								
								interface/src/project/HeatingInformation.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								interface/src/project/HeatingInformation.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
				
			|||||||
 | 
					import React from "react";
 | 
				
			||||||
 | 
					import {FormButton, restController, RestControllerProps, RestFormLoader, SectionContent} from "../components";
 | 
				
			||||||
 | 
					import {ENDPOINT_ROOT} from "../api";
 | 
				
			||||||
 | 
					import {Box, List, ListItem, ListItemText} from "@material-ui/core";
 | 
				
			||||||
 | 
					import RefreshIcon from "@material-ui/icons/Refresh";
 | 
				
			||||||
 | 
					import {getRealTimeString, stringifyTime} from "./Time";
 | 
				
			||||||
 | 
					import {HeatingInformationState} from "./types";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// define api endpoint
 | 
				
			||||||
 | 
					export const HEATING_ENDPOINT = ENDPOINT_ROOT + "heatinginfo";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type HeatingRestcontollerprops = RestControllerProps<HeatingInformationState>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class HeatingInformation extends React.Component<HeatingRestcontollerprops> {
 | 
				
			||||||
 | 
					    componentDidMount() {
 | 
				
			||||||
 | 
					        this.props.loadData();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    render = () => (
 | 
				
			||||||
 | 
					        <SectionContent title='Heizung Information' titleGutter>
 | 
				
			||||||
 | 
					            <RestFormLoader
 | 
				
			||||||
 | 
					                {...this.props}
 | 
				
			||||||
 | 
					                render={props => (
 | 
				
			||||||
 | 
					                    <>
 | 
				
			||||||
 | 
					                        <List>
 | 
				
			||||||
 | 
					                            <ListItem>
 | 
				
			||||||
 | 
					                                <ListItemText
 | 
				
			||||||
 | 
					                                    primary="Heizung lief zuletzt:"
 | 
				
			||||||
 | 
					                                    secondary={props.data.lastheating !== 0 ?
 | 
				
			||||||
 | 
					                                        <>
 | 
				
			||||||
 | 
					                                            vor {stringifyTime(props.data.lastheating)}<br/>
 | 
				
			||||||
 | 
					                                            {getRealTimeString(props.data.lastheating)}
 | 
				
			||||||
 | 
					                                        </> : "noch nie!"}
 | 
				
			||||||
 | 
					                                />
 | 
				
			||||||
 | 
					                            </ListItem>
 | 
				
			||||||
 | 
					                            <ListItem>
 | 
				
			||||||
 | 
					                                <ListItemText
 | 
				
			||||||
 | 
					                                    primary="Letze Heizdauer:"
 | 
				
			||||||
 | 
					                                    secondary={props.data.lastheatduration === 0 ? "-" : props.data.lastheatduration === -1 ? "läuft gerade!" : stringifyTime(props.data.lastheatduration)}
 | 
				
			||||||
 | 
					                                />
 | 
				
			||||||
 | 
					                            </ListItem>
 | 
				
			||||||
 | 
					                            <ListItem>
 | 
				
			||||||
 | 
					                                <ListItemText
 | 
				
			||||||
 | 
					                                    primary="Gesammte Heizdauer / Prozentuelle Einschaltzeit"
 | 
				
			||||||
 | 
					                                    secondary={stringifyTime(props.data.totalheattime) + ' / ' + (props.data.heattimepercent * 100).toFixed(2) + '%'}
 | 
				
			||||||
 | 
					                                />
 | 
				
			||||||
 | 
					                            </ListItem>
 | 
				
			||||||
 | 
					                            <ListItem>
 | 
				
			||||||
 | 
					                                <ListItemText
 | 
				
			||||||
 | 
					                                    primary="Temperatur/Luftfeuchtigkeit:"
 | 
				
			||||||
 | 
					                                    secondary={(props.data.temp !== -1 ? props.data.temp + "C" : "Auslesefehler!") + " / " + (props.data.hum !== -1 ? props.data.hum + "%" : "Auslesefehler!")}
 | 
				
			||||||
 | 
					                                />
 | 
				
			||||||
 | 
					                            </ListItem>
 | 
				
			||||||
 | 
					                        </List>
 | 
				
			||||||
 | 
					                        <Box display="flex" flexWrap="wrap">
 | 
				
			||||||
 | 
					                            <Box flexGrow={1} padding={1}>
 | 
				
			||||||
 | 
					                                <FormButton startIcon={<RefreshIcon/>} variant="contained" color="secondary"
 | 
				
			||||||
 | 
					                                            onClick={this.props.loadData}>
 | 
				
			||||||
 | 
					                                    Refresh
 | 
				
			||||||
 | 
					                                </FormButton>
 | 
				
			||||||
 | 
					                            </Box>
 | 
				
			||||||
 | 
					                        </Box>
 | 
				
			||||||
 | 
					                    </>
 | 
				
			||||||
 | 
					                )}
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
 | 
					        </SectionContent>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default restController(HEATING_ENDPOINT, HeatingInformation);
 | 
				
			||||||
@@ -9,6 +9,7 @@ import { AuthenticatedRoute } from '../authentication';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import GeneralInformation from './GeneralInformation';
 | 
					import GeneralInformation from './GeneralInformation';
 | 
				
			||||||
import SettingsController from "./SettingsController";
 | 
					import SettingsController from "./SettingsController";
 | 
				
			||||||
 | 
					import HeatingInformation from "./HeatingInformation";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PumpControl extends Component<RouteComponentProps> {
 | 
					class PumpControl extends Component<RouteComponentProps> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -21,10 +22,12 @@ class PumpControl extends Component<RouteComponentProps> {
 | 
				
			|||||||
      <MenuAppBar sectionTitle="Wasserpumpensteuerung">
 | 
					      <MenuAppBar sectionTitle="Wasserpumpensteuerung">
 | 
				
			||||||
        <Tabs value={this.props.match.url} onChange={this.handleTabChange} variant="fullWidth">
 | 
					        <Tabs value={this.props.match.url} onChange={this.handleTabChange} variant="fullWidth">
 | 
				
			||||||
          <Tab value={`/${PROJECT_PATH}/pumpe/information`} label="Information" />
 | 
					          <Tab value={`/${PROJECT_PATH}/pumpe/information`} label="Information" />
 | 
				
			||||||
 | 
					            <Tab value={`/${PROJECT_PATH}/pumpe/heizung`} label="Heizung" />
 | 
				
			||||||
          <Tab value={`/${PROJECT_PATH}/pumpe/settings`} label="Einstellungen" />
 | 
					          <Tab value={`/${PROJECT_PATH}/pumpe/settings`} label="Einstellungen" />
 | 
				
			||||||
        </Tabs>
 | 
					        </Tabs>
 | 
				
			||||||
        <Switch>
 | 
					        <Switch>
 | 
				
			||||||
          <AuthenticatedRoute exact path={`/${PROJECT_PATH}/pumpe/information`} component={GeneralInformation} />
 | 
					          <AuthenticatedRoute exact path={`/${PROJECT_PATH}/pumpe/information`} component={GeneralInformation} />
 | 
				
			||||||
 | 
					            <AuthenticatedRoute exact path={`/${PROJECT_PATH}/pumpe/heizung`} component={HeatingInformation} />
 | 
				
			||||||
          <AuthenticatedRoute exact path={`/${PROJECT_PATH}/pumpe/settings`} component={SettingsController} />
 | 
					          <AuthenticatedRoute exact path={`/${PROJECT_PATH}/pumpe/settings`} component={SettingsController} />
 | 
				
			||||||
          <Redirect to={`/${PROJECT_PATH}/pumpe/information`} />
 | 
					          <Redirect to={`/${PROJECT_PATH}/pumpe/information`} />
 | 
				
			||||||
        </Switch>
 | 
					        </Switch>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										33
									
								
								interface/src/project/Time.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								interface/src/project/Time.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * stringify seconds to a pretty format
 | 
				
			||||||
 | 
					 * @param sec number of seconds
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function stringifyTime(sec: number): string {
 | 
				
			||||||
 | 
					    if (sec >= 86400) {
 | 
				
			||||||
 | 
					        // display days
 | 
				
			||||||
 | 
					        return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec");
 | 
				
			||||||
 | 
					    } else if (sec >= 3600) {
 | 
				
			||||||
 | 
					        // display hours
 | 
				
			||||||
 | 
					        return (Math.trunc(sec / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec");
 | 
				
			||||||
 | 
					    } else if (sec >= 60) {
 | 
				
			||||||
 | 
					        // only seconds and minutes
 | 
				
			||||||
 | 
					        return (Math.trunc(sec / 60) + "min " + sec % 60 + "sec");
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        // only seconds
 | 
				
			||||||
 | 
					        return (sec + "sec");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function 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) + ']';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -7,8 +7,6 @@ export interface SettingsState {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface GeneralInformaitonState {
 | 
					export interface GeneralInformaitonState {
 | 
				
			||||||
  hum: number;
 | 
					 | 
				
			||||||
  temp: number;
 | 
					 | 
				
			||||||
  lastpumptime: number;
 | 
					  lastpumptime: number;
 | 
				
			||||||
  lastWaterOutage: number;
 | 
					  lastWaterOutage: number;
 | 
				
			||||||
  lastPumpDuration: number;
 | 
					  lastPumpDuration: number;
 | 
				
			||||||
@@ -16,4 +14,14 @@ export interface GeneralInformaitonState {
 | 
				
			|||||||
  watersensor: boolean;
 | 
					  watersensor: boolean;
 | 
				
			||||||
  pressuresensor: boolean;
 | 
					  pressuresensor: boolean;
 | 
				
			||||||
  version: string;
 | 
					  version: string;
 | 
				
			||||||
 | 
					  pumpcycles: number;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface HeatingInformationState {
 | 
				
			||||||
 | 
					  lastheating: number;
 | 
				
			||||||
 | 
					  lastheatduration: number;
 | 
				
			||||||
 | 
					  hum: number;
 | 
				
			||||||
 | 
					  temp: number;
 | 
				
			||||||
 | 
					  totalheattime: number;
 | 
				
			||||||
 | 
					  heattimepercent: number;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@ void APSettingsService::manageAP() {
 | 
				
			|||||||
void APSettingsService::startAP() {
 | 
					void APSettingsService::startAP() {
 | 
				
			||||||
  Serial.println(F("Starting software access point"));
 | 
					  Serial.println(F("Starting software access point"));
 | 
				
			||||||
  WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
 | 
					  WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
 | 
				
			||||||
  WiFi.softAP(_state.ssid.c_str(), _state.password.c_str());
 | 
					  WiFi.softAP(_state.ssid.c_str(), _state.password.c_str(), 1, !_state.networkVisible);
 | 
				
			||||||
  if (!_dnsServer) {
 | 
					  if (!_dnsServer) {
 | 
				
			||||||
    IPAddress apIp = WiFi.softAPIP();
 | 
					    IPAddress apIp = WiFi.softAPIP();
 | 
				
			||||||
    Serial.print(F("Starting captive portal on "));
 | 
					    Serial.print(F("Starting captive portal on "));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,10 @@
 | 
				
			|||||||
#define FACTORY_AP_PASSWORD "esp-react"
 | 
					#define FACTORY_AP_PASSWORD "esp-react"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef FACTORY_AP_VISIBLE
 | 
				
			||||||
 | 
					#define FACTORY_AP_VISIBLE true
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef FACTORY_AP_LOCAL_IP
 | 
					#ifndef FACTORY_AP_LOCAL_IP
 | 
				
			||||||
#define FACTORY_AP_LOCAL_IP "192.168.4.1"
 | 
					#define FACTORY_AP_LOCAL_IP "192.168.4.1"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@@ -53,10 +57,11 @@ class APSettings {
 | 
				
			|||||||
  IPAddress localIP;
 | 
					  IPAddress localIP;
 | 
				
			||||||
  IPAddress gatewayIP;
 | 
					  IPAddress gatewayIP;
 | 
				
			||||||
  IPAddress subnetMask;
 | 
					  IPAddress subnetMask;
 | 
				
			||||||
 | 
					  bool networkVisible;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool operator==(const APSettings& settings) const {
 | 
					  bool operator==(const APSettings& settings) const {
 | 
				
			||||||
    return provisionMode == settings.provisionMode && ssid == settings.ssid && password == settings.password &&
 | 
					    return provisionMode == settings.provisionMode && ssid == settings.ssid && password == settings.password &&
 | 
				
			||||||
           localIP == settings.localIP && gatewayIP == settings.gatewayIP && subnetMask == settings.subnetMask;
 | 
					           localIP == settings.localIP && gatewayIP == settings.gatewayIP && subnetMask == settings.subnetMask && networkVisible == settings.networkVisible;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static void read(APSettings& settings, JsonObject& root) {
 | 
					  static void read(APSettings& settings, JsonObject& root) {
 | 
				
			||||||
@@ -66,6 +71,7 @@ class APSettings {
 | 
				
			|||||||
    root["local_ip"] = settings.localIP.toString();
 | 
					    root["local_ip"] = settings.localIP.toString();
 | 
				
			||||||
    root["gateway_ip"] = settings.gatewayIP.toString();
 | 
					    root["gateway_ip"] = settings.gatewayIP.toString();
 | 
				
			||||||
    root["subnet_mask"] = settings.subnetMask.toString();
 | 
					    root["subnet_mask"] = settings.subnetMask.toString();
 | 
				
			||||||
 | 
					    root["network_visible"] = settings.networkVisible;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static StateUpdateResult update(JsonObject& root, APSettings& settings) {
 | 
					  static StateUpdateResult update(JsonObject& root, APSettings& settings) {
 | 
				
			||||||
@@ -81,6 +87,7 @@ class APSettings {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    newSettings.ssid = root["ssid"] | FACTORY_AP_SSID;
 | 
					    newSettings.ssid = root["ssid"] | FACTORY_AP_SSID;
 | 
				
			||||||
    newSettings.password = root["password"] | FACTORY_AP_PASSWORD;
 | 
					    newSettings.password = root["password"] | FACTORY_AP_PASSWORD;
 | 
				
			||||||
 | 
					    newSettings.networkVisible = root["network_visible"] | FACTORY_AP_VISIBLE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    JsonUtils::readIP(root, "local_ip", newSettings.localIP, FACTORY_AP_LOCAL_IP);
 | 
					    JsonUtils::readIP(root, "local_ip", newSettings.localIP, FACTORY_AP_LOCAL_IP);
 | 
				
			||||||
    JsonUtils::readIP(root, "gateway_ip", newSettings.gatewayIP, FACTORY_AP_GATEWAY_IP);
 | 
					    JsonUtils::readIP(root, "gateway_ip", newSettings.gatewayIP, FACTORY_AP_GATEWAY_IP);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,12 +6,11 @@
 | 
				
			|||||||
#include "Pins.h"
 | 
					#include "Pins.h"
 | 
				
			||||||
#include "Timer.h"
 | 
					#include "Timer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GeneralInfoService::GeneralInfoService(AsyncWebServer *server, float *lasthum, float *lasttemp) :
 | 
					GeneralInfoService::GeneralInfoService(AsyncWebServer *server) :
 | 
				
			||||||
        hum(lasthum),
 | 
					 | 
				
			||||||
        temp(lasttemp),
 | 
					 | 
				
			||||||
        lastPumpTime(0),
 | 
					        lastPumpTime(0),
 | 
				
			||||||
        lastWaterOutage(0),
 | 
					        lastWaterOutage(0),
 | 
				
			||||||
        lastPumpDuration(0) {
 | 
					        lastPumpDuration(0),
 | 
				
			||||||
 | 
					        pumpCycles(0) {
 | 
				
			||||||
    server->on(GENERALINFO_SERVICE_PATH, HTTP_GET, std::bind(&GeneralInfoService::reply, this, std::placeholders::_1));
 | 
					    server->on(GENERALINFO_SERVICE_PATH, HTTP_GET, std::bind(&GeneralInfoService::reply, this, std::placeholders::_1));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,9 +18,6 @@ void GeneralInfoService::reply(AsyncWebServerRequest *request) {
 | 
				
			|||||||
    AsyncJsonResponse *response = new AsyncJsonResponse(false, MAX_FEATURES_SIZE);
 | 
					    AsyncJsonResponse *response = new AsyncJsonResponse(false, MAX_FEATURES_SIZE);
 | 
				
			||||||
    JsonObject root = response->getRoot();
 | 
					    JsonObject root = response->getRoot();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    root["temp"] = *temp;
 | 
					 | 
				
			||||||
    root["hum"] = *hum;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const uint32_t systime = Timer::getSystemSeconds();
 | 
					    const uint32_t systime = Timer::getSystemSeconds();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    root["lastpumptime"] = lastPumpTime != 0 ? systime - lastPumpTime : 0;
 | 
					    root["lastpumptime"] = lastPumpTime != 0 ? systime - lastPumpTime : 0;
 | 
				
			||||||
@@ -32,6 +28,8 @@ void GeneralInfoService::reply(AsyncWebServerRequest *request) {
 | 
				
			|||||||
    root["watersensor"] = digitalRead(WasserSensorPin) ? true : false;
 | 
					    root["watersensor"] = digitalRead(WasserSensorPin) ? true : false;
 | 
				
			||||||
    root["pressuresensor"] = digitalRead(DruckSensorPin) ? true : false;
 | 
					    root["pressuresensor"] = digitalRead(DruckSensorPin) ? true : false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    root["pumpcycles"] = pumpCycles;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    root["version"] = VERSION;
 | 
					    root["version"] = VERSION;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    response->setLength();
 | 
					    response->setLength();
 | 
				
			||||||
@@ -49,3 +47,7 @@ void GeneralInfoService::setlastWaterOutage(uint32_t lastWaterOutage) {
 | 
				
			|||||||
void GeneralInfoService::setPumpDuration(uint32_t lastPumpDuration) {
 | 
					void GeneralInfoService::setPumpDuration(uint32_t lastPumpDuration) {
 | 
				
			||||||
    this->lastPumpDuration = lastPumpDuration;
 | 
					    this->lastPumpDuration = lastPumpDuration;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void GeneralInfoService::setPumpCycles(uint32_t cycles) {
 | 
				
			||||||
 | 
					    this->pumpCycles = cycles;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class GeneralInfoService {
 | 
					class GeneralInfoService {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    GeneralInfoService(AsyncWebServer* server, float* lasthum, float* lasttemp);
 | 
					    GeneralInfoService(AsyncWebServer* server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * sets the last time when the pump was on
 | 
					     * sets the last time when the pump was on
 | 
				
			||||||
@@ -37,14 +37,14 @@ public:
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    void setPumpDuration(uint32_t lastPumpDuration);
 | 
					    void setPumpDuration(uint32_t lastPumpDuration);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void setPumpCycles(uint32_t i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void reply(AsyncWebServerRequest* request);
 | 
					    void reply(AsyncWebServerRequest* request);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    float * hum;
 | 
					 | 
				
			||||||
    float * temp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    unsigned long lastPumpTime, lastWaterOutage, lastPumpDuration;
 | 
					    unsigned long lastPumpTime, lastWaterOutage, lastPumpDuration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uint32_t pumpCycles;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,18 +4,22 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "Heating.h"
 | 
					#include "Heating.h"
 | 
				
			||||||
#include "Pins.h"
 | 
					#include "Pins.h"
 | 
				
			||||||
 | 
					#include "Timer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Heating::Heating() : mHeizungTicker(),
 | 
					Heating::Heating() : mHeizungTicker(),
 | 
				
			||||||
                     mLuefterTicker(),
 | 
					                     mLuefterTicker(),
 | 
				
			||||||
                     mTurnOffTicker(),
 | 
					                     mTurnOffTicker(),
 | 
				
			||||||
                     msettings(nullptr),
 | 
					                     msettings(nullptr),
 | 
				
			||||||
                     mHeatingStatus(),
 | 
					                     mheatingservice(nullptr),
 | 
				
			||||||
 | 
					                     mHeatingStatus(false),
 | 
				
			||||||
 | 
					                     mPumpCycleActive(false),
 | 
				
			||||||
                     lasttemp(0),
 | 
					                     lasttemp(0),
 | 
				
			||||||
                     lasthum(0),
 | 
					                     lasthum(0),
 | 
				
			||||||
                     sensor() {}
 | 
					                     sensor() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Heating::init(unsigned mode, const SettingState *settings) {
 | 
					void Heating::init(unsigned mode, const SettingState *settings, HeatingInfoService *heatingservice) {
 | 
				
			||||||
    msettings = settings;
 | 
					    msettings = settings;
 | 
				
			||||||
 | 
					    mheatingservice = heatingservice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch (mode) {
 | 
					    switch (mode) {
 | 
				
			||||||
        case TIME: {
 | 
					        case TIME: {
 | 
				
			||||||
@@ -27,10 +31,12 @@ void Heating::init(unsigned mode, const SettingState *settings) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            sensor.setPin(TempSensorPin);
 | 
					            sensor.setPin(TempSensorPin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            sensor.onData([this, settings](float hum, float temp) {
 | 
					            sensor.onData([this](float hum, float temp) {
 | 
				
			||||||
                schedule_function([hum, temp, settings, this]() {
 | 
					                schedule_function([hum, temp, this]() {
 | 
				
			||||||
                    Serial.printf("Temp: %gdegC\n", temp);
 | 
					//                    Serial.printf("Temp: %gdegC\n", temp);
 | 
				
			||||||
                    Serial.printf("Humid: %g%%\n", hum);
 | 
					//                    Serial.printf("Humid: %g%%\n", hum);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    mheatingservice->setSensorData(hum, temp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    this->lasttemp = temp;
 | 
					                    this->lasttemp = temp;
 | 
				
			||||||
                    this->lasthum = hum;
 | 
					                    this->lasthum = hum;
 | 
				
			||||||
@@ -43,18 +49,23 @@ void Heating::init(unsigned mode, const SettingState *settings) {
 | 
				
			|||||||
                this->lasttemp = -1.0;
 | 
					                this->lasttemp = -1.0;
 | 
				
			||||||
                this->lasthum = -1.0;
 | 
					                this->lasthum = -1.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                mheatingservice->setSensorData(-1.0, -1.0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // emergency turnoff of heating
 | 
					                // emergency turnoff of heating
 | 
				
			||||||
                if (mHeatingStatus) {
 | 
					                if (mHeatingStatus) {
 | 
				
			||||||
                    digitalWrite(HeizungPin, LOW);
 | 
					                    digitalWrite(HeizungPin, LOW);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                schedule_function([e]() {
 | 
					//                schedule_function([e]() {
 | 
				
			||||||
                    Serial.printf("Error: %d\n", e);
 | 
					//                    Serial.printf("Error: %d\n", e);
 | 
				
			||||||
                });
 | 
					//                });
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            mHeizungTicker.attach(10, [this]() {
 | 
					            mHeizungTicker.attach(10, [this]() {
 | 
				
			||||||
 | 
					                // only check if no pump cycle is active
 | 
				
			||||||
 | 
					                if (!mPumpCycleActive) {
 | 
				
			||||||
                    sensor.read();
 | 
					                    sensor.read();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
@@ -63,27 +74,30 @@ void Heating::init(unsigned mode, const SettingState *settings) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
float *Heating::getLastTemp() {
 | 
					 | 
				
			||||||
    return &lasttemp;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
float *Heating::getLastHum() {
 | 
					 | 
				
			||||||
    return &lasthum;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void Heating::handleHeatingEvents() {
 | 
					void Heating::handleHeatingEvents() {
 | 
				
			||||||
    if (this->lasthum > (float) msettings->heatUp) {
 | 
					    if (this->lasthum > (float) msettings->heatUp) {
 | 
				
			||||||
 | 
					        // only turn on if turned off
 | 
				
			||||||
 | 
					        if (mHeatingStatus == false) {
 | 
				
			||||||
            // turn off active turnoff timers
 | 
					            // turn off active turnoff timers
 | 
				
			||||||
            mLuefterTicker.detach();
 | 
					            mLuefterTicker.detach();
 | 
				
			||||||
        Serial.println("heating should run now!");
 | 
					            //Serial.println("heating should run now!");
 | 
				
			||||||
        // turn on heating and fan
 | 
					
 | 
				
			||||||
            digitalWrite(LuefterPin, HIGH);
 | 
					            digitalWrite(LuefterPin, HIGH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            digitalWrite(HeizungPin, HIGH);
 | 
					            digitalWrite(HeizungPin, HIGH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            mHeatingStatus = true;
 | 
					            mHeatingStatus = true;
 | 
				
			||||||
 | 
					            mheatingservice->setLastHeatingStarttime(Timer::getSystemSeconds());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            mheatingservice->setLastHetingEndtime(0);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    } else if (this->lasthum < (float) msettings->heatLow) {
 | 
					    } else if (this->lasthum < (float) msettings->heatLow) {
 | 
				
			||||||
        // if humidity too low turn off heating and fan after 60secs
 | 
					        // if humidity too low turn off heating and fan after 60secs
 | 
				
			||||||
 | 
					        if (mHeatingStatus == true) {
 | 
				
			||||||
            digitalWrite(HeizungPin, LOW);
 | 
					            digitalWrite(HeizungPin, LOW);
 | 
				
			||||||
        Serial.println("heating should NOT run now!");
 | 
					            ////Serial.println("heating should NOT run now!");
 | 
				
			||||||
 | 
					            // add the heat time it took to the total
 | 
				
			||||||
 | 
					            mheatingservice->addHeatTime(Timer::getSystemSeconds() - mheatingservice->getLastHeatingStartTime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // if heating status in on set ticker to turn of fan in 60sec
 | 
					            // if heating status in on set ticker to turn of fan in 60sec
 | 
				
			||||||
            if (mHeatingStatus) {
 | 
					            if (mHeatingStatus) {
 | 
				
			||||||
@@ -91,13 +105,15 @@ void Heating::handleHeatingEvents() {
 | 
				
			|||||||
                    // turn off fan
 | 
					                    // turn off fan
 | 
				
			||||||
                    digitalWrite(LuefterPin, LOW);
 | 
					                    digitalWrite(LuefterPin, LOW);
 | 
				
			||||||
                    schedule_function([]() {
 | 
					                    schedule_function([]() {
 | 
				
			||||||
                    Serial.println("turning off fan");
 | 
					                        ////Serial.println("turning off fan");
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            mheatingservice->setLastHetingEndtime(Timer::getSystemSeconds());
 | 
				
			||||||
            mHeatingStatus = false;
 | 
					            mHeatingStatus = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Heating::handleTimeHeater() {
 | 
					void Heating::handleTimeHeater() {
 | 
				
			||||||
    const unsigned percentOn = 20;
 | 
					    const unsigned percentOn = 20;
 | 
				
			||||||
@@ -110,21 +126,46 @@ void Heating::handleTimeHeater() {
 | 
				
			|||||||
        digitalWrite(LuefterPin, HIGH);
 | 
					        digitalWrite(LuefterPin, HIGH);
 | 
				
			||||||
        digitalWrite(HeizungPin, HIGH);
 | 
					        digitalWrite(HeizungPin, HIGH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Serial.println("Turning on heating");
 | 
					        ////Serial.println("Turning on heating");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() {
 | 
					        mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() {
 | 
				
			||||||
            digitalWrite(HeizungPin, LOW);
 | 
					            digitalWrite(HeizungPin, LOW);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Serial.println("Turned off heating!");
 | 
					            ////Serial.println("Turned off heating!");
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() {
 | 
					        mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() {
 | 
				
			||||||
            digitalWrite(LuefterPin, LOW);
 | 
					            digitalWrite(LuefterPin, LOW);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Serial.println("Turned off fan!");
 | 
					            ////Serial.println("Turned off fan!");
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    func();
 | 
					    func();
 | 
				
			||||||
    mHeizungTicker.attach(refreshperiod, func);
 | 
					    mHeizungTicker.attach(refreshperiod, func);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Heating::setPumCycleActive(bool active) {
 | 
				
			||||||
 | 
					    mPumpCycleActive = active;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // turn off fan if pumpcycleactive
 | 
				
			||||||
 | 
					    if (active) {
 | 
				
			||||||
 | 
					        digitalWrite(LuefterPin, LOW);
 | 
				
			||||||
 | 
					        digitalWrite(HeizungPin, LOW);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        mHeizungTicker.detach();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (mHeatingStatus) {
 | 
				
			||||||
 | 
					            // to add the correct time to the heat min counter!
 | 
				
			||||||
 | 
					            mheatingservice->addHeatTime(Timer::getSystemSeconds() - mheatingservice->getLastHeatingStartTime());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        mHeizungTicker.detach();
 | 
				
			||||||
 | 
					        mHeizungTicker.attach(10, [this]() {
 | 
				
			||||||
 | 
					            // only check if no pump cycle is active
 | 
				
			||||||
 | 
					            if (!mPumpCycleActive) {
 | 
				
			||||||
 | 
					                sensor.read();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@
 | 
				
			|||||||
#include <DHT.h>
 | 
					#include <DHT.h>
 | 
				
			||||||
#include "Pins.h"
 | 
					#include "Pins.h"
 | 
				
			||||||
#include "SettingsService.h"
 | 
					#include "SettingsService.h"
 | 
				
			||||||
 | 
					#include "HeatingInfoService.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Heating {
 | 
					class Heating {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
@@ -18,19 +19,9 @@ public:
 | 
				
			|||||||
     * @param mode select the operating mode
 | 
					     * @param mode select the operating mode
 | 
				
			||||||
     * @param settings a settings object is needed for HUMIDITY mode to get percent values set by user
 | 
					     * @param settings a settings object is needed for HUMIDITY mode to get percent values set by user
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void init(unsigned mode, const SettingState* settings);
 | 
					    void init(unsigned mode, const SettingState* settings, HeatingInfoService *heatingservice);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    void setPumCycleActive(bool active);
 | 
				
			||||||
     * get the last captured humidity value
 | 
					 | 
				
			||||||
     * @return humidity value
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    float* getLastHum();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * get the last captured temperature value
 | 
					 | 
				
			||||||
     * @return temperature value
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    float* getLastTemp();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    enum MODES {TIME, HUMIDITY};
 | 
					    enum MODES {TIME, HUMIDITY};
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
@@ -39,8 +30,9 @@ private:
 | 
				
			|||||||
    Ticker mTurnOffTicker;
 | 
					    Ticker mTurnOffTicker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const SettingState* msettings;
 | 
					    const SettingState* msettings;
 | 
				
			||||||
 | 
					    HeatingInfoService *mheatingservice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool mHeatingStatus;
 | 
					    bool mHeatingStatus, mPumpCycleActive;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    float lasttemp;
 | 
					    float lasttemp;
 | 
				
			||||||
    float lasthum;
 | 
					    float lasthum;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										58
									
								
								src/HeatingInfoService.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								src/HeatingInfoService.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Created by lukas on 19.12.20.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <AsyncJson.h>
 | 
				
			||||||
 | 
					#include "HeatingInfoService.h"
 | 
				
			||||||
 | 
					#include "Timer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					HeatingInfoService::HeatingInfoService(AsyncWebServer *server) :
 | 
				
			||||||
 | 
					        hum(-1),
 | 
				
			||||||
 | 
					        temp(-1),
 | 
				
			||||||
 | 
					        lastheating(0),
 | 
				
			||||||
 | 
					        lastheatend(0),
 | 
				
			||||||
 | 
					        totalHeatTime(0) {
 | 
				
			||||||
 | 
					    server->on(HEATINGINFO_SERVICE_PATH, HTTP_GET, std::bind(&HeatingInfoService::reply, this, std::placeholders::_1));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void HeatingInfoService::reply(AsyncWebServerRequest *request) {
 | 
				
			||||||
 | 
					    AsyncJsonResponse *response = new AsyncJsonResponse(false, MAX_FEATURES_SIZE);
 | 
				
			||||||
 | 
					    JsonObject root = response->getRoot();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    root["temp"] = temp;
 | 
				
			||||||
 | 
					    root["hum"] = hum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const uint32_t systime = Timer::getSystemSeconds();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    root["lastheating"] = lastheating != 0 ? systime - lastheating : 0;
 | 
				
			||||||
 | 
					    // if lastheating == 0 => there was no cycle upon now
 | 
				
			||||||
 | 
					    // if lastheatend == 0 => heating is currently active
 | 
				
			||||||
 | 
					    root["lastheatduration"] = lastheating == 0 ? 0 : lastheatend == 0 ? -1 : lastheatend - lastheating;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    root["totalheattime"] = this->totalHeatTime;
 | 
				
			||||||
 | 
					    root["heattimepercent"] = (float)this->totalHeatTime / (float)Timer::getSystemSeconds();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    response->setLength();
 | 
				
			||||||
 | 
					    request->send(response);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void HeatingInfoService::setSensorData(float hum, float temp) {
 | 
				
			||||||
 | 
					    this->hum = hum;
 | 
				
			||||||
 | 
					    this->temp = temp;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void HeatingInfoService::setLastHeatingStarttime(unsigned long time) {
 | 
				
			||||||
 | 
					    this->lastheating = time;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void HeatingInfoService::setLastHetingEndtime(unsigned long time) {
 | 
				
			||||||
 | 
					    this->lastheatend = time;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					uint32_t HeatingInfoService::getLastHeatingStartTime() {
 | 
				
			||||||
 | 
					    return this->lastheating;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void HeatingInfoService::addHeatTime(uint32_t time) {
 | 
				
			||||||
 | 
					    totalHeatTime += time;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										44
									
								
								src/HeatingInfoService.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/HeatingInfoService.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
				
			|||||||
 | 
					//
 | 
				
			||||||
 | 
					// Created by lukas on 19.12.20.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef PUMPENSTEUERUNG_HEATINGINFOSERVICE_H
 | 
				
			||||||
 | 
					#define PUMPENSTEUERUNG_HEATINGINFOSERVICE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <ESPAsyncWebServer.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MAX_FEATURES_SIZE 256
 | 
				
			||||||
 | 
					#define HEATINGINFO_SERVICE_PATH "/rest/heatinginfo" // set the api backend path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class HeatingInfoService {
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    HeatingInfoService(AsyncWebServer* server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void setSensorData(float hum, float temp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void setLastHeatingStarttime(unsigned long time);
 | 
				
			||||||
 | 
					    uint32_t getLastHeatingStartTime();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void setLastHetingEndtime(unsigned long time);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * add time how long the heater heated
 | 
				
			||||||
 | 
					     * @param time time in seconds
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    void addHeatTime(uint32_t time);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					    void reply(AsyncWebServerRequest* request);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    float hum;
 | 
				
			||||||
 | 
					    float temp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    unsigned long lastheating;
 | 
				
			||||||
 | 
					    unsigned long lastheatend;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uint32_t totalHeatTime;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif //PUMPENSTEUERUNG_HEATINGINFOSERVICE_H
 | 
				
			||||||
@@ -16,6 +16,6 @@
 | 
				
			|||||||
#define TempSensorPin  D4
 | 
					#define TempSensorPin  D4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// version info
 | 
					// version info
 | 
				
			||||||
#define VERSION "v1.2.2"
 | 
					#define VERSION "v1.2.4-Alpa1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif //PUMPENSTEUERUNG_PINS_H
 | 
					#endif //PUMPENSTEUERUNG_PINS_H
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,12 +17,12 @@ SettingsService::SettingsService(AsyncWebServer *server, SecurityManager *securi
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SettingsService::onConfigUpdated() {
 | 
					void SettingsService::onConfigUpdated() {
 | 
				
			||||||
    Serial.println("switching led!");
 | 
					    ////Serial.println("switching led!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    File settingsFile = ESPFS.open("settings.json", "w+");
 | 
					    File settingsFile = ESPFS.open("settings.json", "w+");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (settingsFile) {
 | 
					    if (settingsFile) {
 | 
				
			||||||
        Serial.println("writing config file!");
 | 
					        ////Serial.println("writing config file!");
 | 
				
			||||||
        StaticJsonDocument<256> doc;
 | 
					        StaticJsonDocument<256> doc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        doc["waterOutageWaitDuration"] = _state.waterOutageWaitDuration;
 | 
					        doc["waterOutageWaitDuration"] = _state.waterOutageWaitDuration;
 | 
				
			||||||
@@ -46,7 +46,7 @@ void SettingsService::begin() {
 | 
				
			|||||||
        // Deserialize the JSON document
 | 
					        // Deserialize the JSON document
 | 
				
			||||||
        DeserializationError error = deserializeJson(doc, settingsFile);
 | 
					        DeserializationError error = deserializeJson(doc, settingsFile);
 | 
				
			||||||
        if (error) {
 | 
					        if (error) {
 | 
				
			||||||
            Serial.println(F("Failed to read file, using default configuration"));
 | 
					            ////Serial.println(F("Failed to read file, using default configuration"));
 | 
				
			||||||
            onConfigUpdated();
 | 
					            onConfigUpdated();
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -59,7 +59,7 @@ void SettingsService::begin() {
 | 
				
			|||||||
        _state.heatLow = doc["heatLow"] | 65;
 | 
					        _state.heatLow = doc["heatLow"] | 65;
 | 
				
			||||||
        _state.fanRuntime = doc["fanRuntime"] | 60;
 | 
					        _state.fanRuntime = doc["fanRuntime"] | 60;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Serial.println("read config file!");
 | 
					        ////Serial.println("read config file!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        settingsFile.close();
 | 
					        settingsFile.close();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										72
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -6,6 +6,7 @@
 | 
				
			|||||||
#include "GeneralInfoService.h"
 | 
					#include "GeneralInfoService.h"
 | 
				
			||||||
#include "SettingsService.h"
 | 
					#include "SettingsService.h"
 | 
				
			||||||
#include "Timer.h"
 | 
					#include "Timer.h"
 | 
				
			||||||
 | 
					#include "HeatingInfoService.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool allow;
 | 
					bool allow;
 | 
				
			||||||
bool error = false;
 | 
					bool error = false;
 | 
				
			||||||
@@ -20,66 +21,81 @@ Ticker pumpendauer;
 | 
				
			|||||||
Heating mHeat;
 | 
					Heating mHeat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint32_t turnontime = 0;
 | 
					uint32_t turnontime = 0;
 | 
				
			||||||
 | 
					uint32_t pumpcycles = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AsyncWebServer server(80);
 | 
					AsyncWebServer server(80);
 | 
				
			||||||
ESP8266React esp8266React(&server);
 | 
					ESP8266React esp8266React(&server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GeneralInfoService generalinfo = GeneralInfoService(&server, mHeat.getLastHum(), mHeat.getLastTemp());
 | 
					GeneralInfoService generalinfo = GeneralInfoService(&server);
 | 
				
			||||||
 | 
					HeatingInfoService heatinginfo = HeatingInfoService(&server);
 | 
				
			||||||
SettingsService settingsservice = SettingsService(&server, esp8266React.getSecurityManager());
 | 
					SettingsService settingsservice = SettingsService(&server, esp8266React.getSecurityManager());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pumpeSchalten(bool on) {
 | 
					void pumpeSchalten(bool on) {
 | 
				
			||||||
    //    digitalWrite(4,on);
 | 
					    //    digitalWrite(4,on);
 | 
				
			||||||
    if (on) {
 | 
					    if (on) {
 | 
				
			||||||
        Serial.println("versuche Pumpe EIN zuschalten");
 | 
					        //Serial.println("versuche Pumpe EIN zuschalten");
 | 
				
			||||||
        // refresh last pump counter
 | 
					        // refresh last pump counter
 | 
				
			||||||
        generalinfo.setlastPumpTime(Timer::getSystemSeconds());
 | 
					        generalinfo.setlastPumpTime(Timer::getSystemSeconds());
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        Serial.println("versuche Pumpe AUS zuschalten");
 | 
					        //Serial.println("versuche Pumpe AUS zuschalten");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (allow && !error) {
 | 
					    if (allow && !error) {
 | 
				
			||||||
        if (on) {
 | 
					        if (on) {
 | 
				
			||||||
 | 
					            pumpcycles++;
 | 
				
			||||||
 | 
					            generalinfo.setPumpCycles(pumpcycles);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // pump cycle started
 | 
				
			||||||
 | 
					            mHeat.setPumCycleActive(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            pumpendauer.once((float) settingsservice.getSettings()->maxpumpduration + 1, []() {
 | 
					            pumpendauer.once((float) settingsservice.getSettings()->maxpumpduration + 1, []() {
 | 
				
			||||||
                //erlaube keine einschaltung von mehr als 60 sek
 | 
					                //erlaube keine einschaltung von mehr als 60 sek
 | 
				
			||||||
                if (Timer::getSystemSeconds() - turnontime >= (unsigned)settingsservice.getSettings()->maxpumpduration && turnontime != 0) {
 | 
					                if (Timer::getSystemSeconds() - turnontime >=
 | 
				
			||||||
 | 
					                    (unsigned) settingsservice.getSettings()->maxpumpduration && turnontime != 0) {
 | 
				
			||||||
                    //error zu lange
 | 
					                    //error zu lange
 | 
				
			||||||
                    Serial.println("\n\npumpe lief mehr als 10 Minuten durchgaengig");
 | 
					                    //Serial.println("\n\npumpe lief mehr als 10 Minuten durchgaengig");
 | 
				
			||||||
                    pumpeSchalten(false);
 | 
					                    pumpeSchalten(false);
 | 
				
			||||||
                    error = true;
 | 
					                    error = true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            generalinfo.setPumpDuration(Timer::getSystemSeconds() - turnontime);
 | 
					            generalinfo.setPumpDuration(Timer::getSystemSeconds() - turnontime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // pump cycle stopped...
 | 
				
			||||||
 | 
					            mHeat.setPumCycleActive(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // save pump start time
 | 
					        // save pump start time
 | 
				
			||||||
        turnontime = Timer::getSystemSeconds();
 | 
					        turnontime = Timer::getSystemSeconds();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        digitalWrite(SchuetzPin, on);
 | 
					        digitalWrite(SchuetzPin, on);
 | 
				
			||||||
        Serial.println("[Erfolg] pumpe wird geschalten");
 | 
					        //Serial.println("[Erfolg] pumpe wird geschalten");
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        Serial.println("[FEHLGESCHLAGEN] Schalten des Schütz gesperrt durch Timeout oder Fehler-- sofortiges ausschalten der pumpe\n");
 | 
					        //Serial.println("[FEHLGESCHLAGEN] Schalten des Schütz gesperrt durch Timeout oder Fehler-- sofortiges ausschalten der pumpe\n");
 | 
				
			||||||
        turnontime = -1;
 | 
					        turnontime = -1;
 | 
				
			||||||
        digitalWrite(SchuetzPin, LOW);
 | 
					        digitalWrite(SchuetzPin, LOW);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ICACHE_RAM_ATTR void DruckschalterInt() {
 | 
					ICACHE_RAM_ATTR void DruckschalterInt() {
 | 
				
			||||||
 | 
					    schedule_function([]() {
 | 
				
			||||||
        if (digitalRead(DruckSensorPin) == HIGH) {
 | 
					        if (digitalRead(DruckSensorPin) == HIGH) {
 | 
				
			||||||
            //pumpe einschalten
 | 
					            //pumpe einschalten
 | 
				
			||||||
        Serial.println("\n\nDruck Sensor EIN");
 | 
					            //Serial.println("\n\nDruck Sensor EIN");
 | 
				
			||||||
            if (digitalRead(WasserSensorPin)) {
 | 
					            if (digitalRead(WasserSensorPin)) {
 | 
				
			||||||
            Serial.println("Wasser Sensor EIN");
 | 
					                //Serial.println("Wasser Sensor EIN");
 | 
				
			||||||
                pumpeSchalten(true);
 | 
					                pumpeSchalten(true);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
            Serial.println("Wasser Sensor aus irgent einem Grund doch nicht ein -- sofort abschalten!");
 | 
					                //Serial.println("Wasser Sensor aus irgent einem Grund doch nicht ein -- sofort abschalten!");
 | 
				
			||||||
                pumpeSchalten(false);
 | 
					                pumpeSchalten(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            //pumpe ausschalten
 | 
					            //pumpe ausschalten
 | 
				
			||||||
        Serial.println("\n\nDruck Sensor AUS");
 | 
					            //Serial.println("\n\nDruck Sensor AUS");
 | 
				
			||||||
            pumpeSchalten(false);
 | 
					            pumpeSchalten(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// time counter to wait
 | 
					// time counter to wait
 | 
				
			||||||
@@ -87,48 +103,50 @@ int wateroutagewaitduration;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void WasserSensorCheck() {
 | 
					void WasserSensorCheck() {
 | 
				
			||||||
    if (digitalRead(WasserSensorPin) == LOW) {
 | 
					    if (digitalRead(WasserSensorPin) == LOW) {
 | 
				
			||||||
        Serial.println("Wasser Sensor AUS");
 | 
					        //Serial.println("Wasser Sensor AUS");
 | 
				
			||||||
        //kein Wasser dh timer auf 10min stellen
 | 
					        //kein Wasser dh timer auf 10min stellen
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // refresh wateroutage counter
 | 
					        // refresh wateroutage counter
 | 
				
			||||||
        generalinfo.setlastWaterOutage(Timer::getSystemSeconds());
 | 
					        generalinfo.setlastWaterOutage(Timer::getSystemSeconds());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        allow = false;
 | 
					        allow = false;
 | 
				
			||||||
        Serial.println("Schalte pumpe aus");
 | 
					        //Serial.println("Schalte pumpe aus");
 | 
				
			||||||
        pumpeSchalten(false);
 | 
					        pumpeSchalten(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Serial.println("warte 30min");
 | 
					        //Serial.println("warte 30min");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        status.detach();
 | 
					        status.detach();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        wateroutagewaitduration = settingsservice.getSettings()->waterOutageWaitDuration;
 | 
					        wateroutagewaitduration = settingsservice.getSettings()->waterOutageWaitDuration;
 | 
				
			||||||
        status.attach(5, []() {
 | 
					        status.attach(5, []() {
 | 
				
			||||||
            wateroutagewaitduration -= 5;
 | 
					            wateroutagewaitduration -= 5;
 | 
				
			||||||
            Serial.print("noch ");
 | 
					            //Serial.print("noch ");
 | 
				
			||||||
            Serial.print(wateroutagewaitduration);
 | 
					            //Serial.print(wateroutagewaitduration);
 | 
				
			||||||
            Serial.println(" Sekunden verbleibend");
 | 
					            //Serial.println(" Sekunden verbleibend");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (wateroutagewaitduration <= 0) {
 | 
					            if (wateroutagewaitduration <= 0) {
 | 
				
			||||||
                if (digitalRead(WasserSensorPin)) {
 | 
					                if (digitalRead(WasserSensorPin)) {
 | 
				
			||||||
                    allow = true;
 | 
					                    allow = true;
 | 
				
			||||||
                    Serial.println("Einschalten der Pumpe wieder erlaubt.");
 | 
					                    //Serial.println("Einschalten der Pumpe wieder erlaubt.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    //pruefen ob drucksensor ein
 | 
					                    //pruefen ob drucksensor ein
 | 
				
			||||||
                    DruckschalterInt();
 | 
					                    DruckschalterInt();
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    Serial.print("wassersensor immer noch kein Wasser --> verlaengern um 120min\n\n");
 | 
					                    //Serial.print("wassersensor immer noch kein Wasser --> verlaengern um 120min\n\n");
 | 
				
			||||||
                    WasserSensorCheck();
 | 
					                    WasserSensorCheck();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                status.detach();
 | 
					                status.detach();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        Serial.println("Wasser Sensor EIN");
 | 
					        //Serial.println("Wasser Sensor EIN");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ICACHE_RAM_ATTR void WasserSensorInt() {
 | 
					ICACHE_RAM_ATTR void WasserSensorInt() {
 | 
				
			||||||
 | 
					    schedule_function([]() {
 | 
				
			||||||
        WasserSensorCheck();
 | 
					        WasserSensorCheck();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void setup() {
 | 
					void setup() {
 | 
				
			||||||
@@ -149,9 +167,9 @@ void setup() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // initilize serial connection
 | 
					    // initilize serial connection
 | 
				
			||||||
    Serial.begin(115200);
 | 
					    Serial.begin(115200);
 | 
				
			||||||
    Serial.println("\n\n\n\nstartup of ESP");
 | 
					    //Serial.println("\n\n\n\nstartup of ESP");
 | 
				
			||||||
    Serial.print("Version: ");
 | 
					    //Serial.print("Version: ");
 | 
				
			||||||
    Serial.println(VERSION);
 | 
					    //Serial.println(VERSION);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //initial measurement of water state
 | 
					    //initial measurement of water state
 | 
				
			||||||
@@ -173,16 +191,16 @@ void setup() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // initialize wifi
 | 
					    // initialize wifi
 | 
				
			||||||
    Serial.println("Initializing wifi");
 | 
					    //Serial.println("Initializing wifi");
 | 
				
			||||||
    esp8266React.begin();
 | 
					    esp8266React.begin();
 | 
				
			||||||
    settingsservice.begin();
 | 
					    settingsservice.begin();
 | 
				
			||||||
    server.begin();
 | 
					    server.begin();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // initialize heating control
 | 
					    // initialize heating control
 | 
				
			||||||
    Serial.println("initializing heating service");
 | 
					    //Serial.println("initializing heating service");
 | 
				
			||||||
    mHeat.init(Heating::HUMIDITY, settingsservice.getSettings());
 | 
					    mHeat.init(Heating::HUMIDITY, settingsservice.getSettings(), &heatinginfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Serial.println("startup sequence complete!\n");
 | 
					    //Serial.println("startup sequence complete!\n");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user