JNP3 16/17

Dependencies:   mbed nRF24L01P

Revision:
36:6686483418a4
Parent:
35:0f01042765d6
Child:
65:7153b7640953
--- a/server/databaseconnector.py	Tue Jan 17 11:50:16 2017 +0100
+++ b/server/databaseconnector.py	Tue Jan 17 12:00:38 2017 +0100
@@ -7,26 +7,30 @@
         {
             'name': 'Motion at the stairway',
             'type': 'bool',
-            'value': None
+            'value': None,
+            'timestamp': None
         },
         {
             'name': 'Motion at the entrance',
             'type': 'bool',
-            'value': None
+            'value': None,
+            'timestamp': None
         },
         {
             'name': 'Distance at the entrance',
             'type': 'number',
             'range': [0, 90],
             'unit': 'cm',
-            'value': None
+            'value': None,
+            'timestamp': None
         },
         {
             'name': 'Volume inside',
             'type': 'number',
             'range': [-30, 30],
             'unit': 'dB',
-            'value': None
+            'value': None,
+            'timestamp': None
         }
     ]
 }
@@ -58,7 +62,7 @@
         return None
 
     def read(self):
-        stmt = 'SELECT value FROM %s ORDER BY id DESC LIMIT 1'
+        stmt = 'SELECT value, timestamp FROM %s ORDER BY id DESC LIMIT 1'
         json_dict = json_template
         self.mutex.acquire()
         for i, t in enumerate(self.tables):
@@ -67,6 +71,7 @@
                 entry = self.curr.fetchone()
                 if entry:
                     json_dict['sensors'][i]['value'] = entry[0]
+                    json_dict['sensors'][i]['timestamp'] = entry[1]
             except Error:
                 print 'Database error on read: ' + t
         self.mutex.release()