Compare commits
4 Commits
5dc3587ccb
...
d39b4e8494
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d39b4e8494 | ||
|
|
4162cead3d | ||
|
|
4a8b2474b8 | ||
|
|
d86cd5b72e |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
config.ini
|
||||
3
config.ini
Normal file
3
config.ini
Normal file
@@ -0,0 +1,3 @@
|
||||
[Default]
|
||||
AppId=app_id
|
||||
AccessKey=ttn-account-v2.redacted
|
||||
15
main.py
15
main.py
@@ -4,9 +4,12 @@ import base64
|
||||
import message_pb2
|
||||
import sqlite3
|
||||
|
||||
app_id = "fenceles_grazing"
|
||||
access_key = "ttn-account-v2.XVvtBVcWzkeby-fe9eLtiJBLRbjQR-b358S4z70Xa-0"
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini")
|
||||
|
||||
app_id = config['Default']['AppId']
|
||||
access_key = config['Default']['AccessKey']
|
||||
|
||||
# For now use collar id of 1, should look up collar id based on collarname from db
|
||||
def store_coord(collarname, x, y):
|
||||
@@ -41,14 +44,6 @@ def on_message(client, userdata, msg):
|
||||
res.ParseFromString(bcode)
|
||||
store_coord(payload['dev_id'], res.loc.x, res.loc.y)
|
||||
|
||||
# Test protobuf here
|
||||
# code = bytearray('CgoNAAAAABUAAAAA', "utf-8")
|
||||
# print(code)
|
||||
# bcode = base64.b64decode(code)
|
||||
# res = message_pb2.CollarResponse()
|
||||
# res.ParseFromString(bcode)
|
||||
# print("Coord {x: " + str(res.loc.x) + ", y: " + str(res.loc.y) + "}")
|
||||
|
||||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
|
||||
@@ -9,6 +9,7 @@ message Coordinate {
|
||||
|
||||
message CollarResponse {
|
||||
required Coordinate loc = 1;
|
||||
required int32 oob = 2;
|
||||
}
|
||||
|
||||
message Coordinates {
|
||||
|
||||
16
tests.py
Normal file
16
tests.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import paho.mqtt.client as mqtt
|
||||
import json
|
||||
import base64
|
||||
import message_pb2
|
||||
import sqlite3
|
||||
|
||||
# Test protobuf here
|
||||
code = bytearray('CgoNAAAAABUAAAAA', "utf-8")
|
||||
print(code)
|
||||
bcode = base64.b64decode(code)
|
||||
res = message_pb2.CollarResponse()
|
||||
res.ParseFromString(bcode)
|
||||
|
||||
assert res.loc.x == 0
|
||||
assert res.loc.y == 0
|
||||
print("Coord {x: " + str(res.loc.x) + ", y: " + str(res.loc.y) + "}")
|
||||
Reference in New Issue
Block a user