Esempio n. 1
0
def main():
    """main part"""

    if this_PI not in PIs:
        Log("wrong host!")
        shutdown_application()

    udp = UDP_Sender()
    htu21df = HTU21DF()
    tempds = DS1820(AddressesDS1820[this_PI])
    tempcpu = CPU()
    if this_PI == pik_i:
        bmp180 = BMP180()

    pressure = 1013.25  # in case of no BMP180 available
    while True:
        temp_ds = tempds.read_temperature()
        temp_cpu = tempcpu.read_temperature()
        temp_htu = htu21df.read_temperature()
        humi_htu = htu21df.read_humidity()

        if this_PI == pik_i:
            pressure = bmp180.read_pressure() / 100.0

        rrd_data = "N:{:.2f}".format(temp_ds)     + \
                    ":{:.2f}".format(temp_htu)    + \
                    ":{:.2f}".format(temp_cpu)    + \
                    ":{:.2f}".format(humi_htu)    + \
                    ":{:.2f}".format(pressure)

        udp.send("{},{}".format(this_PI, rrd_data))
        time.sleep(45)
Esempio n. 2
0
def main():
    cpu = CPU()
    htu21df = HTU21DF(qvalue_temp=qv_temp_wardrobe,
                      qvalue_humi=qv_humi_wardrobe)
    udp = UDP_Sender()

    lightness.start()
    forecast.start()
    for c in controls.values():
        c.start()

    while True:
        with central_i2c_lock:
            htu21df_temperature = htu21df.read_temperature()
            htu21df_humidity = htu21df.read_humidity()

        rrd_data = "N:{:.2f}".format(htu21df_temperature)    + \
                    ":{:.2f}".format(cpu.read_temperature()) + \
                    ":{:.2f}".format(99.99)                  + \
                    ":{:.2f}".format(htu21df_humidity)       + \
                    ":{:.2f}".format(lightness.value)        + \
                    ":{}".format(controls['doors'].switchvalue_stretched())  + \
                    ":{}".format(0)                          + \
                    ":{}".format(controls['drawer'].switchvalue_stretched()) + \
                    ":{}".format(0)

        udp.send(rrd_data)
        sleep(50)
Esempio n. 3
0
    def __init__(self):
        threading.Thread.__init__(self)

        self.values = {
            'temp': "n/a",
            'tempcpu': "n/a",
            'humi': "n/a",
            'airpressure': "n/a",
            'lightness': "n/a",
            'airquality': "n/a"
        }

        self.qv_temp = SensorValue("ID_40", "TempKueche",
                                   SensorValue_Data.Types.Temp, "°C")
        self.qv_humi = SensorValue("ID_41", "HumiKueche",
                                   SensorValue_Data.Types.Humi, "% rF")
        self.qv_pressure = SensorValue("ID_42", "PressureKueche",
                                       SensorValue_Data.Types.Pressure, "hPa")
        self.qv_light = SensorValue("ID_43", "LightKueche",
                                    SensorValue_Data.Types.Light, "lux")
        self.qv_airquality = SensorValue("ID_44", "AirQualityKueche",
                                         SensorValue_Data.Types.AirQuality,
                                         "%")

        self.sq = SensorQueueClient_write("../../../configs/weatherqueue.ini")
        self.sq.register(self.qv_temp)
        self.sq.register(self.qv_humi)
        self.sq.register(self.qv_pressure)
        self.sq.register(self.qv_light)
        self.sq.register(self.qv_airquality)

        self.cpu = CPU()
        self.bme680  = BME680(i2c_addr=BME_680_BASEADDR, \
                              qv_temp=self.qv_temp, qv_humi=self.qv_humi, \
                              qv_pressure=self.qv_pressure, qv_airquality=self.qv_airquality)
        self.tsl2561 = TSL2561(qvalue=self.qv_light)

        self.rrd_template = DS_TEMP        + ":" + \
                            DS_TEMPCPU     + ":" + \
                            DS_HUMI        + ":" + \
                            DS_AIRPRESSURE + ":" + \
                            DS_LIGHTNESS   + ":" + \
                            DS_AIRQUALITY  + ":" + \
                            DS_OPEN1       + ":" + \
                            DS_OPEN2       + ":" + \
                            DS_OPEN3       + ":" + \
                            DS_OPEN4
        self._running = True
