JNP3 16/17

Dependencies:   mbed nRF24L01P

Revision:
65:7153b7640953
Parent:
36:6686483418a4
--- a/server/databaseconnector.py	Mon Jan 23 11:21:28 2017 +0100
+++ b/server/databaseconnector.py	Mon Jan 23 12:33:56 2017 +0100
@@ -35,6 +35,12 @@
     ]
 }
 
+funs = {
+    'pir1': lambda x: x,
+    'pir2': lambda x: x,
+    'distance': lambda x: 18 / (3.3 * x - 0.4),
+    'volume': lambda x: x,
+}
 
 class DatabaseConnector:
     def __init__(self, database, tables, separator=':'):
@@ -70,7 +76,7 @@
                 self.curr.execute(stmt % t)
                 entry = self.curr.fetchone()
                 if entry:
-                    json_dict['sensors'][i]['value'] = entry[0]
+                    json_dict['sensors'][i]['value'] = funs[t](entry[0])
                     json_dict['sensors'][i]['timestamp'] = entry[1]
             except Error:
                 print 'Database error on read: ' + t