changes
[iotcloud.git] / version2 / src / java / light_fan_embed_benchmark / Sensor.java
1 import iotcloud.*;
2 import java.util.*;
3 import java.lang.*;
4 import java.io.*;
5
6 class Sensor {
7     public static void main(String[] args) throws Exception {
8
9
10         Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 361, -1);
11         t1.rebuild();
12
13
14
15         String pingTimerKey = "sensorController";
16         IoTString ipingTimerKey = new IoTString(pingTimerKey);
17
18         String a1 = "sensor";
19         IoTString ia1 = new IoTString(a1);
20
21
22         System.out.println("Starting System");
23
24
25
26
27         while (true) {
28             try {
29
30
31
32                 Runtime runTime = Runtime.getRuntime();
33                 // Process proc = runTime.exec("/opt/vc/bin/vcgencmd measure_temp | tr -d 'temp=' |  tr -d \"'C\"");
34                 Process proc = runTime.exec("/opt/vc/bin/vcgencmd measure_temp");
35                 BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
36                 String line = null;
37                 String dat = "";
38                 while ((line = reader.readLine()) != null) {
39                     System.out.println(line);
40                     dat = line;
41                 }
42                 reader.close();
43
44
45
46                 String pingTimer = Long.toString(System.currentTimeMillis());
47                 IoTString ipingTimer = new IoTString(pingTimer);
48
49
50                 IoTString senDat = new IoTString(dat);
51
52                 t1.update();
53                 t1.startTransaction();
54                 t1.addKV(ipingTimerKey, ipingTimer);
55                 t1.addKV(ia1, senDat);
56                 t1.commitTransaction();
57
58
59
60
61
62
63
64
65
66
67
68
69                 Thread.sleep(5000);
70
71             } catch (Error e) {
72                 e.printStackTrace();
73
74                 Runtime runTime = Runtime.getRuntime();
75                 runTime.exec("gpio mode 4 out");
76
77
78                 while (true) {
79                     runTime.exec("gpio write 4 1");
80                     Thread.sleep(500);
81                     runTime.exec("gpio write 4 0");
82                     Thread.sleep(500);
83                 }
84             }
85         }
86     }
87 }