Esempio n. 4
0
class Statistics(threading.Thread):
    cpu = CPU()

    def __init__(self):
        threading.Thread.__init__(self)
        self.udp = Sender()

    def run(self):
        self._running = True
        while self._running:
            rrd_data = "N:{}".format(relais.status_stretchon().value) + \
                        ":{:.2f}".format(self.cpu.read_temperature()) + \
                        ":{}".format(0.0)                             + \
                        ":{}".format(0.0)                             + \
                        ":{}".format(0.0)                             + \
                        ":{}".format(0.0)                             + \
                        ":{}".format(0.0)
            Log(rrd_data, True)
            self.udp.send(rrd_data)

            for _ in range(500):  # interruptible sleep
                if self._running:
                    sleep(0.1)
                else:
                    break

    def stop(self):
        self._running = False
Esempio n. 5
0
def Sensor ():
    """reads data from sensor"""
    htu21df = HTU21DF()
    cpu = CPU()
    udp = UDP.Sender(CREDENTIALS)

    while True:
        temperature = htu21df.read_temperature()
        humidity    = htu21df.read_humidity()
        cpu_temp    = cpu.read_temperature()

        rrd_data = "N:" + \
                   ":".join(f"{d:.2f}" for d in [temperature, \
                                                 humidity,   \
                                                 cpu_temp])
        udp.send(rrd_data)
        time.sleep(50)
Esempio n. 6
0
def Sensor ():
    """reads data from sensor"""

    if this_PI not in PIs:
        Log("wrong host!")
        global shutdown_application
        shutdown_application()

    tempds  = DS1820(AddressesDS1820[this_PI])
    tempcpu = CPU()
    if this_PI == pik_i:
        bme680 = BME680(i2c_addr=BME_680_SECONDARYADDR)
    else:
        htu21df = HTU21DF()

    udp_rrd = UDP.Sender(CREDENTIALS_RRD)  # Server for all rrd stuff
    udp_ha = UDP.Sender(CREDENTIALS_HA)    # Display at home ("Homeautomation")

    pressure = 1013.25 # in case of no BME680 available
    airquality = 0

    while True:
        temp_ds  = tempds.read_temperature()
        temp_cpu = tempcpu.read_temperature()

        if this_PI == pik_i:
            bme680.get_sensor_data()
            temp = bme680.data.temperature
            humi = bme680.data.humidity
            pressure = bme680.data.pressure
            airquality = bme680.data.air_quality_score \
                         if bme680.data.air_quality_score != None else 0
        else:
            temp = htu21df.read_temperature()
            humi = htu21df.read_humidity()

        rrd_data = "N:{:.2f}".format(temp_ds)     + \
                    ":{:.2f}".format(temp)    + \
                    ":{:.2f}".format(temp_cpu)    + \
                    ":{:.2f}".format(humi)    + \
                    ":{:.2f}".format(pressure) + \
                    ":{:.2f}".format(airquality)

        udp_rrd.send(f"{this_PI},{rrd_data}")
        udp_ha.send(f"{this_PI},{rrd_data}")
        time.sleep(45)
Esempio n. 7
0
    def __init__(self, data, update_display):
        threading.Thread.__init__(self)

        self.cpu = CPU()
        self.ds1820_outdoor = DS1820(
            "/sys/bus/w1/devices/28-0000085607ec/w1_slave")
        self.ds1820_room = DS1820(
            "/sys/bus/w1/devices/28-000008561957/w1_slave")
        self.ds1820_water = DS1820(
            "/sys/bus/w1/devices/28-030c979462a8/w1_slave")
        self.bme280_box = BME280()
        self.sht31_airin = SHT31(addr=SHT31_BASEADDR)
        self.sht31_airout = SHT31(addr=SHT31_SECONDARYADDR)
        self.pcf8591 = PCF8591()

        self.__data = data
        self.update_display = update_display
        self._running = True
