コード例 #1
0
def main():
    # load w1 modules
    ds18b20.init_w1()

    # detect DS18B20 temperature sensors
    ds_sensors = ds18b20.DS18b20.find_all()

    # Put variable declarations here
    variables = {
        'Room Temp': {
            'type': 'numeric',
            'bind': ds_sensors[0]
        },
        # 'Outside Temp': {
        #     'type': 'numeric',
        #     'bind': ds_sensors[1]
        # },
        'CPU Temp': {
            'type': 'numeric',
            'bind': rpi.cpu_temp
        }
    }

    diagnostics = {
        'IP Address': rpi.ip_address,
        'Host': gethostname(),
        'Operating System': " ".join(uname())
    }

    device = cloud4rpi.Device()
    device.declare(variables)
    device.declare_diag(diagnostics)

    api = cloud4rpi.connect_mqtt(DEVICE_TOKEN)
    cfg = device.read_config()
    api.publish_config(cfg)

    # adds a 1 second delay to ensure device variables are created
    sleep(1)

    try:
        diag_timer = 0
        data_timer = 0
        while True:
            if data_timer <= 0:
                data = device.read_data()
                api.publish_data(data)
                data_timer = DATA_SENDING_INTERVAL

            if diag_timer <= 0:
                diag = device.read_diag()
                api.publish_diag(diag)
                diag_timer = DIAG_SENDING_INTERVAL

            diag_timer -= POLL_INTERVAL
            data_timer -= POLL_INTERVAL
            sleep(POLL_INTERVAL)

    except KeyboardInterrupt:
        cloud4rpi.log.info('Keyboard interrupt received. Stopping...')

    except Exception as e:
        error = cloud4rpi.get_error_message(e)
        cloud4rpi.log.error("ERROR! %s %s", error, sys.exc_info()[0])

    finally:
        sys.exit(0)
コード例 #2
0
def main():
    # Load w1 modules
    ds18b20.init_w1()

    # Detect ds18b20 temperature sensors
    ds_sensors = ds18b20.DS18b20.find_all()

    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string', 'location'
    variables = {
        'Room Temp': {
            'type': 'numeric',
            'bind': ds_sensors[0] if ds_sensors else None
        },
        # 'Outside Temp': {
        #     'type': 'numeric',
        #     'bind': ds_sensors[1] if len(ds_sensors) > 1 else None
        # },
        'LED On': {
            'type': 'bool',
            'value': False,
            'bind': led_control
        },
        'CPU Temp': {
            'type': 'numeric',
            'bind': rpi.cpu_temp
        },
        'STATUS': {
            'type': 'string',
            'bind': listen_for_events
        },
        'Eiffel Tower': {
            'type': 'location',
            'bind': get_location
        }
    }

    diagnostics = {
        'CPU Temp': rpi.cpu_temp,
        'IP Address': rpi.ip_address,
        'Host': rpi.host_name,
        'Operating System': rpi.os_name
    }
    device = cloud4rpi.connect(DEVICE_TOKEN)

    # Use the following 'device' declaration
    # to enable the MQTT traffic encryption (TLS).
    #
    # tls = {
    #     'ca_certs': '/etc/ssl/certs/ca-certificates.crt'
    # }
    # device = cloud4rpi.connect(DEVICE_TOKEN, tls_config=tls)

    try:
        device.declare(variables)
        device.declare_diag(diagnostics)

        device.publish_config()

        # Adds a 1 second delay to ensure device variables are created
        sleep(1)

        data_timer = 0
        diag_timer = 0

        while True:
            if data_timer <= 0:
                device.publish_data()
                data_timer = DATA_SENDING_INTERVAL

            if diag_timer <= 0:
                device.publish_diag()
                diag_timer = DIAG_SENDING_INTERVAL

            sleep(POLL_INTERVAL)
            diag_timer -= POLL_INTERVAL
            data_timer -= POLL_INTERVAL

    except KeyboardInterrupt:
        cloud4rpi.log.info('Keyboard interrupt received. Stopping...')

    except Exception as e:
        error = cloud4rpi.get_error_message(e)
        cloud4rpi.log.exception("ERROR! %s %s", error, sys.exc_info()[0])

    finally:
        sys.exit(0)
