Beispiel #1
0
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
Beispiel #2
0
from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType
from dotenv import load_dotenv
import os
import signal

load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

try:
    my_thing.read()

except KeyError:
    print("nothing")

prop = my_thing.find_property_by_name("hello")
print("property id is {}".format(prop.property_id))
prop = my_thing.read_property(prop.property_id)
a = my_thing.properties[prop.property_id]
print('--')
print(a.values)
print('--')
print(prop)

# Register our Keyboard handler to exit


def keyboard_interrupt_handler(signal_num):
Beispiel #3
0
from datetime import datetime
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
from_ts = datetime.timestamp(datetime.strptime(str(START_DATE),
                                               DATE_FORMAT)) * 1000
to_ts = datetime.timestamp(datetime.strptime(str(END_DATE),
                                             DATE_FORMAT)) * 1000

print(from_ts)
print(to_ts)

load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

try:
    my_thing.read()

except KeyError:
    print("nothing")

# prop = my_thing.properties[prop1.property_id]
# print('--')
# print(prop.values[0][1:4])

#读取dcdhub上面的gps数据, 哪段时间里面的数据
prop1 = my_thing.read_property('gps-92d6', from_ts, to_ts)
prop = my_thing.properties[prop1.property_id]
print('--')
import datetime
import time
from random import random

from numpy import genfromtxt
from threading import Thread

load_dotenv()

GPS_data = [0, 0]

THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# define my thing using
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

# Start reading the serial port
# try:
#     ser = serial.Serial('/dev/ttyACM0', 115200, timeout=2)
# except:
#     try:
#         ser = serial.Serial('/dev/ttyACM1', 115200, timeout=2)
#     except:
#         ser = serial.Serial('COM12', 115200, timeout=2)


# Read the next line from the serial port
# and update the property values
def serial_to_property_values():
    # Read one line
Beispiel #5
0
# List characteristics of a device
def discover_characteristic(device):
    for uuid in device.discover_characteristics().keys():
        try:
            print("Read UUID" + str(uuid) + "   " +
                  str(device.char_read(uuid)))
        except:
            print("Something wrong with " + str(uuid))


def read_characteristic(characteristic_id):
    return my_device.char_read(characteristic_id)


# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

# We can read the details of our thing,
# i.e. retrieving its information from the hub
my_thing.read()

# If you just registered your Thing on the DCD Hub,
# it has only an id, a name and a type.
print(my_thing.to_json())

