Created db-agnostic tagserver

This commit is contained in:
Patrick McDonagh
2016-05-03 12:38:35 -05:00
parent 69f32187fb
commit 93ba3b23d0
2 changed files with 79 additions and 7 deletions

View File

@@ -14,10 +14,10 @@ import random
import requests
import json
####### DEFAULTS #######
# DEFAULTS
web_address = "http://localhost:3000"
scan_rate = 30 # seconds
save_all = "test" # use True, False, or any string
scan_rate = 30 # seconds
save_all = "test" # use True, False, or any string
class Sample(Tag):
@@ -63,11 +63,12 @@ class Sample(Tag):
tag_store = {}
def main():
global web_address, scan_rate, save_all
try:
# Get tags stored in database
get_tag_request_data = {'where':'{"tag_class":5}'}
get_tag_request_data = {'where': '{"tag_class": 5}'}
get_tag_request = requests.get('{}/tag'.format(web_address), params=get_tag_request_data)
tags = json.loads(get_tag_request.text)
except Exception, e:
@@ -86,7 +87,7 @@ def main():
print("I'll just use {} seconds as the scan rate...".format(scan_rate))
try:
sa_req_data = {"where":{"parameter":"save_all"}}
sa_req_data = {"where": {"parameter": "save_all"}}
sa_req = requests.get('{}/config'.format(web_address), params=sa_req_data)
sa_try = json.loads(sa_req.text)
if len(sa_try) > 0:
@@ -100,8 +101,7 @@ def main():
for t in tags:
# name, tag, db_id, data_type, change_threshold, guarantee_sec, mapFn=None, device_type='CLX', ip_address='192.168.1.10'):
tag_store[t['name']] = Sample(t['name'], t['tag'],t['id'], t['data_type'], t['change_threshold'], t['guarantee_sec'], mapFn=t['map_function'], ip_address=t['deviceID']['address'])
tag_store[t['name']] = Sample(t['name'], t['tag'], t['id'], t['data_type'], t['change_threshold'], t['guarantee_sec'], mapFn=t['map_function'], ip_address=t['deviceID']['address'])
while True:
for tag in tag_store: