Adding Fidelius manual.
[iotcloud.git] / version2 / src / java / light_fan_embed_fake_benchmark / WemoController.java
1 import iotcloud.*;
2 import java.util.*;
3
4
5 class WemoController {
6     public static void main(String[] args) throws Exception {
7
8         Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
9         t1.rebuild();
10
11         String a1 = "wemo1";
12         String a2 = "wemo2";
13
14         IoTString ia1 = new IoTString(a1);
15         IoTString ia2 = new IoTString(a2);
16
17         List<IoTString> keys = new ArrayList<IoTString>();
18         keys.add(ia1);
19         keys.add(ia2);
20
21         Wemo wemo1 = new Wemo();
22         Wemo wemo2 = new Wemo();
23
24         List<Wemo> wemos = new ArrayList<Wemo>();
25         wemos.add(wemo1);
26         wemos.add(wemo2);
27
28
29         String pingTimerKey = "wemoController";
30         IoTString ipingTimerKey = new IoTString(pingTimerKey);
31
32
33         String valueA = "on";
34         IoTString iValueA = new IoTString(valueA);
35
36         System.out.println("Starting System");
37         int counter = 0;
38
39
40         while (true) {
41             try {
42                 String pingTimer = Long.toString(System.currentTimeMillis());
43                 IoTString ipingTimer = new IoTString(pingTimer);
44
45                 t1.update();
46                 t1.startTransaction();
47                 t1.addKV(ipingTimerKey, ipingTimer);
48                 t1.commitTransaction();
49
50
51                 t1.update();
52                 Thread.sleep(1000);
53
54                 for (int i = 0; i < 2; i++) {
55                     IoTString testValA1 = t1.getCommitted(keys.get(i));
56                     if ((testValA1 != null) && (testValA1.equals(iValueA) == true)) {
57                         wemos.get(i).turnOn();
58                     } else {
59                         wemos.get(i).turnOff();
60                     }
61                 }
62
63             } catch (Error e) {
64                 e.printStackTrace();
65
66                 Runtime runTime = Runtime.getRuntime();
67                 runTime.exec("gpio mode 4 out");
68
69
70                 while (true) {
71                     runTime.exec("gpio write 4 1");
72                     Thread.sleep(500);
73                     runTime.exec("gpio write 4 0");
74                     Thread.sleep(500);
75                 }
76             }
77         }
78     }
79 }