Exemple #1
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)
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
Exemple #5
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.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)
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.connect(DEVICE_TOKEN)
    device.declare(variables)
    device.declare_diag(diagnostics)

    device.publish_config()

    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)
Exemple #7
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()
Exemple #8
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)
Exemple #10
0
            'bind': sysErrorSet
        },
        'String': {
            'type': 'string',
            'bind': changeString
        }
    }

    diagnostics = {
        'CPU Temp': rpi.cpu_temp,
        'IP Address': rpi.ip_address,
        '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!')

    #-----------------------------------------------------------
Exemple #11
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():

    # 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)
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)
Exemple #14
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)
Exemple #15
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)
Exemple #16
0
def main():
    variables = {
        'Distance': {
            'type': 'numeric',
        },
        'Status': {
            'type': 'string',
        },
        'PumpRelay': {
            'type': 'bool',
            'value': False
        },
        'WaterLevel': {
            'type': 'numeric',
        }
    }

    diagnostics = {
        'Pump_Enabled': is_pump_enabled,
        'IP_Address': rpi.ip_address,
        'Host': rpi.host_name,
        'CPU_Temp': rpi.cpu_temp,
        'OS': rpi.os_name,
        'Uptime': rpi.uptime_human
    }

    cloud = cloud4rpi.connect(C4R_TOKEN, C4R_HOST)
    cloud.declare(variables)
    cloud.declare_diag(diagnostics)
    cloud.publish_config()

    data_timer = 0
    diag_timer = 0
    log_timer = 0

    log_info("Setup GPIO...")
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(GPIO_PUMP, GPIO.IN)
    GPIO.add_event_detect(GPIO_PUMP, GPIO.BOTH, callback=pump_relay_handle, bouncetime=PUMP_BOUNCE_TIME) 
    toggle_pump(STOP_PUMP)

    try:
        log_debug('Start...')
        while True:
            global disable_alerts

            distance = wait_for_distance() # Read the current water depth

            if distance is None:
                log_error('Distance error!')
                if not disable_alerts:
                    notify_in_background(calc_alert(SENSOR_ERROR))
                    send(cloud, variables, distance, error_code=SENSOR_ERROR, force=True)
                    disable_alerts = True

                if is_pump_on() and prev_distance < STOP_PUMP_DISTANCE + DISTANCE_DELTA:
                    log_error('[!] Emergency stop of the pump. No signal from a distance sensor')
                    toggle_pump(STOP_PUMP)

                continue

            now = time()
            should_log = now - log_timer > DEBUG_LOG_INTERVAL
            if should_log:
                #log_debug("Distance = %.2f (cm)" % (distance))
                log_timer = now

            if distance <= STOP_PUMP_DISTANCE:  # Stop pouring
                toggle_pump(STOP_PUMP)
           
            if GPIO.event_detected(GPIO_PUMP):                
                is_pouring = is_pump_on()
                set_emergency_stop_time(now, is_pouring)
                log_debug('[!] Pump event detected:  %s' % ('On' if is_pouring else 'Off'))
                send(cloud, variables, distance, force=True)

            global pump_disabled
            if check_water_source_empty(now):
                log_error('[!] Emergency stop of the pump. Water source is empty')                
                toggle_pump(STOP_PUMP)
                pump_disabled = True
                
                notify_in_background(calc_alert(NO_WATER_ERROR))
                send(cloud, variables, distance, error_code=NO_WATER_ERROR, force=True)

            if distance > MAX_DISTANCE * 2:  # Distance is out of expected range: do not start pouring
                log_error('Distance is out of range:  %.2f' % distance)
                continue

            if distance > MAX_DISTANCE: # Start pouring
                toggle_pump(START_PUMP)
            
            if water_level_changed(prev_distance, distance):
                log_debug("Distance changed to %.2f (cm)" % (distance))
                send(cloud, variables, distance)
                
                update_distance(distance)
                set_emergency_stop_time(now, is_pump_on())
                
                pump_disabled = False # Allow to activate pump next time

            if now - data_timer > DATA_SENDING_INTERVAL:
                send(cloud, variables, distance)
                data_timer = now

            if now - diag_timer > DIAG_SENDING_INTERVAL:
                cloud.publish_diag()
                diag_timer = now
            
            disable_alerts = False
            
            sleep(POLL_INTERVAL)

    except Exception as e:
        log_error('ERROR: %s' % e)
        traceback.print_exc()

    finally:
        log_debug('Stopped!')
        GPIO.remove_event_detect(GPIO_PUMP)
        GPIO.cleanup()
        sys.exit(0)
