Updating files for the bug fix (sequence number starts from 1, not 0); adding a local...
authorrtrimana <rtrimana@uci.edu>
Mon, 14 May 2018 18:57:11 +0000 (11:57 -0700)
committerrtrimana <rtrimana@uci.edu>
Mon, 14 May 2018 18:57:11 +0000 (11:57 -0700)
version2/src/Control-2bulbs/.idea/modules.xml
version2/src/Control-2bulbs/app/src/main/java/com/example/ali/control/MainActivity.java
version2/src/Control-2bulbs/app/src/main/java/iotcloud/CloudComm.java
version2/src/Control-2bulbs/app/src/main/java/iotcloud/Table.java
version2/src/java/light_fan_embed_benchmark_2bulbs/LightsController.java
version2/src/java/light_fan_embed_benchmark_2bulbs/README.txt
version2/src/java/light_fan_embed_benchmark_2bulbs/Setup.java
version2/src/java/light_fan_embed_benchmark_2bulbs/run2.bash

index 893470c37d179627edd5bd23693db7fa8fc3a8d5..718fdadde27e0d8d2a9b83017afe947c225e1862 100644 (file)
@@ -2,7 +2,7 @@
 <project version="4">
   <component name="ProjectModuleManager">
     <modules>
-      <module fileurl="file://$PROJECT_DIR$/Control.iml" filepath="$PROJECT_DIR$/Control.iml" />
+      <module fileurl="file://$PROJECT_DIR$/Control-2bulbs.iml" filepath="$PROJECT_DIR$/Control-2bulbs.iml" />
       <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
     </modules>
   </component>
index 9a0fd49356f3abdeff7fac562dd589f3cffc6428..b24aeccee2d28885fe8cdf85353d1ced3e788421 100644 (file)
@@ -33,15 +33,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     private Handler handler = new Handler();
     private static final String CLOUD_SERVER = "http://dc-6.calit2.uci.edu/test.iotcloud/";
     private static final String PASSWORD = "reallysecret";
