Esempio n. 1
0
def main():
    # Put variable declarations here
    variables = {'STATUS': {'type': 'string', 'bind': listen_for_events}}

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

    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
    time.sleep(1)

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

            data_timer -= POLL_INTERVAL
            time.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)
Esempio n. 2
0
def main():
    variables = {
        'PC IP': {
            'type': 'string',
            'value': False,
            'bind': ping_pc,
        },
        'PC WoL': {
            'type': 'bool',
            'value': False,
            'bind': wake_pc,
        },
        'CPU Temp': {
            'type': 'numeric',
            'bind': chip.cpu_temp
        }
    }

    # Put system data declarations here
    diagnostics = {
        'IP Address': chip.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
    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)
Esempio n. 3
0
def main():
    # Put variable declarations here
    variables = {
        'Room Temp': {
            'type': 'numeric',
            'bind': room_temp
        },
        'Outside Temp': {
            'type': 'numeric',
            'bind': outside_temp
        }
    }

    # Put system data declarations here
    diagnostics = {
        'CPU Temp': cpu_temp,
        'IP Address': ip_address,
        'Host Name': hostname,
        'Operating System': osname
    }

    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)
Esempio n. 4
0
def main():
    rgb.init()

    # Put variable declarations here
    variables = {
        'Omega LED': {
            'type': 'bool',
            'value': False,
            'bind': o2.led_control
        },
        'RGB LED - Red': {
            'type': 'numeric',
            'value': 0,
            'bind': rgb.set_R
        },
        'RGB LED - Green': {
            'type': 'numeric',
            'value': 0,
            'bind': rgb.set_G
        },
        'RGB LED - Blue': {
            'type': 'numeric',
            'value': 0,
            'bind': rgb.set_B
        }
    }

    # Put system data declarations here
    diagnostics = {
        'Host': gethostname(),
        'Operating System': " ".join(uname()),
        'Omega2 Version': 'Omega2 Plus' if 'p' in o2.version else 'Omega2',
        '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:
        device.publish_diag()
        while True:
            device.publish_data()
            sleep(DATA_SENDING_INTERVAL)

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

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

    # Put variable declarations here
    variables = {
        'Gravity': {
            'type': 'numeric',
            'bind': getGravity
        },
        'Beer Temp': {
            'type': 'numeric',
            'bind': getTemp
        }
    }

    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:
                global beacon
                beacon = tilt.getFirstTilt()
                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)
Esempio n. 6
0
def main():
    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string', 'location'
    variables = {
        'Room Temp': {
            'type': 'numeric',
            'bind': room_temp
        },
        'Outside Temp': {
            'type': 'numeric',
            'bind': outside_temp
        }
    }

    # Put system data declarations here
    diagnostics = {
        'CPU Temp': cpu_temp,
        'IP Address': ip_address,
        'Host Name': hostname,
        'Operating System': osname
    }

    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])

    finally:
        sys.exit(0)
Esempio n. 7
0
def main():
    # Put variable declarations here
    variables = {
        'XIO-P0': {
            'type': 'bool',
            'value': False,
            'bind': P0_control
        }
    }

    # Put system data declarations here
    diagnostics = {
        'IP Address': chip.ip_address,
        'Host': gethostname(),
        'Operating System': " ".join(uname()),
        'CPU Temperature': chip.cpu_temp
    }

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

    api = cloud4rpi.connect_mqtt(DEVICE_TOKEN)
    api.on_command = device.handle_mqtt_commands(api)
    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...')
        sys.exit(0)

    except Exception as e:
        error = cloud4rpi.get_error_message(e)
        cloud4rpi.log.error("ERROR! %s %s", error, sys.exc_info()[0])
        sys.exit(1)
Esempio n. 8
0
def main():
    variables = {
        'STATUS': {
            'type': 'string',
            'bind': listen_for_events
        },
        'LED On': {
            'type': 'bool',
            'value': False,
            'bind': led_control
        },
    }

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

    api = cloud4rpi.HttpApi(DEVICE_TOKEN)
    cfg = device.read_config()
    publish_config(api, cfg)

    try:
        data_timer = 0
        while True:
            if data_timer <= 0:
                res = fetch_commands(api)
                cmds = json.loads(res.content)
                for x in cmds:
                    cloud4rpi.log.info('Applying commands: %s', x)
                    device.apply_commands(x)

                data = device.read_data()
                publish_data(api, data)

                data_timer = DATA_SENDING_INTERVAL

            time.sleep(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)
Esempio n. 9
0
def main():
    o2 = omega2.Omega2()

    # Put variable declarations here
    variables = {
        'Omega LED': {
            'type': 'bool',
            'value': False,
            'bind': o2.led_control
        }
    }

    # Put system data declarations here
    diagnostics = {
        'Host': gethostname(),
        'Operating System': " ".join(uname()),
        'Omega2 version': 'Omega2 Plus' if 'p' in o2.version else 'Omega2'
    }

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

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

    try:
        diag = device.read_diag()
        api.publish_diag(diag)
        while True:
            data = device.read_data()
            api.publish_data(data)
            sleep(DATA_SENDING_INTERVAL)

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

    except Exception as e:
        error = cloud4rpi.get_error_message(e)
        cloud4rpi.log.error("ERROR! %s %s", error, sys.exc_info()[0])
        sys.exit(1)
Esempio n. 10
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)
Esempio n. 11
0
def main():

    variables = {
        'Acc_x': {
            'type': 'numeric',
            'bind': check_acc_x
        },
        'Acc_y': {
            'type': 'numeric',
            'bind': check_acc_y
        },
        'Acc_z': {
            'type': 'numeric',
            'bind': check_acc_z
        },
        'Gyro_x': {
            'type': 'numeric',
            'bind': check_gyro_x
        },
        'Gyro_y': {
            'type': 'numeric',
            'bind': check_gyro_y
        },
        'Gyro_z': {
            'type': 'numeric',
            'bind': check_gyro_z
        },
        'Mag_x': {
            'type': 'numeric',
            'bind': check_mag_x
        },
        'Mag_y': {
            'type': 'numeric',
            'bind': check_mag_y
        },
        'Mag_z': {
            'type': 'numeric',
            'bind': check_mag_z
        },
        'latitude': {
            'type': 'numeric',
            'bind': check_lat
        },
        'longitude': {
            'type': 'numeric',
            'bind': check_long
        },
        'CPU Temp': {
            'type': 'numeric',
            'bind': rpi.cpu_temp
        },
    }

    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)
Esempio n. 12
0
def main():

    variables = {
        'CPU Temp': {
            'type': 'numeric',
            'bind': cpu_temp
        },
        'CPU %': {
            'type': 'numeric',
            'bind': cpu_percent
        },
        'CPU freq': {
            'type': 'numeric',
            'bind': cpu_freq
        },
        'Memory Usage %': {
            'type': 'numeric',
            'bind': mem_percent
        },
        'Swap Usage %': {
            'type': 'numeric',
            'bind': swap_percent
        },
        'Disk Usage %': {
            'type': 'numeric',
            'bind': disk_percent
        },
        'Up Time': {
            'type': 'string',
            'bind': up_time
        },
        'Last Boot Time': {
            'type': 'string',
            'bind': boot_time
        }
    }

    # Check if OpenWeatherMap api key and location where specified
    owm_enabled = (not is_empty(OWM_API_KEY)) and (
        not is_empty(OWM_CITY_COUNTRY))

    if owm_enabled:
        print()
        print(
            f'OpenWeatherMap data enabled: Key: {OWM_API_KEY}, Location: {OWM_CITY_COUNTRY}'
        )
        print()
        variables['Weather Location'] = {
            'type': 'string',
            'bind': get_owm_location
        }
        variables['Weather Temperature Celsius'] = {
            'type': 'numeric',
            'bind': get_owm_temp
        }
        variables['Weather Humidity %'] = {
            'type': 'numeric',
            'bind': get_owm_hum
        }

    print(variables)

    diagnostics = {
        '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
        owm_timer = 0

        while True:
            if owm_enabled:
                # Check if owm data needs to be updated:
                if owm_timer <= 0:
                    get_current_owm_data()
                    owm_timer = OWM_INTERVAL_SEC

            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
            owm_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)
Esempio n. 13
0
def main():
    try:
        device = cloud4rpi.connect(CLOUD4RPI_DEVICE_TOKEN)
        status, remitdata = InstaRemRate()
        if status:
            rate_instarem = round(remitdata["destination_amount"]/1000, 2)
            fx_rate = round(remitdata["fx_rate"], 2)
        else:
            rate_instarem = 0
        # Remitly
        status, rate_remitly = RemitlyRate()
        # Xoom
        status, rate_xoom = XoomRate()
        # Ria Rate
        status, rate_ria = RiaRate()
        # Transferwise Rate
        status, rate_transferwise = TransferWise()
        datetime = time.strftime("%m/%d/%y %H:%M:%S")
        print(f"FX Rate: {fx_rate} Instarem: {rate_instarem} Remitly: {rate_remitly} Xoom: {rate_xoom} Ria: {rate_ria}, TransferWise: {rate_transferwise}  Last Updated {datetime}")
        rate_all = {
            "instarem": rate_instarem,
            "remitly": rate_remitly,
            "xoom": rate_xoom,
            "ria": rate_ria,
            "transferwise": rate_transferwise
            }
        try:
            variables = {
                "Fx Rate": {
                    "type": "numeric" if fx_rate else "string",
                    "value": fx_rate if fx_rate else "N/A"
                },
                "Instarem": {
                    "type": "numeric" if rate_instarem else "string",
                    "value": rate_instarem if rate_instarem else "N/A"
                },
                "Remitly": {
                    "type": "numeric" if rate_remitly else "string",
                    "value": rate_remitly if rate_remitly else "N/A"
                },
                "Xoom": {
                    "type": "numeric" if rate_xoom else "string",
                    "value": rate_xoom if rate_xoom else "N/A"
                },
                "Ria": {
                    "type": "numeric" if rate_ria else "string",
                    "value": rate_ria if rate_ria else "N/A"
                },
                "TransferWise": {
                    "type": "numeric" if rate_transferwise else "string",
                    "value": rate_transferwise if rate_transferwise else "N/A"
                }
            }
            device.declare(variables)
            # Uncomment Below 2 Lines in first run after Cloud4Rpi Device Creation
            # device.publish_config()
            # time.sleep(1)
            print("Uploading  Data to cloud4rpi")
            device.publish_data()
            lastrun = time.time()
        except Exception as e:
            error = cloud4rpi.get_error_message(e)
            cloud4rpi.log.exception("ERROR! %s %s", error, sys.exc_info()[0])
    except KeyboardInterrupt:
        epd2in13_V2.epdconfig.module_exit()
        exit()
