store stimulus information
This commit is contained in:
parent
d39b4e8494
commit
cf51b0da69
22
main.py
22
main.py
@ -12,12 +12,23 @@ app_id = config['Default']['AppId']
|
|||||||
access_key = config['Default']['AccessKey']
|
access_key = config['Default']['AccessKey']
|
||||||
|
|
||||||
# For now use collar id of 1, should look up collar id based on collarname from db
|
# For now use collar id of 1, should look up collar id based on collarname from db
|
||||||
def store_coord(collarname, x, y):
|
def store_collar_data(collarname, res):
|
||||||
print("Coord {x: " + str(x) + ", y: " + str(y) + "}")
|
print("Coord {x: " + str(res.loc.x) + ", y: " + str(res.loc.y) + "}")
|
||||||
db = sqlite3.connect('data.sqlite')
|
db = sqlite3.connect('data.sqlite')
|
||||||
entries = [(1, x, y)]
|
|
||||||
db.executemany("INSERT INTO data_point (collar_id, longitude, latitude, datetime) VALUES (?,?,?,datetime('now'))", entries)
|
entries = [(1, res.loc.x, res.loc.y)]
|
||||||
|
db.executemany(
|
||||||
|
"INSERT INTO data_point (collar_id, longitude, latitude, datetime) VALUES (?,?,?,datetime('now'))",
|
||||||
|
entries)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
if(res.oob == 1):
|
||||||
|
entries = [(1, res.loc.x, res.loc.y)]
|
||||||
|
db.executemany(
|
||||||
|
"INSERT INTO stimulus_activation (collar_id, longitude, latitude, datetime) VALUES (?,?,?,datetime('now'))",
|
||||||
|
entries)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
# The callback for when the client receives a CONNACK response from the server.
|
# The callback for when the client receives a CONNACK response from the server.
|
||||||
@ -42,7 +53,8 @@ def on_message(client, userdata, msg):
|
|||||||
bcode = base64.b64decode(code)
|
bcode = base64.b64decode(code)
|
||||||
res = message_pb2.CollarResponse()
|
res = message_pb2.CollarResponse()
|
||||||
res.ParseFromString(bcode)
|
res.ParseFromString(bcode)
|
||||||
store_coord(payload['dev_id'], res.loc.x, res.loc.y)
|
# store_collar_data(payload['dev_id'], res.loc.x, res.loc.y)
|
||||||
|
store_collar_data(payload['dev_id'], res)
|
||||||
|
|
||||||
client = mqtt.Client()
|
client = mqtt.Client()
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
|
7
tests.py
7
tests.py
@ -5,12 +5,13 @@ import message_pb2
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
# Test protobuf here
|
# Test protobuf here
|
||||||
code = bytearray('CgoNAAAAABUAAAAA', "utf-8")
|
code = bytearray('CgoNAABIQxUAAMhCEAA=', "utf-8")
|
||||||
print(code)
|
print(code)
|
||||||
bcode = base64.b64decode(code)
|
bcode = base64.b64decode(code)
|
||||||
res = message_pb2.CollarResponse()
|
res = message_pb2.CollarResponse()
|
||||||
res.ParseFromString(bcode)
|
res.ParseFromString(bcode)
|
||||||
|
|
||||||
assert res.loc.x == 0
|
assert res.loc.x == 200
|
||||||
assert res.loc.y == 0
|
assert res.loc.y == 100
|
||||||
|
assert res.oob == 0
|
||||||
print("Coord {x: " + str(res.loc.x) + ", y: " + str(res.loc.y) + "}")
|
print("Coord {x: " + str(res.loc.x) + ", y: " + str(res.loc.y) + "}")
|
||||||
|
Loading…
Reference in New Issue
Block a user