Changes
[iotcloud.git] / version2 / src / java / light_fan_embed_benchmark / Sensor.java
diff --git a/version2/src/java/light_fan_embed_benchmark/Sensor.java b/version2/src/java/light_fan_embed_benchmark/Sensor.java
new file mode 100644 (file)
index 0000000..fe03e1d
--- /dev/null
@@ -0,0 +1,87 @@
+import iotcloud.*;
+import java.util.*;
+import java.lang.*;
+import java.io.*;
+
+class Sensor {
+    public static void main(String[] args) throws Exception {
+
+
+        Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 361, -1);
+        t1.rebuild();
+
+
+
+        String pingTimerKey = "sensorController";
+        IoTString ipingTimerKey = new IoTString(pingTimerKey);
+
+        String a1 = "sensor";
+        IoTString ia1 = new IoTString(a1);
+
+
+        System.out.println("Starting System");
+
+
+
+
+        while (true) {
+            try {
+
+
+
+                Runtime runTime = Runtime.getRuntime();
+                // Process proc = runTime.exec("/opt/vc/bin/vcgencmd measure_temp | tr -d 'temp=' |  tr -d \"'C\"");
+                Process proc = runTime.exec("/opt/vc/bin/vcgencmd measure_temp");
+                BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+                String line = null;
+                String dat = "";
+                while ((line = reader.readLine()) != null) {
+                    System.out.println(line);
+                    dat = line;
+                }
+                reader.close();
+
+
+
+                String pingTimer = Long.toString(System.currentTimeMillis());
+                IoTString ipingTimer = new IoTString(pingTimer);
+
+
+                IoTString senDat = new IoTString(dat);
+
+                t1.update();
+                t1.startTransaction();
+                t1.addKV(ipingTimerKey, ipingTimer);
+                t1.addKV(ia1, senDat);
+                t1.commitTransaction();
+
+
+
+
+
+
+
+
+
+
+
+
+                Thread.sleep(1000);
+
+            } catch (Error e) {
+                e.printStackTrace();
+
+                Runtime runTime = Runtime.getRuntime();
+                runTime.exec("gpio mode 4 out");
+
+
+                while (true) {
+                    runTime.exec("gpio write 4 1");
+                    Thread.sleep(500);
+                    runTime.exec("gpio write 4 0");
+                    Thread.sleep(500);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file