summaryrefslogtreecommitdiff
path: root/server.py
diff options
context:
space:
mode:
Diffstat (limited to 'server.py')
-rw-r--r--server.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/server.py b/server.py
index 5a46c17..d6aeb9a 100644
--- a/server.py
+++ b/server.py
@@ -143,6 +143,18 @@ class TrackerHTTPRequestHandler(BaseHTTPRequestHandler):
self.send_response(204)
self.end_headers()
self.wfile.write(b"")
+ elif u.path == "/sensors/airgradient/measures":
+ chip_id = post_data.pop("chip_id")
+ co2 = post_data.pop("rco2")
+ pm25 = post_data.pop("pm02")
+ temp = post_data.pop("atmp")
+ rhum = post_data.pop("rhum")
+ with conn.cursor() as cur:
+ cur.execute("INSERT INTO airgradient_measure (created, chip_id, co2, pm25, temp, rhum) VALUES (NOW(), %s, %s, %s, %s, %s)", (chip_id, co2, pm25, temp, rhum))
+ conn.commit()
+ self.send_response(204)
+ self.end_headers()
+ self.wfile.write(b"")
else:
self.send_response(404)
self.end_headers()
@@ -159,6 +171,7 @@ def setup_db():
cur.execute("CREATE TABLE IF NOT EXISTS book_datapoint (id SERIAL PRIMARY KEY, created TIMESTAMP, book_id SERIAL, pages TEXT, CONSTRAINT fk_book FOREIGN KEY(book_id) REFERENCES book(id));")
cur.execute("CREATE TABLE IF NOT EXISTS email (id SERIAL PRIMARY KEY, created TIMESTAMP, username TEXT, domain TEXT);")
cur.execute("CREATE TABLE IF NOT EXISTS form (id SERIAL PRIMARY KEY, type TEXT, prompt TEXT, prompt_id TEXT, extra JSON);")
+ cur.execute("CREATE TABLE IF NOT EXISTS airgradient_measure (id SERIAL PRIMARY KEY, created TIMESTAMP, chip_id INTEGER, co2 INTEGER, pm25 INTEGER, temp REAL, rhum INTEGER);")
conn.commit()
date_pattern = re.compile(r"(\d{4})-(\d{2})-(\d{2})")