Dr. Arne Jachens

Set up the Raspberry Pi

no warranty for any of the provided information

Keine Erläuterungen gefunden.

import  os
from stat import  * 
import  json

class HvcOperationMode:
    
    def  __init__(self):
        """
        Initialization, specify the configuration file.
        """
        self.opModFile = "./ConfDir/operationMode.yml"
        self.paramFile = "./ConfDir/parameters.yml"

    def  read(self):
        """
        Check for  changes of the configuration fles,
        and load it on change.
        """
        try:
            st = os.stat(self.opModFile)
        except IOError:
            print("failed to get information about", opModFile)
        else:
            lastModo = st[ST_MTIME]

        changed = 0
        if HvcOperationMode.lastModo != lastModo:
            changed = 1
            HvcOperationMode.lastModo = lastModo
            with open(self.opModFile) as  json_file:
                HvcOperationMode.operationMode = json.load(json_file)

        try:
            st = os.stat(self.paramFile)
        except IOError:
            print("failed to get information about", paramFile)
        else:
            lastModp = st[ST_MTIME]

        changed = 0
        if HvcOperationMode.lastModp != lastModp:
            changed = 1
            HvcOperationMode.lastModp = lastModp
            with open(self.paramFile) as  json_file:
                parTmp = json.load(json_file)
            for  p in parTmp:
                HvcOperationMode.parameters[p] = float(parTmp[p])

        
        return HvcOperationMode.operationMode,HvcOperationMode.parameters,changed
            

    
    def  write(self,operationMode):
        """
        Typically, the configuration file is edited via the web-frontend,
        use this to initially create an yaml file.
        """
        with open(self.file, 'w') as  outfile:
            json.dump(operationMode, outfile)


#persistant values:
HvcOperationMode.lastModo = 0
HvcOperationMode.lastModp = 0
HvcOperationMode.operationMode = {}
HvcOperationMode.parameters    = {}


"""
for  testing
"""
if __name__ == "__main__":
    import  time, threading
    om = HvcOperationMode()

    operationMode = {}
    operationMode['solar']= "auto"    # {on / off / auto}
    operationMode['oven'] = "off"     # {on / off / auto}
    operationMode['pump'] = "off"     # {on / off / auto}
    operationMode['vent'] = "minimal" # {minimal/normal/maximal/auto}
    operationMode['byPs'] = "shut"    # {open/shut}
    operationMode['opMod'] = "summer" # {winter/summer/vacation}
    om.write(operationMode)
    
    next_call = time.time()
    while True:
        newOm,params,changed = om.read()
        if changed:
            print(newOm)
        
        next_call = next_call+1;
        time.sleep(next_call - time.time())

python

1HvcControl.py
2HvcHCSR04ultrasonic.py
3HvcMain.py
4HvcMotorDriver.py
5HvcOneWire.py
6HvcOperationMode.py
7HvcRaw2phys.py
8HvcReadSPI.py
9HvcSendI2C.py
10HvcSetGPIO.py
11HvcTables.py
12HvcWeather.py
13makeDoc.py

php

1HV_Admin_Login.php
2HV_colorMap.php
3HV_composeH2Oplot.php
4HV_config.php
5HV_H2Olevel.php
6HV_readOperationState.php
7HV_restart.php
8HV_serviceLog.php
9HV_setParameters.php
10HV_showHouse.php
11HV_showLog.php
12HV_showWeatherForecast.php
13HV_TempCal.php
14index.php
15readFilenames.php
16readNamedData.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.