# If we have no properties, let's create a random one
if my_thing.find_property_by_name("My heart rate measurement") is None:
    # By specifying a property type, the DCD Hub will
    # automatically generate the property dimensions
    # (in this case, 3 generic dimensions)
    my_property = my_thing.create_property(
Beispiel #6
0
    if ((val & 0x8000) == 0x8000):  # treat signed 16bits
        val = -((val ^ 0xffff) + 1)
        val = float(val)
    return val


#put your hrm mac address here
hrmMacAddress = "e9:aa:88:b4:b6:bc"

#access your thing in the hub from this program
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

# We can read the details of our thing,
# i.e. retrieving its information from the hub
my_thing.read()

# If you just registered your Thing on the DCD Hub,
# it has only an id, a name and a type.
print(my_thing.to_json())

# If we have no properties, let's create a random one
if my_thing.find_property_by_name("My heart rate measurement 1") is None:
    # By specifying a property type, the DCD Hub will
    # automatically generate the property dimensions
    # (in this case, 3 generic dimensions)
    my_property = my_thing.create_property(
Beispiel #7
0

def read_characteristic(device, characteristic_id):
    """Read a characteristic"""
    return device.char_read(characteristic_id)


def keyboard_interrupt_handler(signal_num, frame):
    """Make sure we close our program properly"""
    print("Exiting...".format(signal_num))
    left_wheel.unsubscribe(GATT_CHARACTERISTIC_ORIENTATION)
    exit(0)


# Instantiate a thing with its credential, then read its properties from the DCD Hub
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)
my_thing.read()

# Start a BLE adapter
bleAdapter = pygatt.GATTToolBackend()
bleAdapter.start()

# Use the BLE adapter to connect to our device
left_wheel = bleAdapter.connect(BLUETOOTH_DEVICE_MAC,
                                address_type=ADDRESS_TYPE)

# Subscribe to the GATT service
left_wheel.subscribe(GATT_CHARACTERISTIC_ORIENTATION,
                     callback=handle_orientation_data)

# Register our Keyboard handler to exit
Beispiel #8
0
from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType
from dotenv import load_dotenv
import os
from moviepy.video.io.VideoFileClip import VideoFileClip
# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

try:
    my_thing.read()

except KeyError:
    print("nothing")

prop = my_thing.find_or_create_property("hello", PropertyType.VIDEO)
#video_prop.values = "C:\\Users\\11453\\Prototype\\1.mp4"

#print("video_prop.values is {}".format(video_prop.values))

clip = VideoFileClip("1.mp4")
duration = int(clip.duration)
prop.update_values([duration], file_name="1.mp4")
# my_thing.update_property_http(prop, "1.mp4")

print(','.join(map(str, prop.values[0])))
Beispiel #9
0
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Where to save the model to
MODEL_FILE_NAME = "model.pickle"

# Data collection time frame (in milliseconds)
START_TS = 1554388860000
END_TS = START_TS+300000

# Property ID
PROPERTY_DATA = "fsr"
PROPERTY_LABEL = "sittingdata"

# 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

def find_correlation(df, thresh=0.9):
    """
Beispiel #10
0
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Where to save the model to
MODEL_FILE_NAME = "model.pickle"

# Data collection time frame (in milliseconds)
START_TS = 1554281940000
END_TS = 1554281940000 + 5000000

# Property ID
PROPERTY_DATA = "fsryoga-ea9c"
PROPERTY_LABEL = "yoga-wheelchair-42c6"

# 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
Beispiel #11
0
# Import required library
from dotenv import load_dotenv
import os
import serial

from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType

# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

# We can read the details of our thing,
# i.e. retrieving its information from the hub
my_thing.read()
print(my_thing.to_json());

# Start reading the serial port
ser = serial.Serial(
    port=os.environ['SERIAL'],
    baudrate=9600,
    timeout=2)


# Read the next line from the serial port
# and update the property values
Beispiel #12
0
from dotenv import load_dotenv
import os

from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType

# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# 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()
my_property = my_thing.find_or_create_property("IP Address", PropertyType.TEXT)


def update_ip():
    f = os.popen('ifconfig wlan0 | grep "inet " | cut -d " " -f10')
    ip = f.read()
    my_property.update_values((ip.rstrip(),))


update_ip()
Beispiel #13
0
import os
from enum import Enum

from dcd.entities.property import PropertyType
from dcd.entities.thing import Thing
from dotenv import load_dotenv

load_dotenv()

# The thing ID and access token
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Instantiate a thing with its credential
db = Thing(thing_id=THING_ID, token=THING_TOKEN)

# We can read the details of our thing,
# i.e. retrieving its information from the hub
db.read()

# Copied from the DCD hub


class Property(Enum):
    Location = "location-512c"
    Calibration = "calibration-da32"
    Status = "status-4a4f"
    Orientation = "orientation-016a"
    HeartRate = "heart-rate-7d9c"

Beispiel #14
0
from dotenv import load_dotenv
import os

from dcd.entities.thing import Thing

# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

my_thing.read()

# Start recording
#
# property_name = 'WebCam'
# port = '/dev/video'
# segment_size = '30' size of each video segment in seconds
print('Starting video recording...')
my_thing.start_video_recording()
        # Transform the array of string values into float values (numbers)
        values = [float(x) for x in str_values]

        # get the current time in milliseconds
        current_ts_ms = int(round(time.time() * 1000))
        # Update values of data and label properties (send them to the DCD Hub)
        # With the same timestamp, so we can easily connect label and raw data later
        prop_label.update_values([class_index], current_ts_ms)
        prop_data.update_values(values, current_ts_ms)

        return True
    return False


# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

# Read the details of our Thing from the DCD Hub to get property details
my_thing.read()

# Find label and data property by name, create classes if none
prop_label = my_thing.find_or_create_property(LABEL_PROP_NAME,
                                              PropertyType.CLASS)
if prop_label.classes is None or len(prop_label.classes) == 0:
    prop_label.create_classes(CLASSES)

prop_data = my_thing.find_or_create_property(DATA_PROP_NAME,
                                             PropertyType.TWELVE_DIMENSIONS)

# Start collecting data for the first class
collect(0)
Beispiel #16
0
        # Split the string using commas as separator, we get a list of strings
        str_values = line.split(',')
        # Remove the first id
        str_values.pop(0)
        # Transform the array of string values into float values (numbers)
        values = [float(x) for x in str_values]

        # get the current time in milliseconds
        current_ts_ms = int(round(time.time() * 1000))
        # Update values of data and label properties (send them to the DCD Hub)
        # With the same timestamp, so we can easily connect label and raw data later
        prop_label.update_values([class_index], current_ts_ms)
        prop_data.update_values(values, current_ts_ms)

        return True
    return False


# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

# Read the details of our Thing from the DCD Hub to get property details
my_thing.read()

# Find label and data property by name
prop_label = my_thing.find_property_by_name(LABEL_PROP_NAME)
prop_data = my_thing.find_property_by_name(DATA_PROP_NAME)

# Start collecting data for the first class
collect(0)
Beispiel #17
0
from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType

# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Name of the property containing the labels
CLASS_PROP_NAME = "Terrain"

# Where to read the model from
MODEL_FILE_NAME = "model.pickle"

# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)
my_thing.read()

# Extract labels from the label property
terrain = my_thing.find_property_by_name(CLASS_PROP_NAME)
classes = []
for clazz in terrain.classes:
    classes.append(clazz['name'])

PREDICT_PROP_NAME = "Predicted Terrain"
PREDICT_PROP_TYPE = PropertyType.CLASS
prop_predict = my_thing.find_or_create_property(PREDICT_PROP_NAME,
                                                PREDICT_PROP_TYPE)

DATA_PROP_NAME = "IMU"
DATA_PROP_TYPE = PropertyType.THREE_DIMENSIONS
import os
import serial
import time
import pandas as pd
import numpy as np

from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType

# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)
my_thing.read()

LABEL_PROP_NAME = "Terrain"
LABEL_PROP_TYPE = PropertyType.CLASS

DATA_PROP_NAME = "IMU"
DATA_PROP_TYPE = PropertyType.THREE_DIMENSIONS

# Sitting classes
CLASSES = ["flat Terrain", "Medium Terrain", "Grassland"]

# Find label property by name, create classes if none
prop_label = my_thing.find_or_create_property(LABEL_PROP_NAME, LABEL_PROP_TYPE)
if prop_label.classes is None or len(prop_label.classes) == 0:
    prop_label.create_classes(CLASSES)
Beispiel #19
0
from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType, Property
from dotenv import load_dotenv
import os
import signal
import serial
# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

ser = serial.Serial(port=os.environ['SERIAL'], baudrate=115200, timeout=2)

try:
    my_thing.read()

except KeyError:
    print("nothing")

gps = my_thing.find_or_create_property('GPS_values',
                                       PropertyType.TWO_DIMENSIONS)

gps.update_values('101', '102')


def keyboard_interrupt_handler(signal_num):
    exit(0)

from flask_socketio import SocketIO, emit, send

from pydub import AudioSegment
from pydub.playback import play

# DCD Hub
from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType

# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Instantiate a thing with its credential that are stored in the .env file
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)
my_thing.read()
my_property = my_thing.find_or_create_property("angle_data",
                                               PropertyType.ONE_DIMENSION)

# Create thet audiosegment that will be played once assignment has been completed
complete = AudioSegment.from_wav("complete.wav")

# Import Bluetooth UUID to access Adafruit Feather from .env file
BLUETOOTH_DEVICE_MAC = os.environ['BLUETOOTH_DEVICE_IMU']

# UUID of the GATT characteristic to subscribe
#GATT_CHARACTERISTIC_ORIENTATION = "MY_GATT_ORIENTATION_SERVICE_UUID"
GATT_CHARACTERISTIC_ORIENTATION = "02118833-4455-6677-8899-aabbccddeeff"

# Many devices, e.g. Fitbit, use random addressing, this is required to connect.
Beispiel #21
0
from random import random
import time
from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType

from dotenv import load_dotenv
import os

#Thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

#Instantiate thing with its credentials
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)
#Fetch thing details
my_thing.read()
# print(my_thing.to_json())

#Create random properties
my_property = my_thing.find_or_create_property("My Random Property", PropertyType.THREE_DIMENSIONS)
#Print random property - includes name, ID and dimensions
print(my_property.to_json())

#Function that generates random values
def generate_dum_property_values(the_property):
    #Define a trio with current time and 3 random values
    values = (random(), random(), random())
    #Update values of property
    the_property.update_values(values)
Beispiel #22
0
from random import random
import time
from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType
from dotenv import load_dotenv
import os


def generate_dum_property_values(the_property):
    values = [random()]
    the_property.update_values(values)
    print(values)


load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

my_thing.read()

print(my_thing.to_json())
my_property = my_thing.find_or_create_property("PROPTEST",
                                               PropertyType.ONE_DIMENSION)
print(my_property.to_json())

while True:
    generate_dum_property_values(my_property)
    time.sleep(2)
from random import random
import time

from dotenv import load_dotenv
import os

from dcd.entities.thing import Thing
from dcd.entities.property_type import PropertyType

# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

# We can read the details of our thing,
# i.e. retrieving its information from the hub
my_thing.read()

# If you just registered your Thing on the DCD Hub,
# it has only an id, a name and a type.
print(my_thing.to_json())

# If we have no properties, let's create a random one
if my_thing.find_property_by_name("My Random Property") is None:
    # By specifying a property type, the DCD Hub will
    # automatically generate the property dimensions
    # (in this case, 3 generic dimensions)
    my_property = my_thing.create_property(
Beispiel #24
0
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)
Beispiel #25
0
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
Beispiel #26
0
from dotenv import load_dotenv
import os
import serial

from dcd.entities.thing import Thing
from dcd.entities.property import PropertyType

# The thing ID and access token
load_dotenv()
THING_ID = os.environ['THING_ID']
THING_TOKEN = os.environ['THING_TOKEN']

DATA_PROP_NAME = "frame_orientation-ab9e"

# Instantiate a thing with its credential
my_thing = Thing(thing_id=THING_ID, token=THING_TOKEN)

# We can read the details of our thing,
# i.e. retrieving its information from the hub
my_thing.read()

prop_data = my_thing.find_or_create_property(DATA_PROP_NAME, PropertyType.THREE_DIMENSIONS)


ser = serial.Serial(
    port = os.environ['SERIAL'],
    baudrate = 9600,
    timeout = 2)

# Read the next line from the serial port
# and update the property values