Esempio n. 8
0
def Sensor():
    """ reads data from sensor(s). """

    qv_temp = SensorValue("ID_03", "TempOutdoor", SensorValue_Data.Types.Temp,
                          "°C")
    qv_temp_garden = SensorValue("ID_12", "TempOutdoorGarden",
                                 SensorValue_Data.Types.Temp, "°C")
    qv_humi = SensorValue("ID_04", "HumiOutdoor", SensorValue_Data.Types.Humi,
                          "% rF")
    qv_lightness = SensorValue("ID_15", "LightnessOutdoor",
                               SensorValue_Data.Types.Light, "lux")

    sq.register(qv_temp)
    sq.register(qv_temp_garden)
    sq.register(qv_humi)
    sq.register(qv_lightness)

    bme280 = BME280(qvalue_pressure=None, \
                    qvalue_temp=qv_temp,  \
                    qvalue_humi=qv_humi)
    ds1820 = DS1820("/sys/bus/w1/devices/28-000006d62eb1/w1_slave",
                    qv_temp_garden)
    tsl2561 = TSL2561(qvalue=qv_lightness)
    cpu = CPU()
    udp = UDP.Sender(CREDENTIALS)

    while True:
        temp = bme280.read_temperature()
        temp_garden = ds1820.read_temperature()
        humi = bme280.read_humidity()
        pressure = bme280.read_pressure() / 100.0
        lightness = tsl2561.lux()
        cpu_temp = cpu.read_temperature()

        rrd_data = "N:" + \
                   ":".join(f"{d:.2f}" for d in [temp,        \
                                                 temp_garden, \
                                                 humi,        \
                                                 pressure,    \
                                                 lightness,   \
                                                 cpu_temp])
        udp.send(rrd_data)
        time.sleep(50)
Esempio n. 9
0
def Sensor():
    """reads data from sensor"""
    qv_temp = SensorValue("ID_01", "TempWohnzimmerIndoor",
                          SensorValue_Data.Types.Temp, "°C")
    qv_humi = SensorValue("ID_02", "HumiWohnzimmerIndoor",
                          SensorValue_Data.Types.Humi, "% rF")
    qv_pressure = SensorValue("ID_05", "Luftdruck",
                              SensorValue_Data.Types.Pressure, "hPa")
    qv_airquality = SensorValue("ID_14", "AirQualityWohnzimmer",
                                SensorValue_Data.Types.AirQuality, "%")

    sq.register(qv_temp)
    sq.register(qv_humi)
    sq.register(qv_pressure)
    sq.register(qv_airquality)

    bme680 = BME680(i2c_addr=BME_680_BASEADDR, \
                    qv_temp=qv_temp, qv_humi=qv_humi, \
                    qv_pressure=qv_pressure, qv_airquality=qv_airquality)
    cpu = CPU()
    udp = UDP.Sender(CREDENTIALS)

    while True:
        bme680.get_sensor_data()
        temp = bme680.data.temperature
        humi = bme680.data.humidity
        pressure = bme680.data.pressure
        airquality = bme680.data.air_quality_score \
                     if bme680.data.air_quality_score != None else 0
        cpu_temp = cpu.read_temperature()

        rrd_data = "N:" + \
                   ":".join(f"{d:.2f}" for d in [temp,       \
                                                 humi,       \
                                                 pressure,   \
                                                 airquality, \
                                                 cpu_temp])

        udp.send(rrd_data)
        time.sleep(50)