Esempio n. 14
0
def main():
    try:
        lastrun = time.time() - 300
        device = cloud4rpi.connect(CLOUD4RPI_DEVICE_TOKEN)
        epd = epd2in13_V2.EPD()
        epd.init(epd.FULL_UPDATE)
        # epd.Clear(0xFF)
        image = Image.new("1", (epd.height, epd.width), 255)  # 255: clear the frame
        draw = ImageDraw.Draw(image)
        epd.displayPartBaseImage(epd.getbuffer(image))
        epd.init(epd.PART_UPDATE)
        while True:
            status, remitdata = InstaRemRate()
            if status:
                rate_instarem = round(remitdata["destination_amount"]/1000, 2)
                fx_rate = round(remitdata["fx_rate"], 2)
            else:
                rate_instarem = 0
            # Remitly
            status, rate_remitly = RemitlyRate()
            # Xoom
            status, rate_xoom = XoomRate()
            # Ria Rate
            status, rate_ria = RiaRate()
            datetime = time.strftime("%m/%d/%y %H:%M:%S")
            print(f"FX Rate: {fx_rate} Instarem: {rate_instarem} Remitly: {rate_remitly} Xoom: {rate_xoom} Ria: {rate_ria}  Last Updated {datetime}")
            draw.rectangle([(0, 0), (epd.height, 26)], fill=255)
            draw.text((0, 0), f"$1 = {fx_rate}", font=font24, fill=0)
            draw.text((140, 2), time.strftime("%m/%d %H:%M"), font=font20, fill=0)
            draw.line([(0, 30), (epd.height, 30)], fill=0, width=1)
            rate_all = {
                "instarem": rate_instarem,
                "remitly": rate_remitly,
                "xoom": rate_xoom,
                "ria": rate_ria
                }
            rate_sorted = sorted(rate_all.items(), key=lambda x: x[1], reverse=True)
            draw.rectangle([(0, 75), (epd.height, 105)], fill=255)
            ypos_icon = 10
            ypos_rate = 0
            space_icon = 65
            for name, rate in rate_sorted:
                image.paste(get_icon(name), (ypos_icon, 40))
                if rate != 0:
                    draw.text((ypos_rate, 75), str(rate), font=font20, fill=0)
                ypos_icon += space_icon
                ypos_rate += space_icon
            draw.rectangle((0, 104, 249, 121), fill=255, outline=0)
            epd.displayPartial(epd.getbuffer(image))
            currentperf = time.time()
            try:
                diagnostics = {
                "CPU Temp": rpi.cpu_temp,
                "IP Address": rpi.ip_address,
                "Host": rpi.host_name,
                "Operating System": rpi.os_name,
                "Client Version:": cloud4rpi.__version__,
                }
                variables = {
                    "Fx Rate": {
                        "type": "numeric",
                        "value": fx_rate if fx_rate != 0 else ""
                    },
                    "Instarem": {
                        "type": "numeric",
                        "value": rate_instarem if rate_instarem != 0 else ""
                    },
                    "Remitly": {
                        "type": "numeric",
                        "value": rate_remitly if rate_remitly != 0 else ""
                    },
                    "Xoom": {
                        "type": "numeric",
                        "value": rate_xoom if rate_xoom != 0 else ""
                    },
                    "Ria": {
                        "type": "numeric",
                        "value": rate_ria if rate_ria != 0 else ""
                    }
                }
                device.declare(variables)
                device.declare_diag(diagnostics)
                # device.publish_config()
                # time.sleep(1)
                device.publish_diag()
                if currentperf - lastrun > 300:
                    print("Uploading  Data to cloud4rpi")
                    device.publish_data()
                    lastrun = time.time()
            except Exception as e:
                error = cloud4rpi.get_error_message(e)
                cloud4rpi.log.exception("ERROR! %s %s", error, sys.exc_info()[0])
            for i in range(10, 255, 10):
                draw.rectangle((0, 107, i, 118), fill=0)
                epd.displayPartial(epd.getbuffer(image))
                time.sleep(2)
    except KeyboardInterrupt:
        epd2in13_V2.epdconfig.module_exit()
        exit()
