JNP3 16/17

Dependencies:   mbed nRF24L01P

Revision:
25:4fd33808f095
Parent:
24:a929fcdb1208
Child:
26:52e8eee05dc6
diff -r a929fcdb1208 -r 4fd33808f095 frontend/kubus.js
--- a/frontend/kubus.js	Mon Jan 09 19:24:43 2017 +0100
+++ b/frontend/kubus.js	Mon Jan 09 19:52:29 2017 +0100
@@ -185,7 +185,7 @@
 
 const sensorCharts = new Charts("charts");
 
-function update() {
+function fakeUpdate() {
     sensorCharts.addSensorData([
         {
             name: "Distance at the entrance",
@@ -201,7 +201,25 @@
         }
     ]);
 
+    setTimeout(fakeUpdate, UPDATE_INTERVAL_SECONDS * 1000);
+}
+
+function update() {
+    fetch("/api/sensors")
+        .then((response) => {
+            return response.json();
+        })
+        .then((json) => {
+            sensorCharts.addSensorData(json);
+        });
+
     setTimeout(update, UPDATE_INTERVAL_SECONDS * 1000);
 }
 
-update();
\ No newline at end of file
+const query = window.location.search.substring(1);
+
+if (query === "fake") {
+    fakeUpdate();
+} else {
+    update();
+}
\ No newline at end of file