diff --git a/main.py b/main.py index c99250e..342b1a7 100644 --- a/main.py +++ b/main.py @@ -41,14 +41,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 diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..0c89831 --- /dev/null +++ b/tests.py @@ -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) + "}")