Esempio n. 15
0
def main():
    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string', 'location'
    variables = {
        'LED On': {
            'type': 'bool',
            'value': False,
            'bind': relay_control
        },
    }

    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:
            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)
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)
Esempio n. 17
0
        'Host': rpi.host_name,
        'Operating Sytem': rpi.os_name
    }

    device = cloud4rpi.connect(DEVICE_TOKEN)

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

        device.publish_config()

        print('Cloud Connected!')

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

    #-----------------------------------------------------------
    date = datetime.today()

    logName = './log-' + date.strftime('%m-%d-%Y-%H-%M')

    log = open(logName, 'a+')

    log.write('\t\tSenPH\tSenEC\t\n')

    log.close()

    lcd.clear()
Esempio n. 18
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)
def main():

    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string'
    variables = {

        ##### RASP PI ######
        'CPU Temp': {
            'type': 'numeric',
            'bind': rpi.cpu_temp
        },

        ##### NETWORK ######
        'Network Latency': {
            'type': 'numeric',
            'bind': network_latency
        },
        'Localnet Latency': {
            'type': 'numeric',
            'bind': localnet_latency
        },        
        'Hosts Up': {
            'type': 'numeric',
            'bind': hosts_up
        },

		##### WEMO ######
        'WEMO Online': {
            'type': 'numeric',
            'bind': wemo_online
        },
        'UPS State': {
            'type': 'bool',
            'bind': wemo_status
        },		

        ##### UPS ######
        'UPS Line Voltage': {
            'type': 'numeric',
            'bind': line_voltage
        },
        'UPS LoadPCT': {
            'type': 'numeric',
            'bind': loadpct
        },        
        'UPS Last On Battery': {
            'type': 'string',
            'bind': xonbatt
        },        
        'UPS Last Off Battery': {
            'type': 'string',
            'bind': xoffbatt
        },
        'UPS Last Transfer': {
            'type': 'string',
            'bind': lastxfer
        },

        ##### 4G ROUTER ######
        'GSM Rssi': {
            'type': 'numeric',
            'bind': gsm_rssi
        },
        'GSM Rsrq': {
            'type': 'numeric',
            'bind': gsm_rsrq
        },
        'GSM Rsrp': {
            'type': 'numeric',
            'bind': gsm_rsrp
        },
        'GSM Band': {
            'type': 'numeric',
            'bind': gsm_band
        },
        'GSM Signal': {
            'type': 'numeric',
            'bind': gsm_signal
        },
        'GSM Mode': {
            'type': 'string',
            'bind': gsm_mode
        },
        'GSM Status': {
            'type': 'string',
            'bind': gsm_status
        },

        ####### ARLO ########
        'Arlo Base Station Status': {
            'type': 'bool',
            'bind': arlo_basestationstatus
        },

        'Arlo Camera 0 Status': {
            'type': 'bool',
            'bind': arlo_camera_0_connectionstate
        },
        'Arlo Camera 0 Battery Level': {
            'type': 'numeric',
            'bind': arlo_camera_0_batterylevel
        },
        'Arlo Camera 0 Signal Strength': {
            'type': 'numeric',
            'bind': arlo_camera_0_signalstrength
        },

        'Arlo Camera 1 Status': {
            'type': 'bool',
            'bind': arlo_camera_1_connectionstate
        },
        'Arlo Camera 1 Battery Level': {
            'type': 'numeric',
            'bind': arlo_camera_1_batterylevel
        },
        'Arlo Camera 1 Signal Strength': {
            'type': 'numeric',
            'bind': arlo_camera_1_signalstrength
        },        
    }

    diagnostics = {
        'IP Address': rpi.ip_address,
        'Host': rpi.host_name,
        'Operating System': rpi.os_name,
    }

    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:
                update_gsm()
                apcaccess()
                arlo_updatecamerasstate()
				update_wemo()
                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)
Esempio n. 20
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)
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)
def main():
    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string'
    variables = {
        'VALUE': {
            'type': 'numeric',
            'bind': get_data
            },
        'VOLTAGE': {
            'type': 'numeric',
            'bind': get_volts
            },
        'STATUS': {
            'type': 'string',
            'bind': get_status
        }
    }

    diagnostics = {
        '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).

    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)
Esempio n. 23
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)