コード例 #3
0
def main():
    # initialize lcd
    # drivelcd.lcd_init()

    # Load w1 modules
    ds18b20.init_w1()

    # Detect ds18b20 temperature sensors
    ds_sensors = ds18b20.DS18b20.find_all()

    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string'
    variables = {
        'Temp1': {
            'type': 'numeric',
            'bind': ds_sensors[0] if ds_sensors else None
        },
        'Temp2': {
            'type': 'numeric',
            'bind': ds_sensors[1] if len(ds_sensors) > 1 else None
        },
        'Temp3': {
            'type': 'numeric',
            'bind': ds_sensors[2] if len(ds_sensors) > 1 else None
        },
        'Temp4': {
            'type': 'numeric',
            'bind': ds_sensors[3] if len(ds_sensors) > 1 else None
        },
        'Temp5': {
            'type': 'numeric',
            'bind': ds_sensors[4] if len(ds_sensors) > 1 else None
        },
        'CPU Temp': {
            'type': 'numeric',
            'bind': rpi.cpu_temp
        },
        'STATUS': {
            'type': 'string',
            'bind': listen_for_events
        }
        #        'LED On': {
        #            'type': 'bool',
        #            'value': False,
        #            'bind': led_control#
        #         },
    }

    diagnostics = {
        'CPU Temp': rpi.cpu_temp,
        'IP Address': rpi.ip_address,
        'Host': rpi.host_name,
        'Operating System': rpi.os_name
    }
    device = cloud4rpi.connect(DEVICE_TOKEN)

    # Use the following 'device' declaration
    # to enable the MQTT traffic encryption (TLS).
    #
    # tls = {
    #     'ca_certs': '/etc/ssl/certs/ca-certificates.crt'
    # }
    # device = cloud4rpi.connect(DEVICE_TOKEN, tls_config=tls)

    try:
        device.declare(variables)
        device.declare_diag(diagnostics)

        device.publish_config()

        # Adds a 1 second delay to ensure device variables are created
        sleep(1)

        data_timer = 0
        diag_timer = 0

        while True:
            if data_timer <= 0:
                device.publish_data()
                data_timer = DATA_SENDING_INTERVAL

            if diag_timer <= 0:
                device.publish_diag()
                diag_timer = DIAG_SENDING_INTERVAL

            sleep(POLL_INTERVAL)
            diag_timer -= POLL_INTERVAL
            data_timer -= POLL_INTERVAL

            temp1 = variables['Temp1']
            tempuno = str(temp1.get("value"))
            temp2 = variables['Temp2']
            tempdos = str(temp2.get("value"))
            page1 = 'GlyRes:' + str(tempuno) + '\nGlyRet:' + str(tempdos)

            temp3 = variables['Temp3']
            temptre = str(temp3.get("value"))
            temp4 = variables['Temp4']
            tempcua = str(temp4.get("value"))
            page2 = 'CompTop:' + str(temptre) + '\nCompBot:' + str(tempcua)

            temp5 = variables['Temp5']
            tempcin = str(temp5.get("value"))
            cputemp = variables['CPU Temp']
            cputemp = str(cputemp.get("value"))
            page3 = 'Ambient:' + str(tempcin) + '\nCPU:' + str(cputemp)

            lcd.message(page1)
            sleep(5.0)
            lcd.clear()
            lcd.message(page2)
            sleep(3.0)
            lcd.clear()
            lcd.message(page3)
            sleep(3.0)
            lcd.clear()

    except KeyboardInterrupt:
        cloud4rpi.log.info('Keyboard interrupt received. Stopping...')

    except Exception as e:
        error = cloud4rpi.get_error_message(e)
        cloud4rpi.log.exception("ERROR! %s %s", error, sys.exc_info()[0])

    finally:
        sys.exit(0)
コード例 #4
0
def main():
    # load w1 modules
    ds18b20.init_w1()

    # Detect DS18B20 temperature sensors.
    ds_sensors = ds18b20.DS18b20.find_all()

    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string', 'location'
    variables = {
        'Room Temp': {
            'type': 'numeric' if ds_sensors else 'string',
            'bind': ds_sensors[0] if ds_sensors else sensor_not_connected
        },
        'LED On': {
            'type': 'bool',
            'value': False,
            'bind': led_control,
        },
        'CPU Temp': {
            'type': 'numeric',
            'bind': chip.cpu_temp
        },
        'STATUS': {
            'type': 'string',
            'bind': listen_for_events
        },
        'Location': {
            'type': 'location',
            'bind': get_location
        }
    }

    # Put system data declarations here
    diagnostics = {
        'CPU Temp': chip.cpu_temp,
        'IP Address': chip.ip_address,
        'Host': chip.host_name,
        'Operating System': chip.os_name,
        'Client Version:': cloud4rpi.__version__
    }

    device = cloud4rpi.connect(DEVICE_TOKEN)
    device.declare(variables)
    device.declare_diag(diagnostics)

    device.publish_config()

    # adds a 1 second delay to ensure device variables are created
    sleep(1)

    try:
        diag_timer = 0
        data_timer = 0
        while True:
            if data_timer <= 0:
                device.publish_data()
                data_timer = DATA_SENDING_INTERVAL

            if diag_timer <= 0:
                device.publish_diag()
                diag_timer = DIAG_SENDING_INTERVAL

            diag_timer -= POLL_INTERVAL
            data_timer -= POLL_INTERVAL
            sleep(POLL_INTERVAL)

    except KeyboardInterrupt:
        cloud4rpi.log.info('Keyboard interrupt received. Stopping...')

    except Exception as e:
        error = cloud4rpi.get_error_message(e)
        cloud4rpi.log.error("ERROR! %s %s", error, sys.exc_info()[0])
        sys.exit(1)

    finally:
        sys.exit(0)
