Exemplo n.º 1
0
def make_params(nums):
    mothership_url = birdhouse_utils.make_mothership_url(args)

    tbapi = TbApi(mothership_url, thingsboard_username, thingsboard_password)

    params = []

    for num in nums:
        print(f"Retrieving details for device {num}... ", end='', flush=True)
        device_name = birdhouse_utils.make_device_name(num)
        dash_name = birdhouse_utils.make_dash_name(num)

        device = tbapi.get_device_by_name(device_name)
        dash = tbapi.get_dashboard_by_name(dash_name)
        dash_url = tbapi.get_public_dash_url(dash)
        tiny_url = make_tiny_url(dash_url)

        if device is None:
            print(f"Failed.\nCould not find device {num}... Aborting.")
            exit()

        token = tbapi.get_device_token(device)

        params.append((
            birdhouse_utils.get_sensor_type(num)[1],
            birdhouse_utils.make_device_number(num),
            token,
            tiny_url
        ))
        print("done.")

    return params
Exemplo n.º 2
0
def main():
    cleanup = True

    tbapi = TbApi(motherShipUrl, username, password)

    # Get a definition of our template dashboard
    template_dash = tbapi.get_dashboard_by_name(dashboard_template_name)
    dash_def = tbapi.get_dashboard_definition(tbapi.get_id(template_dash))

    # Lookup missing fields, such as zip, lat, and lon
    update_customer_data()

    if cust_lat is None or cust_lon is None:
        print("Must have valid lat/lon in order to add device!")
        exit(1)

    # Create new customer and device records on the server
    customer = tbapi.add_customer(cust_name, cust_address, cust_address2,
                                  cust_city, cust_state, cust_zip,
                                  cust_country, cust_email, cust_phone)

    server_attributes = {"latitude": cust_lat, "longitude": cust_lon}

    shared_attributes = {"LED": "Unknown", "nonce": 0}
    device = tbapi.add_device(make_device_name(cust_name), sensor_type,
                              shared_attributes, server_attributes)
    device_id = tbapi.get_id(device)

    # We need to store the device token as a server attribute so our REST services can get access to it
    device_token = tbapi.get_device_token(device_id)

    server_attributes = {"device_token": device_token}

    tbapi.set_server_attributes(device_id, server_attributes)

    # Upate the dash def. to point at the device we just created (modifies dash_def)
    update_dash_def(dash_def, cust_name, device_id)

    # Create a new dash with our definition, and assign it to the new customer
    dash = tbapi.create_dashboard_for_customer(cust_name + ' Dash', dash_def)
    tbapi.assign_dash_to_user(tbapi.get_id(dash), tbapi.get_id(customer))

    if cleanup:
        # input("Press Enter to continue...")   # Don't run from Sublime with this line enabled!!!

        print("Cleaning up!")
        tbapi.delete_dashboard(tbapi.get_id(dash))
        tbapi.delete_device(device_id)
        tbapi.delete_customer_by_id(tbapi.get_id(customer))
Exemplo n.º 3
0
def main():

    mothership_url = birdhouse_utils.make_mothership_url(args, config)
    tbapi = TbApi(mothership_url, thingsboard_username, thingsboard_password)

    for num in args["<num>"]:
        print(f"Retrieving details for device {num}... ", end='', flush=True)
        name = birdhouse_utils.make_device_name(num)
        device = tbapi.get_device_by_name(name)

        if device is None:
            print(f"Failed.\nCould not find device {num}... Aborting.")
            exit()

        token = tbapi.get_device_token(device)
        print("done.")
        print(token)
Exemplo n.º 4
0
import deq_tools                                                    # pip install deq_tools

from thingsboard_api_tools import TbApi                             # pip install git+git://github.com/eykamp/thingsboard_api_tools.git --upgrade
from config import motherShipUrl, username, password, deq_logfile   # You'll need to create this... Be sure to gitignore it!

tbapi = TbApi(motherShipUrl, username, password)

device_name = 'DEQ (SEL)'
deq_tz_name = 'US/Pacific'

logging.basicConfig(filename=deq_logfile, format='%(asctime)s %(message)s', level=logging.INFO)    # WARN, INFO, DEBUG


# Data is stored as if it were coming from one of our devices
device = tbapi.get_device_by_name(device_name)
device_token = tbapi.get_device_token(tbapi.get_id(device))


# This is the earliest timestamp we're interested in.  The first time we run this script, all data since this date will be imported. 
# Making the date unnecessarily early will make this script run very slowly.
earliest_ts = "2018/04/28T00:00"        # DEQ uses ISO datetime format: YYYY/MM/DDTHH:MM

station_id = 2              # 2 => SE Lafayette, 7 => Sauvie Island, 51 => Gresham Learning Center.  See bottom of this file more more stations.


# Mapping of DEQ keys to the ones we'll use for the same data
key_mapping = {
    "PM2.5 Est": "pm25",
    "Ambient Temperature": "temperature",
    "Barometric Pressure": "pressure"
}