mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-11-10 01:35:50 +00:00
Integration Complete
Seems to work, debug print statements removed
This commit is contained in:
parent
1272b78f69
commit
35f98a2e99
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -153,3 +153,7 @@ cython_debug/
|
||||||
|
|
||||||
# VSCode
|
# VSCode
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
# misc
|
||||||
|
OpenHaystack.app/
|
||||||
|
extract.txt
|
BIN
OpenHaystack.zip
Normal file
BIN
OpenHaystack.zip
Normal file
Binary file not shown.
21
main.py
21
main.py
|
@ -1,5 +1,4 @@
|
||||||
import requests
|
import requests, json, subprocess, re
|
||||||
import json
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
def OpenHayStackLocation():
|
def OpenHayStackLocation():
|
||||||
|
@ -12,19 +11,31 @@ def on_connect(client, userdata, flags, rc):
|
||||||
|
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
if msg.topic == "/data":
|
if msg.topic == "/data":
|
||||||
|
loc_lat, loc_lon = None, None
|
||||||
|
try:
|
||||||
|
subprocess.run("./OpenHaystack.app/Contents/MacOS/OpenHaystack > extract.txt", capture_outout=True, shell=True, timeout=5)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
with open("extract.txt", "r") as output:
|
||||||
|
lines = output.readlines()
|
||||||
|
for line in reversed(lines):
|
||||||
|
if "FindMyLocationReport" in line:
|
||||||
|
loc_lat = re.findall("latitude: (-?[0-9]*\.[0-9]*)", line)[0]
|
||||||
|
loc_lon = re.findall("longitude: (-?[0-9]*\.[0-9]*)", line)[0]
|
||||||
|
break
|
||||||
|
subprocess.run("pkill OpenHaystack", shell=True)
|
||||||
data = json.loads(msg.payload)
|
data = json.loads(msg.payload)
|
||||||
firebase_url = "https://leg-barkr.nw.r.appspot.com/readings/save"
|
firebase_url = "https://leg-barkr.nw.r.appspot.com/readings/save"
|
||||||
firebase_headers = {
|
firebase_headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Device-ID": data["devID"]
|
"Device-ID": data["devID"]
|
||||||
}
|
}
|
||||||
loc_lat, loc_lon = OpenHayStackLocation()
|
|
||||||
firebase_data = {
|
firebase_data = {
|
||||||
"air_temp": data["air_temp"],
|
"air_temp": data["air_temp"],
|
||||||
"cumulative_steps_today": data["day_steps"],
|
"cumulative_steps_today": data["day_steps"],
|
||||||
"humidity": data["hum_perc"],
|
"humidity": data["hum_perc"],
|
||||||
"latitude": loc_lat,
|
"latitude": float(loc_lat),
|
||||||
"longitude": loc_lon,
|
"longitude": float(loc_lon),
|
||||||
"skin_temp": data['pet_temp']
|
"skin_temp": data['pet_temp']
|
||||||
}
|
}
|
||||||
r = requests.post(url = firebase_url, json = firebase_data, params = None, headers = firebase_headers) # add any other necessary values in request
|
r = requests.post(url = firebase_url, json = firebase_data, params = None, headers = firebase_headers) # add any other necessary values in request
|
||||||
|
|
Loading…
Reference in a new issue