Exemple #17
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)
Exemple #18
0
def save_sensor_values():
    device = cloud4rpi.connect(DEVICE_TOKEN)
    adapter = pygatt.GATTToolBackend()
    try:
        adapter.start()
        conn = adapter.connect(mac)

        time_info = int(time.time() * 1000000000.0)
        sensor_values = {}
        for sensor in char_uuids:
            value = conn.char_read(char_uuids[sensor])
            sensor_values[sensor] = float(value.decode("utf-8").rstrip('\00'))

        measure_all = []
        for sensor in sensor_values:
            measure = {
                "measurement": sensor,
                "time": time_info,
                "fields": {
                    "value": sensor_values[sensor]
                }
            }
            measure_all.append(measure)
        co2_value = sensor_values['co2']
        tvoc_value = sensor_values['tvoc']
        battery_value = sensor_values['battery']
        hum_value = sensor_values['humidity']
        temp_value = sensor_values['temperature']
        light_value = sensor_values['ambient-light']
        pressure_value = sensor_values['pressure']
        altitude_value = sensor_values['altitude']
        #		print(measure_all)
        variables = {
            'CO2': {
                'type': 'numeric',
                'value': co2_value
            },
            'Pollution Level': {
                'type': 'numeric',
                'value': tvoc_value
            },
            'Battery': {
                'type': 'numeric',
                'value': battery_value
            },
            'Humidity': {
                'type': 'numeric',
                'value': hum_value
            },
            'Temperature': {
                'type': 'numeric',
                'value': temp_value
            },
            'Air Pressure': {
                'type': 'numeric',
                'value': pressure_value
            },
            'Altitude': {
                'type': 'numeric',
                'value': altitude_value
            },
            'Sun': {
                'type': 'numeric',
                'value': light_value
            }
        }

        device.declare(variables)
        device.publish_config()
        time.sleep(1)
        device.publish_data()
        print(sensor_values)

    except Exception as e:
        print("Error: ", e)


#		msg = "ParkScan: [%d] %s"%(time_info, e)

    finally:
        adapter.stop()
Exemple #19
0
def main():
    # Save the initial time, we will use this to find out when it is time to take a picture or save a reading
    last_read_sensor = last_pic_time = int(time.time())

    # Send to Cloud4rpi using library
    # Put variable declarations here
    # Available types: 'bool', 'numeric', 'string'
    variables = {
        "Room Temp": {
            "type": "numeric",
            "bind": readTemperature
        },
        'Humidity': {
            "type": "numeric",
            "bind": readHumidity
        },
        "InfraRed Light": {
            "type": "numeric",
            "bind": readIR
        },
        "Visible Light": {
            "type": "numeric",
            "bind": readVisible
        },
        "UV Light": {
            "type": "numeric",
            "bind": readUV
        },
        "Soil Moisture1": {
            "type": "numeric",
            "bind": readMoisture1
        },
        "Soil Moisture2": {
            "type": "numeric",
            "bind": readMoisture2
        },
        "Full Spectrum Light": {
            "type": "numeric",
            "bind": readFullLight
        },
        "Ifra-Red Light": {
            "type": "numeric",
            "bind": readIRLight
        }
    }

    # Send diagnostic data to Cloud4RPI
    diagnostics = {
        'CPU Temp': rpi.cpu_temp,
        'IP Address': rpi.ip_address,
        'Host': rpi.host_name,
        'Operating System': rpi.os_name
    }

    # Cloud4RPI functions
    device = cloud4rpi.connect(DEVICE_TOKEN)
    device.declare(variables)
    device.declare_diag(diagnostics)
    device.publish_config()

    while True:
        curr_time_sec = int(time.time())

        # If it is time to take the sensor reading - based on time set at the top
        if curr_time_sec - last_read_sensor > time_for_sensor:

            device.publish_data()

            # Update the last read time
            last_read_sensor = curr_time_sec

        # If it is time to take the picture - based on time set at the top
        if curr_time_sec - last_pic_time > time_for_picture:
            take_picture()
            last_pic_time = curr_time_sec
            device.publish_diag()

        # Slow down the loop
        time.sleep(time_to_sleep)
Exemple #20
0
def main():
    #Configure the Rack information.
    rack = 'rackA'
    device = cloud4rpi.connect(DEVICE_TOKEN)

    #The gateway node diagnostics information.
    diagnostics = {
        'CPU Temp': 33,
        'IP Address': "10.0.0.0",
        'Host': rack,
        'Operating System': "Linux",
        'Client Version:': cloud4rpi.__version__,
    }
    device.declare_diag(diagnostics)
    device.publish_diag()

    #The individual node data.
    variables = {
        'id': {
            'type': 'numeric',
            'bind': get_id
        },
        'temperature': {
            'type': 'numeric',
            'bind': get_temperature
        },
        'humidity': {
            'type': 'numeric',
            'bind': get_humidity
        },
        'pathogenPresence': {
            'type': 'numeric',
            'bind': get_pathogenpresence
        },
        'Location': {
            'type': 'location',
            'bind': get_location
        }
    }
    device.declare(variables)
    device.publish_config()
    sleep(1)
    # sleep for a second to make sure the configuration data is published.
    #Pick the jsons recorded by the sensor.
    fileArr = os.listdir(rack + '/')
    for file in fileArr:
        if re.match('NE', file):
            #Load json file to a json dictionary
            fileContent = open(rack + '/' + file, 'r')
            fileJson = json.loads(fileContent.read())
            fileContent.close()
            os.rename(r'' + rack + '/' + file,
                      r'' + rack + '/IE' + str(fileJson["id"]) + '.json')
            headers = {'content-type': 'application/json'}
            request = requests.post(url + rack + '/' + str(fileJson["id"]) +
                                    '?qos=1',
                                    data=json.dumps(fileJson),
                                    headers=headers,
                                    cert=('bf0d06941b-certificate.pem.crt',
                                          'bf0d06941b-private.pem.key'),
                                    verify='AmazonRootCA1.pem.txt')
            print(request.status_code)
            #os.rename(r''+rack+'/IE'+str(fileJson["id"])+'.json',r''+rack+'/CE'+str(fileJson["id"])+'.json')
            device.publish_data()
            os.rename(r'' + rack + '/IE' + str(fileJson["id"]) + '.json',
                      r'' + rack + '/CE' + str(fileJson["id"]) + '.json')
            sleep(DATA_SENDING_INTERVAL)
Exemple #21
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()
Exemple #22
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)
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)