-    private static final int LOCAL_MACHINE_ID = 400;
-    private static final int LISTENING_PORT = -1;
+    private static final int LOCAL_MACHINE_ID = 399;
+    private static final int LISTENING_PORT = 7000;
 
     private Runnable runnable = new Runnable() {
         @Override
         public void run() {
 
-            //String strAlarm = "alarm";
-            //IoTString iotAlarm = new IoTString(strAlarm);
             String strBulb = "bulb";
             IoTString iotBulb = new IoTString(strBulb);
 
@@ -53,15 +51,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                 //t1.rebuild();
                 t1.update();
                 IoTString testValStatus = t1.getCommitted(iotBulb);
-                t1.update();
-
-                int intStatus = 0;
-                if(testValStatus != null) {
-                    String strStatus = testValStatus.toString();
-                    intStatus = Integer.parseInt(strStatus);
-                }
+                //t1.update();
+                if(testValStatus == null)
+                    return;
 
-                if (intStatus == 0) {
+                String strStatus = testValStatus.toString();
+                Log.d("RAHMADI::::", "Getting bulb status: " + strStatus);
+                if (strStatus.equals("off")) {
                     alarmStatus.setText("OFF");
                     alarmButton.setText("ON");
                     alarmStatus.setTextColor(Color.BLUE);
@@ -69,7 +65,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                     alarmOn = false;
                     Log.d("RAHMADI::::", "Set text to OFF and BLUE with alarm value: " + testValStatus);
                 }
-                else {// value 1
+                else {// value "on"
                     alarmStatus.setText("ON");
                     alarmButton.setText("OFF");
                     alarmStatus.setTextColor(Color.RED);
@@ -86,7 +82,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                 Log.e("ALI::::", sw.toString());
             }
 
-
             // Repeat every 2 seconds
             handler.postDelayed(runnable, 1000);
         }
@@ -110,7 +105,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
             Log.e("Ali::::", "Here2");
             //t1.initTable();
             t1.rebuild(); // update
-            t1.addLocalCommunication(260, "192.168.1.192", 6000);
+            t1.addLocalCommunication(400, "192.168.1.192", 6000);
             Log.e("Ali::::", "Here3");
 
         } catch (Exception e) {
@@ -128,7 +123,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         alarmButton = (Button) findViewById(R.id.alarmButton);
         alarmButton.setOnClickListener(this);
 
-        //handler.post(runnable);
+        handler.post(runnable);
     }
 
     public void onClick(View v) {
index 0ecaf772011c545bb36183a2367d29918ff59750..c9451679f06d96ec890df3d07106a98f4e1acf90 100644 (file)
@@ -753,6 +753,7 @@ class CloudComm {
 
 
                        // Open a TCP socket connection to a local device
+                       Log.e("RAHMADI::::", "host: " + host + " port: " + port);
                        Socket socket = new Socket(host, port);
                        socket.setReuseAddress(true);
                        DataOutputStream output = new DataOutputStream(socket.getOutputStream());
index b97be74fbb0c1e6d7e0ad95fd0256d3b6ad004a7..fdeaeb41c2c9b466742f7177f3063643261bf51f 100644 (file)
@@ -44,17 +44,17 @@ final public class Table {
        private int numberOfSlots = 0;  // Number of slots stored in buffer
        private int bufferResizeThreshold = 0; // Threshold on the number of live slots before a resize is needed
        private long liveSlotCount = 0; // Number of currently live slots
-       private long oldestLiveSlotSequenceNumver = 0;  // Smallest sequence number of the slot with a live entry
+       private long oldestLiveSlotSequenceNumver = 1;  // Smallest sequence number of the slot with a live entry
        private long localMachineId = 0; // Machine ID of this client device
        private long sequenceNumber = 0; // Largest sequence number a client has received
        private long localSequenceNumber = 0;
 
        // private int smallestTableStatusSeen = -1; // Smallest Table Status that was seen in the latest slots sent from the server
        // private int largestTableStatusSeen = -1; // Largest Table Status that was seen in the latest slots sent from the server
-       private long localTransactionSequenceNumber = 0; // Local sequence number counter for transactions
-       private long lastTransactionSequenceNumberSpeculatedOn = -1; // the last transaction that was speculated on
-       private long oldestTransactionSequenceNumberSpeculatedOn = -1; // the oldest transaction that was speculated on
-       private long localArbitrationSequenceNumber = 0;
+       private long localTransactionSequenceNumber = 1; // Local sequence number counter for transactions
+       private long lastTransactionSequenceNumberSpeculatedOn = 0; // the last transaction that was speculated on
+       private long oldestTransactionSequenceNumberSpeculatedOn = 0; // the oldest transaction that was speculated on
+       private long localArbitrationSequenceNumber = 1;
        private boolean hadPartialSendToServer = false;
        private boolean attemptedToSendToServer = false;
        private long expectedsize;
index 9be0b02b3601c2c698f800262a615d3c6744a5d5..0f7e59010a647fb740b36b5c80ca80cbef066fa9 100644 (file)
@@ -63,9 +63,8 @@ class LightsController {
 
         Table t1 = null;
         try {
-            t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 260, 6000);
-            //t1.addLocalCommunication(400, "192.168.1.108", 6000);
-            t1.addLocalCommunication(260, "192.168.1.192", 6000);
+            t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, 6000);
+            t1.addLocalCommunication(399, "192.168.1.192", 7000);
 
             t1.rebuild();
         } catch (Error e) {
index 8cb0d0bd6e05e77b832173e83c739781e71ac317..fe7b11c48a3a9e3f87601c6ae880c3fc7b0f53ad 100644 (file)
@@ -2,23 +2,17 @@ First build using:
     ./build.bash
 
 To run this example run:
-    # Set up the table on the cloud
+    # Set up the table on the cloud after cleaning up the cloud (delete everything on /iotcloud/test.iotcloud/)
     ./runSetup.bash
     
     # Starts the light bulb controller
     ./run1.bash   
 
-    # Starts the fan controller
-    ./run3.bash   
-
-
-    # For each switch you need to run (can launch as many of these as desired as long as input number is different)
-    ./run2.bash <a unique integer not equal to 321 or 351>
-
+    # Starts the other controller to test updates from a second local updater (trying local communication here)
+    # For some reason the android application timeouts everytime it executes server.accept() and it fails to
+    # connect to the necessary socket.
+    ./run2.bash   
 
 Dont forget to clear the cloud server directory
 
-
-
-
 https://javatutorial.net/raspberry-pi-java-tutorial
index c1d3d7b092977c300eeddbfb2a7a227949f35012..897ed62bbd71b7c49b59a821d4f0497842a3eca6 100644 (file)
@@ -5,13 +5,21 @@ class Setup {
 
     public static void main(String[] args) throws Exception {
 
-        Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 260, -1);
+        Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, -1);
         t1.initTable();
 
                String a = "bulb";
         IoTString ia = new IoTString(a);
 
-        t1.createNewKey(ia, 260);
+        t1.createNewKey(ia, 400);
+
+        String valueA = "on";
+        IoTString iValueA = new IoTString(valueA);
+        IoTString testValA1 = t1.getCommitted(ia);
+        
+        t1.startTransaction();
+        t1.addKV(ia, iValueA);
+        t1.commitTransaction();
 
         t1.update();
     }
index c12e81cb60e114cbaf2ec92fa3de891d4cf11185..1494cffad695b8b87444fe74a8b25e3846569a37 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-java -cp .:../iotcloud/bin WemoController
\ No newline at end of file
+java -cp .:../iotcloud/bin LocalControl