Esempio n. 10
0
class Sensors(threading.Thread):
    def __init__(self, data, update_display):
        threading.Thread.__init__(self)

        self.cpu = CPU()
        self.ds1820_outdoor = DS1820(
            "/sys/bus/w1/devices/28-0000085607ec/w1_slave")
        self.ds1820_room = DS1820(
            "/sys/bus/w1/devices/28-000008561957/w1_slave")
        self.ds1820_water = DS1820(
            "/sys/bus/w1/devices/28-030c979462a8/w1_slave")
        self.bme280_box = BME280()
        self.sht31_airin = SHT31(addr=SHT31_BASEADDR)
        self.sht31_airout = SHT31(addr=SHT31_SECONDARYADDR)
        self.pcf8591 = PCF8591()

        self.__data = data
        self.update_display = update_display
        self._running = True

    def run(self):
        while self._running:
            self.__data.cpu = self.cpu.read_temperature()
            self.__data.box_temp = self.bme280_box.read_temperature()
            self.__data.box_humidity = self.bme280_box.read_humidity()
            self.__data.airin_temp = self.sht31_airin.read_temperature()
            self.__data.airin_humidity = self.sht31_airin.read_humidity()
            self.__data.airout_temp = self.sht31_airout.read_temperature()
            self.__data.airout_humidity = self.sht31_airout.read_humidity()
            self.__data.engine_circulation = self.pcf8591.read(channel=0)
            self.__data.engine_countercurrent = self.pcf8591.read(channel=1)
            self.__data.outdoor_temp = self.ds1820_outdoor.read_temperature()
            self.__data.room_temp = self.ds1820_room.read_temperature()
            self.__data.water_temp = self.ds1820_water.read_temperature()
            self.__data.box_abs_humidity = abs_humidity(
                self.__data.box_humidity, self.__data.box_temp)
            self.__data.airin_abs_humidity = abs_humidity(
                self.__data.airin_humidity, self.__data.airin_temp)
            self.__data.airout_abs_humidity = abs_humidity(
                self.__data.airout_humidity, self.__data.airout_temp)
            self.__data.valid = True
            # Log("\n{}".format(self.__data))
            self.update_display()

            for _ in range(600):  # interruptible sleep
                if not self._running:
                    break
                time.sleep(0.1)

    def stop(self):
        self._running = False
Esempio n. 11
0
    def __init__(self):
        threading.Thread.__init__(self)

        self.values = {
            'temp': "n/a",
            'tempcpu': "n/a",
            'humi': "n/a",
            'airpressure': "n/a",
            'lightness': "n/a",
            'airquality': "n/a"
        }

        self.qv_temp = SensorValue("ID_40", "TempKueche",
                                   SensorValue_Data.Types.Temp, "°C")
        self.qv_humi = SensorValue("ID_41", "HumiKueche",
                                   SensorValue_Data.Types.Humi, "% rF")
        self.qv_pressure = SensorValue("ID_42", "PressureKueche",
                                       SensorValue_Data.Types.Pressure, "hPa")
        self.qv_light = SensorValue("ID_43", "LightKueche",
                                    SensorValue_Data.Types.Light, "lux")
        self.qv_airquality = SensorValue("ID_44", "AirQualityKueche",
                                         SensorValue_Data.Types.AirQuality,
                                         "%")

        self.sq = SensorQueueClient_write("../../../configs/weatherqueue.ini")
        self.sq.register(self.qv_temp)
        self.sq.register(self.qv_humi)
        self.sq.register(self.qv_pressure)
        self.sq.register(self.qv_light)
        self.sq.register(self.qv_airquality)

        self.cpu = CPU()
        self.bme680  = BME680(i2c_addr=BME_680_BASEADDR, \
                              qv_temp=self.qv_temp, qv_humi=self.qv_humi, \
                              qv_pressure=self.qv_pressure, qv_airquality=self.qv_airquality)
        self.tsl2561 = TSL2561(qvalue=self.qv_light)

        self.udp = UDP.Sender(CREDENTIALS)
