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
Exemple #2
0
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)

#Call function to start generating dummy values
while True:
    generate_dum_property_values(my_property)
    #2-second break
    time.sleep(2)
Exemple #3
0
# 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
prop_data = my_thing.find_or_create_property(DATA_PROP_NAME, DATA_PROP_TYPE)

# Load the classifier (model trained in the previous section)
with open(MODEL_FILE_NAME, 'rb') as file:
    neigh = pickle.load(file)

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


# Real time prediction
def serial_to_property_values():
Exemple #4
0
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)


signal.signal(signal.SIGINT, keyboard_interrupt_handler)
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)
        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)
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.
ADDRESS_TYPE = pygatt.BLEAddressType.random

# ==== ==== ===== == =====  Web server
Exemple #8
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)
# 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)
# Find data property by name
prop_data = my_thing.find_or_create_property(DATA_PROP_NAME, DATA_PROP_TYPE)


# Open a serial connection
def open_serial():
    # Start reading the serial port
    # Start reading the serial port
    try:
        ser = serial.Serial('/dev/ttyACM0', 115200, timeout=2)
    except:
        try:
            ser = serial.Serial('/dev/ttyACM1', 115200, timeout=2)
Exemple #10
0
    # Generate parameters to test our model

    matrix = confusion_matrix(labels, predicted)
    print(matrix)
    print(precision_score(labels, predicted, average="macro"))
    print(recall_score(labels, predicted, average="macro"))
    print(f1_score(labels, predicted, average="weighted"))
    print(f1_score(labels, predicted, average=None))



# 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())

fsr = my_thing.find_or_create_property(PROPERTY_DATA, PropertyType.SIX_DIMENSIONS)
fsr.read(START_TS, END_TS)

sitting = my_thing.find_or_create_property(PROPERTY_LABEL, PropertyType.ONE_DIMENSION)
sitting.read(START_TS, END_TS)

sitting.align_values_to(fsr)

classes = []
for clazz in sitting.classes:
    classes.append(clazz['name'])
    print(str(clazz['name']))

data = fsr.values
label = sitting.values
Exemple #11
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])))
Exemple #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()
Exemple #13
0
# 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
def serial_to_property_values():
    # Read one line
    line_bytes = ser.readline()
    # If the line is not empty
    if len(line_bytes) > 0:
        # Convert the bytes into string