Skip to content

Commit

Permalink
Random id generator implemented, ping now returns the device ids as well
Browse files Browse the repository at this point in the history
Relevant to issue #12 and Fixes #13
  • Loading branch information
DanDayne committed Oct 25, 2019
1 parent 6511412 commit 9e100dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions DBmanager/DBapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def get(self):
response[node.node_id] = []
for device_type in node.devices:
device = node.devices[device_type]
response[node.node_id].append(device.device_class + '-' + device.device_type)
response[node.node_id].append([device.device_class, device.device_type, device.device_id])
return response, 200


Expand All @@ -279,7 +279,8 @@ def __init__(self):
script_location = Path(__file__).absolute().parent
with open(str(script_location / 'config.json'), 'r') as config_file:
config = load(config_file)
self.app.config['USERNAME'] = config.get('username', None) # if no auth is specified in config, no auth will be required
# if no auth is specified in config, no auth will be required
self.app.config['USERNAME'] = config.get('username', None)
self.app.config['PASSWORD'] = config.get('password', None)
self.api = Api(self.app)

Expand Down
11 changes: 9 additions & 2 deletions DataManager/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import queue
import datetime
from DBmanager import measurement

import random
import string

class Node:

Expand Down Expand Up @@ -76,16 +77,22 @@ def __init__(self, data):
"""
:param data: dictionary, check documentation.txt
"""
self.thread_name = str(data['node_id']) + data['device_type']
self.data = data
self.device_type = data['device_type']
self.device_class = data['device_class']
self.device_id = data.get('device_id', self.generate_random_id())
self.data['device_id'] = self.device_id
self.thread_name = str(data['node_id']) + data['device_type'] + data['device_id']

self.q = queue.Queue() # Queue object - all commands will be stacking here and waiting for execution
self.q_new_item = Event() # Event object - notifies that a new command has been added to queue

# start the checker of the queue
self.checker = executioner.Checker(self.q, self.q_new_item, self.data, self.thread_name)

def generate_random_id(self):
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10))

def accept_command(self, cmd):
"""
Process the command and add id to the queue of the device.
Expand Down

0 comments on commit 9e100dd

Please sign in to comment.