コード例 #5
0
def main():
    global beer_lines
    global trigger

    ds18b20.init_w1()
    ds_sensors = ds18b20.DS18b20.find_all()

    for k, v in beer_lines.items():
        button = Button(k)
        button.when_pressed = on_pulse

    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string', 'location'
    variables = {
        "Cellar Temp": {
            "type": "numeric" if ds_sensors else "string",
            "bind": ds_sensors[0] if ds_sensors else sensor_not_connected,
        },
        "lps1": {
            "type": "numeric",
            "bind": get_val(17, "lps")
        },
        "lps2": {
            "type": "numeric",
            "bind": get_val(18, "lps")
        },
        "liters1": {
            "type": "numeric",
            "bind": get_val(17, "liters")
        },
        "liters2": {
            "type": "numeric",
            "bind": get_val(18, "liters")
        },
    }

    diagnostics = {
        "CPU Temp": rpi.cpu_temp,
        "IP Address": rpi.ip_address,
        "Host": rpi.host_name,
        "Operating System": rpi.os_name,
        "Client Version:": cloud4rpi.__version__,
    }
    device = cloud4rpi.connect(DEVICE_TOKEN)

    # Use the following 'device' declaration
    # to enable the MQTT traffic encryption (TLS).
    #
    # tls = {
    #     'ca_certs': '/etc/ssl/certs/ca-certificates.crt'
    # }
    # device = cloud4rpi.connect(DEVICE_TOKEN, tls_config=tls)

    try:
        device.declare(variables)
        device.declare_diag(diagnostics)

        device.publish_config()

        # Adds a 1 second delay to ensure device variables are created
        sleep(1)

        data_timer = 0
        diag_timer = 0
        while True:
            pouring = on_tick()
            if (data_timer <= 0) or trigger or pouring:
                print("trigger: ", trigger, "pouring: ", pouring)
                #                print("time: ", time())
                #                print("1111111   ",beer_lines)
                calc_values()
                if trigger:
                    trigger = False


#                print("2222222   ",beer_lines)
                device.publish_data()
                data_timer = DATA_SENDING_INTERVAL

            if diag_timer <= 0:
                device.publish_diag()
                diag_timer = DIAG_SENDING_INTERVAL

            sleep(POLL_INTERVAL)
            diag_timer -= POLL_INTERVAL
            data_timer -= POLL_INTERVAL

    except KeyboardInterrupt:
        cloud4rpi.log.info("Keyboard interrupt received. Stopping...")

    except Exception as e:
        error = cloud4rpi.get_error_message(e)
        cloud4rpi.log.exception("ERROR! %s %s", error, sys.exc_info()[0])
    finally:
        sys.exit(0)
コード例 #6
0
def main():
    # load w1 modules
    ds18b20.init_w1()

    # detect ds18b20 temperature sensors
    ds_sensors = ds18b20.DS18b20.find_all()

    # Put variable declarations here
    variables = {
        'Room Temp': {
            'type': 'numeric',
            'bind': ds_sensors[0] if ds_sensors else None
        },
        # 'Outside Temp': {
        #     'type': 'numeric',
        #     'bind': ds_sensors[1] if len(ds_sensors) > 1 else None
        # },
        'LED On': {
            'type': 'bool',
            'value': False,
            'bind': led_control
        },
        'CPU Temp': {
            'type': 'numeric',
            'bind': rpi.cpu_temp
        },
        'STATUS': {
            'type': 'string',
            'bind': listen_for_events
        }
    }

    diagnostics = {
        'CPU Temp': rpi.cpu_temp,
        'IP Address': rpi.ip_address,
        'Host': gethostname(),
        'Operating System': " ".join(uname())
    }

    device = cloud4rpi.connect(DEVICE_TOKEN)
    device.declare(variables)
    device.declare_diag(diagnostics)

    device.publish_config()

    # Adds a 1 second delay to ensure device variables are created
    time.sleep(1)

    try:
        data_timer = 0
        diag_timer = 0
        while True:
            if data_timer <= 0:
                device.publish_data()
                data_timer = DATA_SENDING_INTERVAL

            if diag_timer <= 0:
                device.publish_diag()
                diag_timer = DIAG_SENDING_INTERVAL

            time.sleep(POLL_INTERVAL)
            diag_timer -= POLL_INTERVAL
            data_timer -= POLL_INTERVAL

    except KeyboardInterrupt:
        cloud4rpi.log.info('Keyboard interrupt received. Stopping...')

    except Exception as e:
        error = cloud4rpi.get_error_message(e)
        cloud4rpi.log.error("ERROR! %s %s", error, sys.exc_info()[0])

    finally:
        sys.exit(0)