Esempio n. 12
0
def main ():
    cpu     = CPU()
    htu21df = HTU21DF(qvalue_temp=qv_temp_wardrobe, qvalue_humi=qv_humi_wardrobe)
    lightness.start()
    forecast.start()
    for c in controls.values():
        c.start()

    rrd_template = DS_TEMP1     + ":" + \
                   DS_TEMPCPU   + ":" + \
                   DS_TEMP2     + ":" + \
                   DS_HUMI      + ":" + \
                   DS_LIGHTNESS + ":" + \
                   DS_OPEN1     + ":" + \
                   DS_OPEN2     + ":" + \
                   DS_OPEN3     + ":" + \
                   DS_OPEN4

    while True:
        with central_i2c_lock:
            htu21df_temperature = htu21df.read_temperature()
            htu21df_humidity    = htu21df.read_humidity()

        rrd_data = "N:{:.2f}".format(htu21df_temperature)    + \
                    ":{:.2f}".format(cpu.read_temperature()) + \
                    ":{:.2f}".format(99.99)                  + \
                    ":{:.2f}".format(htu21df_humidity)       + \
                    ":{:.2f}".format(lightness.value)        + \
                    ":{}".format(controls['doors'].switchvalue_stretched())  + \
                    ":{}".format(0)                          + \
                    ":{}".format(controls['drawer'].switchvalue_stretched()) + \
                    ":{}".format(0)
        Log(rrd_data)
        rrdtool.update(RRDFILE, "--template", rrd_template, rrd_data)

        sleep(50)
Esempio n. 13
0
class Sensors(object):
    v_ref = 8.77

    def __init__(self):
        self.cpu = CPU()
        self.bmp180 = BMP180()  # air pressure, temperature
        self.ds1820 = DS1820("/sys/bus/w1/devices/28-00000855fdfe/w1_slave")
        self.pcf8591 = PCF8591()  # ADC for measurement of supply voltage

    def read(self):
        timestamp = time.time()
        return {
            V_TemperatureBox: self.bmp180.read_temperature(),
            V_TemperatureOutside: self.ds1820.read_temperature(),
            V_Pressure: self.bmp180.read_pressure(),
            V_Voltage: self.pcf8591.read(channel=0) / 255.0 * self.v_ref,
            V_TemperatureCPU: self.cpu.read_temperature(),
            V_Timestamp: timestamp,
            V_Time: time.strftime("%X", time.localtime(timestamp))
        }
Esempio n. 14
0
class Statistics(threading.Thread):
    rrd_template = DS_SWITCH  + ":" + \
                   DS_TEMPCPU + ":" + \
                   DS_TEMP    + ":" + \
                   DS_HUMI    + ":" + \
                   DS_RES1    + ":" + \
                   DS_RES2    + ":" + \
                   DS_RES3
    cpu = CPU()

    def __init__(self):
        threading.Thread.__init__(self)
        self._running = True

    def run(self):
        while self._running:
            rrd_data = "N:{}".format(relais.status_stretchon().value) + \
                        ":{:.2f}".format(self.cpu.read_temperature()) + \
                        ":{}".format(0.0)                             + \
                        ":{}".format(0.0)                             + \
                        ":{}".format(0.0)                             + \
                        ":{}".format(0.0)                             + \
                        ":{}".format(0.0)
            Log(rrd_data, True)
            try:
                rrdtool.update(RRDFILE, "--template", self.rrd_template,
                               rrd_data)
            except rrdtool.OperationalError:
                Log("Cannot write to rrd: {0[0]} {0[1]}".format(
                    sys.exc_info()))

            for _ in range(500):  # interruptible sleep
                if self._running:
                    sleep(0.1)
                else:
                    break

    def stop(self):
        self._running = False
Esempio n. 15
0

###############################################################################
## Shutdown stuff #############################################################
def shutdown_application():
    """cleanup stuff"""
    Log("Stopping application")
    Log("Application stopped")
    sys.exit(0)


