Skip to content

Commit

Permalink
added device configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
smstuebe committed Apr 22, 2019
1 parent a9b0a27 commit 1ef6815
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# config files
config.ini

# User-specific files
*.suo
*.user
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ http://www.moserware.com/2010/03/computing-your-skill.html
https://www.microsoft.com/en-us/research/uploads/prod/2018/03/trueskill2.pdf
https://marketplace.visualstudio.com/items?itemName=MicrosoftIoT.WindowsIoTCoreProjectTemplatesforVS15


https://www.dexterindustries.com/howto/auto-run-python-programs-on-the-raspberry-pi/

# Install

Expand Down
9 changes: 9 additions & 0 deletions device/config.template.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[device]
# MUC/STR/FRA/... (airport shortcuts)
location=MUC

[backend]
# somefunctionapp.azurewebsites.net
fn-base-url=
environment-fn-key=
occupation-fn-key=
1 change: 1 addition & 0 deletions device/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
argparse==1.4.0
configparser==3.7.4
numpy==1.15.2
ptvsd==4.2.7
requests==2.21.0
Expand Down
18 changes: 11 additions & 7 deletions device/sensors/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from air import Air
from loudness import Loudness
import argparse
import configparser

parser = argparse.ArgumentParser(description="Kicker activity indicator.")
parser.add_argument('--debug', action='store_const',
Expand All @@ -23,9 +24,10 @@
ptvsd.enable_attach(address=('192.168.178.27', 1337), redirect_output=True)
ptvsd.wait_for_attach()

config = configparser.ConfigParser()
config.read("/mnt/device/config.ini") # TODO: make dynamic

# class Game:
# def __init__(self):
print("Started kckr for location: %s" % (config["device"]["location"]))

lock = threading.Lock()
occupation = Occupation(6, lock)
Expand All @@ -44,21 +46,23 @@
print("Temperature %.02f°C" % (air.temperature))
print("Humidity %.02f%%" % (air.humidity))
num += 1

if occupied != occupation.isOccupied:
occupied = occupation.isOccupied
print("Occupation changed: %s" % (occupied))
requests.post("", json={
"Location": "MUC",
url = "https://%s/api/InsertOccupation?code=%s" % (config["backend"]["fn-base-url"], config["backend"]["occupation-fn-key"])
requests.post(url, json={
"Location": config["device"]["location"],
"Occupied": occupation.isOccupied
})

sleep(1)

if num == 15 and air.hasValues():
print("sending data")
requests.post("", json={
"Location": "MUC",
url = "https://%s/api/InsertEnvironmentData?code=%s" % (config["backend"]["fn-base-url"], config["backend"]["environment-fn-key"])
requests.post(url, json={
"Location": config["device"]["location"],
"Occupied": occupation.isOccupied,
"Temperature": air.temperature,
"Humidity": air.humidity
Expand Down

0 comments on commit 1ef6815

Please sign in to comment.