mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-11-10 01:35:50 +00:00
Merge remote-tracking branch 'datapuller/main'
This commit is contained in:
commit
373972d2fc
159
.gitignore
vendored
Normal file
159
.gitignore
vendored
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
# VSCode
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# misc
|
||||||
|
OpenHaystack.app/
|
||||||
|
extract.txt
|
BIN
OpenHaystack.zip
Normal file
BIN
OpenHaystack.zip
Normal file
Binary file not shown.
8
README.md
Normal file
8
README.md
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# ELEC60013 Embedded Systems: Coursework 1
|
||||||
|
|
||||||
|
Data Fetching script that pulls data from cloud source and forwards it to our custom backend for processing and display to the user, in the app.
|
||||||
|
|
||||||
|
Possible cloud sources include:
|
||||||
|
|
||||||
|
- Airtags Database
|
||||||
|
- MQTT Broker
|
48
main.py
Normal file
48
main.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import requests, json, subprocess, re
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
def OpenHayStackLocation():
|
||||||
|
# TODO: replace with OpenHaystack script
|
||||||
|
return 0, 0
|
||||||
|
|
||||||
|
def on_connect(client, userdata, flags, rc):
|
||||||
|
print("Connected with result code "+str(rc))
|
||||||
|
client.subscribe("/data")
|
||||||
|
|
||||||
|
def on_message(client, userdata, msg):
|
||||||
|
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)
|
||||||
|
firebase_url = "https://leg-barkr.nw.r.appspot.com/readings/save"
|
||||||
|
firebase_headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Device-ID": data["devID"]
|
||||||
|
}
|
||||||
|
firebase_data = {
|
||||||
|
"air_temp": data["air_temp"],
|
||||||
|
"cumulative_steps_today": data["day_steps"],
|
||||||
|
"humidity": data["hum_perc"],
|
||||||
|
"latitude": float(loc_lat),
|
||||||
|
"longitude": float(loc_lon),
|
||||||
|
"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
|
||||||
|
print(r.status_code, r.reason, r.text)
|
||||||
|
|
||||||
|
client = mqtt.Client("DataPuller")
|
||||||
|
client.on_connect = on_connect
|
||||||
|
client.on_message = on_message
|
||||||
|
client.connect("add8.duckdns.org", 8883, 60)
|
||||||
|
client.loop_forever()
|
6
requirements.txt
Normal file
6
requirements.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
certifi==2021.10.8
|
||||||
|
charset-normalizer==2.0.12
|
||||||
|
idna==3.3
|
||||||
|
paho-mqtt==1.6.1
|
||||||
|
requests==2.27.1
|
||||||
|
urllib3==1.26.8
|
Loading…
Reference in a new issue