###############################################################################
## main #######################################################################
if __name__ == "__main__":
    shutdown_application = Shutdown(shutdown_func=shutdown_application)
    cpu = CPU()
    udp = UDP_Sender()

    if this_PI == seti_01:
        ds_room = DS1820(DS1820_Room)
        ds_airflow = DS1820(DS1820_Airflow)
        htu = HTU21DF()
        display = Display()

    temp_room = -99.99  # in case no DS1820 available
    temp_airflow = -99.99
    humidity = -99.99  # in case no HTU21DF available

    while True:
        cpu_usage = psutil.cpu_percent(percpu=True)
Esempio n. 16
0
 def __init__(self):
     self.cpu = CPU()
     self.bmp180 = BMP180()  # air pressure, temperature
     self.ds1820 = DS1820("/sys/bus/w1/devices/28-00000855fdfe/w1_slave")
     self.pcf8591 = PCF8591()  # ADC for measurement of supply voltage
Esempio n. 17
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
sys.path.append('../libs')

from sensors.CPU import CPU

cpu = CPU()
print(cpu.read_temperature())

### eof ###

Esempio n. 18
0
class Sensors(threading.Thread, metaclass=Singleton):
    def __init__(self):
        threading.Thread.__init__(self)

        self.values = {
            'temp': "n/a",
            'tempcpu': "n/a",
            'humi': "n/a",
            'airpressure': "n/a",
            'lightness': "n/a",
            'airquality': "n/a"
        }

        self.qv_temp = SensorValue("ID_40", "TempKueche",
                                   SensorValue_Data.Types.Temp, "°C")
        self.qv_humi = SensorValue("ID_41", "HumiKueche",
                                   SensorValue_Data.Types.Humi, "% rF")
        self.qv_pressure = SensorValue("ID_42", "PressureKueche",
                                       SensorValue_Data.Types.Pressure, "hPa")
        self.qv_light = SensorValue("ID_43", "LightKueche",
                                    SensorValue_Data.Types.Light, "lux")
        self.qv_airquality = SensorValue("ID_44", "AirQualityKueche",
                                         SensorValue_Data.Types.AirQuality,
                                         "%")

        self.sq = SensorQueueClient_write("../../../configs/weatherqueue.ini")
        self.sq.register(self.qv_temp)
        self.sq.register(self.qv_humi)
        self.sq.register(self.qv_pressure)
        self.sq.register(self.qv_light)
        self.sq.register(self.qv_airquality)

        self.cpu = CPU()
        self.bme680  = BME680(i2c_addr=BME_680_BASEADDR, \
                              qv_temp=self.qv_temp, qv_humi=self.qv_humi, \
                              qv_pressure=self.qv_pressure, qv_airquality=self.qv_airquality)
        self.tsl2561 = TSL2561(qvalue=self.qv_light)

        self.udp = UDP.Sender(CREDENTIALS)

    def run(self):
        self._running = True
        while self._running:
            self.bme680.get_sensor_data()
            self.values['temp'] = self.bme680.data.temperature
            self.values['tempcpu'] = self.cpu.read_temperature()
            self.values['humi'] = self.bme680.data.humidity
            self.values['airpressure'] = self.bme680.data.pressure
            self.values['lightness'] = self.tsl2561.lux()
            self.values['airquality']  = self.bme680.data.air_quality_score \
                                         if self.bme680.data.air_quality_score != None else 0

            rrd_data = "N:{:.2f}".format(self.values['temp'])        + \
                        ":{:.2f}".format(self.values['tempcpu'])     + \
                        ":{:.2f}".format(self.values['humi'])        + \
                        ":{:.2f}".format(self.values['airpressure']) + \
                        ":{:.2f}".format(self.values['lightness'])   + \
                        ":{:.2f}".format(self.values['airquality'])  + \
                        ":{}".format(0)                              + \
                        ":{}".format(0)                              + \
                        ":{}".format(0)                              + \
                        ":{}".format(0)
            self.udp.send(rrd_data)

            for _ in range(50):  # interruptible sleep
                if self._running:
                    time.sleep(1)
                    # brightness control needs higher frequency
                    self.values['lightness'] = self.tsl2561.lux()
                else:
                    break

    def stop(self):
        self._running = False