<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>
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);
//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);
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);
Log.e("ALI::::", sw.toString());
}
-
// Repeat every 2 seconds
handler.postDelayed(runnable, 1000);
}
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) {
alarmButton = (Button) findViewById(R.id.alarmButton);
alarmButton.setOnClickListener(this);
- //handler.post(runnable);
+ handler.post(runnable);
}
public void onClick(View v) {
// 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());
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;
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) {
./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
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();
}
#!/bin/sh
-java -cp .:../iotcloud/bin WemoController
\ No newline at end of file
+java -cp .:../iotcloud/bin LocalControl