Hamburger Hamburger

Heating and Ventilation Control

HvcOneWire

Keine Erläuterungen gefunden.

class HvcOneWire_DS1820:
    def  __init__(self):
        self.sensors = {}
        self.sensors["Toven"] = "28-3c01b556c01a"
        self.sensors["Tfolu"] = "28-3c01b55605f9"
        self.sensors["Terde"] = "28-3c01b5566967"
        self.sensors["Twalu"] = "28-3c01b5566647"
        self.sensors["Thaus1"] = "28-012111fb3ff8"
        self.sensors["Thaus2"] = "28-012111ff6f31"
        self.sensors["Thaus3"] = "28-012111e8d0a5"

        for  s in self.sensors:
            HvcOneWire_DS1820.T[s] = -999
            
        return

    def  look4sensors(self):
        """
        Initially, check for  the 1-wire slaves available
        """
        file = open('/sys/devices/w1_bus_master1/w1_master_slaves')
        w1_slaves = file.readlines()
        file.close()
        sensNames = []
        for  line in w1_slaves:
            thisSensorName = line.split("\n")[0]
            sensNames.append(thisSensorName)
            
        return sensNames

    def  read(self,s="all"):
        """
        For each of the DS1820 sensors, return the temperature.
        """
        message = ""
            
        if s=="all":
            for  s in self.sensors:
                try:
                    file = open('/sys/bus/w1/devices/' + str(self.sensors[s]) + '/w1_slave')
                    filecontent = file.read()
                    file.close()
                    
                    # find and convert the temperature
                    tempVal = filecontent.split("\n")[1].split(" ")[9]
                    temperature = float(tempVal[2:]) / 1000.0
                    if temperature == -0.1:
                        temperature = -999
                    HvcOneWire_DS1820.T[s] = temperature
                except:
                    message = message + "Temperature read failed: " + str(s) +"\n"
                    HvcOneWire_DS1820.T[s] = -999
                    continue
        else:
            try:
                file = open('/sys/bus/w1/devices/' + str(self.sensors[s]) + '/w1_slave')
                filecontent = file.read()
                file.close()
                
                # find and convert the temperature
                tempVal = filecontent.split("\n")[1].split(" ")[9]
                temperature = float(tempVal[2:]) / 1000.0
                if temperature == -0.1:
                    temperature = -999
                HvcOneWire_DS1820.T[s] = temperature
            except:
                message = message + "Temperature read failed: " + str(s) +"\n"
                HvcOneWire_DS1820.T[s] = -999
                
        if self.init:
            self.init = False
            
        return HvcOneWire_DS1820.T, message

    #persistant values:
    T = {}
    init = True


if __name__ == "__main__":
    import   time, threading
    
    w1 = HvcOneWire_DS1820()
    sensNames = w1.look4sensors()
    print("Sensor identifiers found:")
    print(sensNames)
    
    # align sensor identifiers to your naming, put this to init()
    sensors = {}
    sensors["oven"] = "28-3c01b5568a59"
    print("Sensor association")
    print(w1.sensors)



    next_call = time.time()
    while True:
        #read temperatures
        T,msg = w1.read()
        print(msg)
    
        # show Temperaturs
        for  s in T:
            print(str(s) + ':\t {0:4.2f}'.format( T[s] )+" °C")
        print("---------")

        next_call = next_call+10;
        time.sleep(next_call - time.time())

python

1/HvcLightControl.py
2/HvcHCSR04ultrasonic.py
3/HvcPV.py
4/HvcMotorDriver.py
5/HvcRollerShutter.py
6/manGenMqttMap.py
7/HvcReadSPI.py
8/HvcMqtt.py
9/HvcTables.py
10/HvcMain.py
11/HvcSetGPIO.py
12/HvcWifiRelay.py
13/HvcOperationMode.py
14/HvcControl.py
15/HvcRaw2phys.py
16/HvcWeather.py
17/HvcOneWire.py
18/makeDoc.py
19/HvcFronius.py
20/EnergyManager.py
21/HvcSendI2C.py

php

1/HV_colorMap.php
2/HV_Admin_Login.php
3/HV_readOperationState.php
4/HV_setParameters.php
5/HV_config.php
6/EM_handleJSON.php
7/index.php
8/readFilenames.php
9/HV_restart.php
10/HV_moveGate.php
11/HV_showLog.php
12/HV_RollerShutter.php
13/EM_editParameter.php
14/HV_serviceLog.php
15/HV_H2Olevel.php
16/HV_TempCal.php
17/HV_Fronius.php
18/EM_plot.php
19/readNamedData.php
20/HV_composeH2Oplot.php
21/HVdoc.php
22/HV_showWeatherForecast.php
23/HV_showHouse.php

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