def setup(): load_dotenv() global THING_ID, THING_TOKEN, BLUETOOTH_DEVICE_MAC, ADDRESS_TYPE, GATT_CHARACTERISTIC_ORIENTATION, bleAdapter global my_thing, my_property, csvName, dataPath global start_time, dcd_start_time global ad, distance, fbm, collecting collecting = True ADDRESS_TYPE = pygatt.BLEAddressType.random THING_ID = os.environ['THING_ID'] THING_TOKEN = os.environ['THING_TOKEN'] csvName = 'defaultdata.csv' dataPath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "defaultdata.csv") #bluetooth max & UUID of gatt service BLUETOOTH_DEVICE_MAC = "F4:36:23:1E:9E:54" GATT_CHARACTERISTIC_ORIENTATION = "02118833-4455-6677-8899-AABBCCDDEEFF" bleAdapter = pygatt.GATTToolBackend() bleAdapter.start() my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN) my_thing.read() my_property = my_thing.find_or_create_property( "Wheelchair Speed", PropertyType.THREE_DIMENSIONS) start_time = time.time() dcd_start_time = datetime.now() ad = analysedata distance = 0 fbm = feedbackmanager
MODEL_FILE_NAME = "model.pickle" # Data collection time frame (in milliseconds) START_TS = 1554468600000 END_TS = 1554468600000 + 780000 # Exact time in local time start time 2019/04/03 12:20:07.540 end time 2019/04/03 12:31:01.302 # START_TS = 1554294007540 # END_TS = 1554294661302 # Property ID PROPERTY_DATA = "discoPressure" PROPERTY_LABEL = "discoPostures" # Instantiate a thing with its credential my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN) # We can fetch the details of our thing my_thing.read() print(my_thing.to_json()) def unix_time_millis(dt): epoch = datetime.utcfromtimestamp(0) return math.floor((dt - epoch).total_seconds() * 1000.0) def list_to_df(dataSet): dfObj = pd.DataFrame(dataSet) return dfObj
from dotenv import load_dotenv import os from dcd.entities.thing import Thing from time import sleep # The thing ID and access token load_dotenv() THING_ID = os.environ['THING_ID'] # Instantiate a thing with its credential my_thing = Thing(thing_id=THING_ID, private_key_path="/etc/ssl/certs/" + THING_ID + ".private.pem") # Find or create a property to store processor usage my_property_cpu = my_thing.find_or_create_property("Processor Usage", "CPU") def update_cpu(): f = os.popen('top -bn1 | grep "Cpu" | cut -c 10-13') cpu = f.read() my_property_cpu.update_values((cpu.rstrip(), )) while True: update_cpu() # sleep every 60 seconds time.sleep(60)