--- /dev/null
+
+
+import java.util.Scanner;
+import iotcloud.*;
+
+class BulbSwitch {
+ public static void main(String[] args) throws Exception {
+
+
+ System.out.println(Integer.parseInt(args[0]));
+
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", Integer.parseInt(args[0]), -1);
+ t1.rebuild(); // update
+
+
+ String a = "bulb";
+ String b = "fan";
+ IoTString ib = new IoTString(b);
+ IoTString ia = new IoTString(a);
+
+ t1.createNewKey(ia, 321);
+
+
+ String valueA = "on";
+ String valueB = "off";
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+
+
+
+ System.out.println("Starting System");
+ Scanner keyboard = new Scanner(System.in);
+
+ while (true) {
+
+
+ System.out.println("Enter 0 for off, 1 for on for bulb");
+ System.out.println("Enter 3 for off, 2 for on for fan");
+ int myint = keyboard.nextInt();
+
+ if (myint == 0) {
+ t1.update();
+ t1.startTransaction();
+ t1.addKV(ia, iValueB);
+ t1.commitTransaction();
+
+ } else if (myint == 1) {
+ t1.update();
+ t1.startTransaction();
+ t1.addKV(ia, iValueA);
+ t1.commitTransaction();
+ }
+ else if (myint == 2) {
+ t1.update();
+ t1.startTransaction();
+ t1.addKV(ib, iValueA);
+ t1.commitTransaction();
+ }
+ else if (myint == 3) {
+ t1.update();
+ t1.startTransaction();
+ t1.addKV(ib, iValueB);
+ t1.commitTransaction();
+ }
+
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+
+
+
+import java.util.Scanner;
+import iotcloud.*;
+
+import java.util.Scanner;
+import iotcloud.*;
+
+import java.util.Scanner;
+import iotcloud.*;
+class Filler {
+ public static void main(String[] args) throws Exception {
+
+
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, -1);
+ t1.rebuild(); // update
+
+ String valueA = "on";
+ String valueB = "off";
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+
+
+ System.out.println("Starting System");
+ Scanner keyboard = new Scanner(System.in);
+
+ for (int i = 0; i < 10; i++) {
+
+
+ String a1 = "bulb" + (i % 100);
+ IoTString ia1 = new IoTString(a1);
+
+
+
+ t1.update();
+ t1.startTransaction();
+ t1.addKV(ia1, iValueB);
+ t1.commitTransaction();
+
+
+
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+
+
+
+import java.util.Scanner;
+import iotcloud.*;
+
+import java.util.Scanner;
+import iotcloud.*;
+class Filler2 {
+ public static void main(String[] args) throws Exception {
+
+
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, -1);
+ t1.rebuild(); // update
+
+ String valueA = "on";
+ String valueB = "off";
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+
+
+ System.out.println("Starting System");
+ String a1 = "bulb1";
+ IoTString ia1 = new IoTString(a1);
+
+
+ while (true) {
+
+
+
+ // t1.update();
+ t1.startTransaction();
+ t1.addKV(ia1, iValueB);
+ t1.commitTransaction();
+
+ try {
+ Thread.sleep(500);
+ } catch (Exception e) {
+
+ }
+
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+\r
+// Java packages\r
+import java.net.Socket;\r
+import java.net.ServerSocket;\r
+import java.net.InetAddress;\r
+import java.net.UnknownHostException;\r
+\r
+/** Class IoTAddress is a wrapper class to pass\r
+ * IoTSet of any addresses from master to slave\r
+ *\r
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>\r
+ * @version 1.0\r
+ * @since 2016-04-22\r
+ */\r
+public class IoTAddress {\r
+\r
+ /**\r
+ * IoTDeviceAddress class properties\r
+ */\r
+ protected final InetAddress inetAddress;\r
+\r
+ /**\r
+ * Class constructor\r
+ *\r
+ * @param sAddress String address\r
+ */\r
+ protected IoTAddress(String sAddress) throws UnknownHostException {\r
+\r
+ inetAddress = InetAddress.getByName(sAddress);\r
+ }\r
+\r
+ /**\r
+ * getHostAddress() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getHostAddress() {\r
+\r
+ return inetAddress.getHostAddress();\r
+\r
+ }\r
+\r
+ /**\r
+ * getHostName() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getHostName() {\r
+\r
+ return inetAddress.getHostName();\r
+\r
+ }\r
+\r
+ /**\r
+ * getUrl() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getURL(String strURLComplete) {\r
+\r
+ //e.g. http:// + inetAddress.getHostAddress() + strURLComplete\r
+ // http://192.168.2.254/cgi-bin/mjpg/video.cgi?\r
+ return "http://" + inetAddress.getHostAddress() + strURLComplete;\r
+ \r
+ }\r
+\r
+ /**\r
+ * getCompleteAddress() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getCompleteAddress() {\r
+\r
+ return inetAddress.toString();\r
+\r
+ }\r
+}\r
--- /dev/null
+// Java packages\r
+import java.net.Socket;\r
+import java.net.ServerSocket;\r
+import java.net.InetAddress;\r
+import java.net.UnknownHostException;\r
+\r
+/** Class IoTDeviceAddress is a wrapper class to pass\r
+ * IoTSet of device addresses from master to slave\r
+ *\r
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>\r
+ * @version 1.0\r
+ * @since 2016-02-18\r
+ */\r
+public class IoTDeviceAddress extends IoTAddress {\r
+\r
+ /**\r
+ * IoTDeviceAddress class properties\r
+ */\r
+ private int iSrcPort;\r
+ private int iDstPort;\r
+ private final String sAddress;\r
+\r
+ // the wildcard status of this address\r
+ private final boolean isSrcPortWildCard;\r
+ private final boolean isDstPortWildCard;\r
+\r
+\r
+ /**\r
+ * Class constructor\r
+ *\r
+ * @param sAddress String address\r
+ * @param _iSrcPort Source port number\r
+ * @param _iDstPort Destination port number\r
+ * @param _isSrcPortWildCard Is this source port a wild card (=can change port number)?\r
+ * @param _isDstPortWildCard Is this destination port a wild card (=can change port number)?\r
+ */\r
+ protected IoTDeviceAddress(String _sAddress, int _iSrcPort, int _iDstPort, boolean _isSrcPortWildCard, \r
+ boolean _isDstPortWildCard) throws UnknownHostException {\r
+\r
+ super(_sAddress);\r
+ sAddress = _sAddress;\r
+ iSrcPort = _iSrcPort;\r
+ iDstPort = _iDstPort;\r
+\r
+ isSrcPortWildCard = _isSrcPortWildCard;\r
+ isDstPortWildCard = _isDstPortWildCard;\r
+ }\r
+\r
+ /**\r
+ * getSourcePortNumber() method\r
+ *\r
+ * @return int\r
+ */\r
+ public int getSourcePortNumber() {\r
+\r
+ return iSrcPort;\r
+\r
+ }\r
+\r
+ /**\r
+ * getDestinationPortNumber() method\r
+ *\r
+ * @return int\r
+ */\r
+ public int getDestinationPortNumber() {\r
+\r
+ return iDstPort;\r
+\r
+ }\r
+\r
+ /**\r
+ * setSrcPort() method\r
+ *\r
+ * @param port Port number\r
+ * @return void\r
+ */\r
+ public void setSrcPort(int port) {\r
+ if (isSrcPortWildCard) {\r
+ iSrcPort = port;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * setDstPort() method\r
+ *\r
+ * @param port Port number\r
+ * @return void\r
+ */\r
+ public void setDstPort(int port) {\r
+ if (isDstPortWildCard) {\r
+ iDstPort = port;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * getAddress() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getAddress() {\r
+ return sAddress;\r
+ }\r
+\r
+ /**\r
+ * getHostAddress() method\r
+ *\r
+ * @return String\r
+ */\r
+ public static String getLocalHostAddress() {\r
+\r
+ String strLocalHostAddress = null;\r
+ try {\r
+ strLocalHostAddress = InetAddress.getLocalHost().getHostAddress();\r
+ } catch (UnknownHostException ex) {\r
+ ex.printStackTrace();\r
+ } \r
+ return strLocalHostAddress;\r
+ }\r
+\r
+ /**\r
+ * getIsSrcPortWildcard() method\r
+ *\r
+ * @return boolean\r
+ */\r
+ public boolean getIsSrcPortWildcard() {\r
+ return isSrcPortWildCard;\r
+ }\r
+\r
+ /**\r
+ * getIsDstPortWildcard() method\r
+ *\r
+ * @return boolean\r
+ */\r
+ public boolean getIsDstPortWildcard() {\r
+ return isDstPortWildCard;\r
+ }\r
+\r
+\r
+ /**\r
+ * getUrl() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getURL(String strURLComplete) {\r
+\r
+ //e.g. http:// + inetAddress.getHostAddress() + strURLComplete\r
+ // http://192.168.2.254/cgi-bin/mjpg/video.cgi?\r
+ return "http://" + inetAddress.getHostAddress() + ":" + iDstPort + strURLComplete;\r
+ \r
+ }\r
+}\r
--- /dev/null
+\r
+// Java packages\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.IOException;\r
+import java.net.HttpURLConnection;\r
+import java.net.MalformedURLException;\r
+import java.net.UnknownHostException;\r
+import java.net.URL;\r
+import java.net.ProtocolException;\r
+\r
+\r
+/** Class IoTHTTP is a wrapper class that provides\r
+ * minimum interfaces for user to interact with IoT\r
+ * devices in our system\r
+ *\r
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>\r
+ * @version 1.0\r
+ * @since 2016-02-18\r
+ */\r
+public class IoTHTTP {\r
+\r
+ /**\r
+ * IoTHTTP class properties\r
+ */\r
+ private IoTDeviceAddress iotDevAdd;\r
+ private URL url;\r
+ private HttpURLConnection httpConnection;\r
+\r
+ /**\r
+ * Class constructor\r
+ */\r
+ public IoTHTTP(IoTDeviceAddress _iotDevAdd) {\r
+\r
+ iotDevAdd = _iotDevAdd;\r
+ url = null;\r
+ httpConnection = null;\r
+ }\r
+\r
+ /**\r
+ * setURL() method\r
+ *\r
+ * @param strUrlComplete String to complete the URL\r
+ * @return void\r
+ */\r
+ public void setURL(String strUrlComplete) throws MalformedURLException {\r
+\r
+ url = new URL(iotDevAdd.getURL(strUrlComplete));\r
+ System.out.println(url.toString());\r
+\r
+ }\r
+\r
+ /**\r
+ * openConnection() method\r
+ */\r
+ public void openConnection() throws IOException {\r
+\r
+ httpConnection = (HttpURLConnection) url.openConnection();\r
+\r
+ }\r
+\r
+ /**\r
+ * setDoInput() method inherited from HttpURLConnection class\r
+ *\r
+ * @param bSetDoInput\r
+ * @return void\r
+ */\r
+ public void setDoInput(boolean bSetDoInput) {\r
+\r
+ httpConnection.setDoInput(bSetDoInput);\r
+\r
+ }\r
+\r
+ /**\r
+ * setRequestProperty() method inherited from HttpURLConnection class\r
+ *\r
+ * @param strProperty String property\r
+ * @param strHttpAuthCredentials String HTTP authentication credentials\r
+ * @return void\r
+ */\r
+ public void setRequestProperty(String strProperty, String strHttpAuthCredentials) {\r
+\r
+ httpConnection.setRequestProperty(strProperty, strHttpAuthCredentials);\r
+\r
+ }\r
+\r
+ /**\r
+ * setRequestMethod() method inherited from HttpURLConnection class\r
+ *\r
+ * @param strMethod String method\r
+ * @return void\r
+ */\r
+ public void setRequestMethod(String strMethod) throws ProtocolException {\r
+\r
+ httpConnection.setRequestMethod(strMethod);\r
+\r
+ }\r
+\r
+ /**\r
+ * setDoOutput() method inherited from HttpURLConnection class\r
+ *\r
+ * @param doOut\r
+ * @return void\r
+ */\r
+ public void setDoOutput(boolean doOut) {\r
+\r
+ httpConnection.setDoOutput(doOut);\r
+\r
+ }\r
+\r
+ /**\r
+ * getOutputStream() method inherited from HttpURLConnection class\r
+ *\r
+ * @return OutputStream\r
+ */\r
+ public OutputStream getOutputStream() throws IOException {\r
+\r
+ return httpConnection.getOutputStream();\r
+\r
+ }\r
+\r
+ /**\r
+ * getInputStream() method inherited from HttpURLConnection class\r
+ *\r
+ * @return InputStream\r
+ */\r
+ public InputStream getInputStream() throws IOException {\r
+\r
+ return httpConnection.getInputStream();\r
+\r
+ }\r
+\r
+ /**\r
+ * connect() method inherited from HttpURLConnection class\r
+ */\r
+ public void connect() throws IOException {\r
+\r
+ httpConnection.connect();\r
+\r
+ }\r
+\r
+ /**\r
+ * disconnect() method inherited from HttpURLConnection class\r
+ */\r
+ public void disconnect() throws IOException {\r
+\r
+ httpConnection.disconnect();\r
+\r
+ }\r
+}\r
--- /dev/null
+import java.lang.UnsupportedOperationException;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.Spliterator;
+
+
+/** Class IoTSet is the actual implementation of @config IoTSet<...>.
+ * Upon extracting DB information, SetInstrumenter class will use
+ * this class to actually instantiate the Set as IoTSet that uses
+ * Java Set<T> to implement; we don't provide interfaces to modify
+ * the contents, but we do provide means to read them out
+ *
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
+ * @version 1.0
+ * @since 2015-12-01
+ */
+public final class IoTSet<T> {
+
+ /**
+ * Reference to an object Set<T>
+ */
+ private Set<T> set;
+
+ /**
+ * Class constructor (pass the reference to this immutable wrapper)
+ */
+ protected IoTSet(Set<T> s) {
+
+ set = s;
+ }
+
+ /**
+ * contains() method inherited from Set interface
+ */
+ public boolean contains(T o) {
+
+ return set.contains(o);
+
+ }
+
+ /**
+ * isEmpty() method inherited from Set interface
+ */
+ public boolean isEmpty() {
+
+ return set.isEmpty();
+
+ }
+
+ /**
+ * iterator() method inherited from Set interface
+ */
+ public Iterator<T> iterator() {
+
+ return new HashSet<T>(set).iterator();
+
+ }
+
+ /**
+ * size() method inherited from Set interface
+ */
+ public int size() {
+
+ return set.size();
+
+ }
+
+ /**
+ * values() method to return Set object values for easy iteration
+ */
+ public Set<T> values() {
+
+ return new HashSet<T>(set);
+
+ }
+}
--- /dev/null
+
+// Java packages
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+
+
+/** Class IoTUDP is a wrapper class that provides
+ * minimum interfaces for user to interact with IoT
+ * devices in our system - adapted from my colleague's
+ * work (Ali Younis - ayounis @ uci.edu)
+ *
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
+ * @version 1.0
+ * @since 2016-02-20
+ */
+public class IoTUDP {
+
+ /**
+ * IoTUDP class properties
+ */
+ private final String strHostAddress;
+ private final int iSrcPort;
+ private final int iDstPort;
+ private DatagramSocket socket; // the socket interface that we are guarding
+ private boolean didClose; // make sure that the clean up was done correctly
+
+ /**
+ * Class constructor
+ */
+ public IoTUDP(IoTDeviceAddress iotDevAdd) throws SocketException, IOException {
+
+ strHostAddress = iotDevAdd.getHostAddress();
+ iSrcPort = iotDevAdd.getSourcePortNumber();
+ iDstPort = iotDevAdd.getDestinationPortNumber();
+
+ socket = new DatagramSocket(iSrcPort);
+ didClose = false;
+ }
+
+ /**
+ * sendData() method
+ *
+ * @param bData Byte type that passes the data to be sent
+ * @return void
+ */
+ public void sendData(byte[] bData) throws UnknownHostException, IOException {
+
+ DatagramPacket dpSendPacket = new DatagramPacket(bData, bData.length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(dpSendPacket);
+ }
+
+ /**
+ * recieveData() method
+ *
+ * @param iMaxDataLength Integer maximum data length as reference
+ * @return byte[]
+ */
+ public byte[] recieveData(int iMaxDataLength) throws IOException {
+
+ byte[] bReceiveData = new byte[iMaxDataLength];
+ DatagramPacket dpReceivePacket = new DatagramPacket(bReceiveData, bReceiveData.length);
+ socket.receive(dpReceivePacket);
+
+ return dpReceivePacket.getData();
+ }
+
+ /**
+ * setSoTimeout() method
+ *
+ * @param iTimeout Integer timeout time
+ */
+ public void setSoTimeout(int iTimeout) throws SocketException {
+
+ socket.setSoTimeout(iTimeout);
+
+ }
+
+ /**
+ * setSendBufferSize() method
+ *
+ * @param iSize Integer buffer size
+ */
+ public void setSendBufferSize(int iSize) throws SocketException {
+
+ socket.setSendBufferSize(iSize);
+
+ }
+
+ /**
+ * setReceiveBufferSize() method
+ *
+ * @param iSize Integer buffer size
+ */
+ public void setReceiveBufferSize(int iSize) throws SocketException {
+
+ socket.setReceiveBufferSize(iSize);
+
+ }
+
+ /**
+ * setReuseAddress(boolean on) method
+ */
+ public void setReuseAddress(boolean on) throws SocketException {
+
+ socket.setReuseAddress(on);
+ }
+
+ /**
+ * close() method
+ */
+ public void close() {
+
+ socket.close();
+ didClose = true;
+
+ }
+
+ /**
+ * close() called by the garbage collector right before trashing object
+ */
+ public void finalize() throws SocketException {
+
+ if (!didClose) {
+ close();
+ throw new SocketException("Socket not closed before object destruction, must call close method.");
+ }
+
+ }
+}
--- /dev/null
+/** Class LightBulb interface for the light bulb devices.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-01-27
+ */
+
+
+public class LightBulb {
+
+
+ public LightBulb() {
+
+ }
+
+ /** Method to turn the light bulb on (Physically illuminate the area).
+ *
+ * @param None.
+ *
+ * @return [void] None.
+ */
+
+ public void turnOff() {
+ System.out.println("Bulb Turning Off")
+ }
+
+ /** Method to turn the light bulb off.
+ *
+ * @return [void] None.
+ */
+ public void turnOn() {
+ System.out.println("Bulb Turning On")
+ }
+
+
+ /** Method to get the current on/off state of the light bulb.
+ *
+ * @return [boolean] True means bulb on.
+ */
+ public boolean getState() {
+ return true;
+ }
+
+
+ /** Method to set the light bulb color using Standard Hue, Saturation and Brightness
+ * conventions. See "http://www.tydac.ch/color/" for reference.
+ *
+ * @param _hue [double]: Hue value (in degrees).
+ * @param _saturation [double]: Saturation value (percentage).
+ * @param _brightness [double]: Brightness value (percentage).
+ *
+ * @return [void] None.
+ */
+ public void setColor(double _hue, double _saturation, double _brightness) {
+
+ }
+
+
+ /** Method to set the color temperature.
+ *
+ * @param _temperature [int]: Color temperature in degrees kelvin.
+ *
+ * @return [void] None.
+ */
+ public void setTemperature(int _temperature) {
+
+ }
+
+
+ /** Method to get the current hue value of the bulb.
+ *
+ * @return [double] Current hue value of the bulb in degrees.
+ */
+ public double getHue() {
+ return 1;
+ }
+
+
+ /** Method to get the current saturation value of the bulb.
+ *
+ * @return [double] Current saturation value of the bulb as a percentage.
+ */
+ public double getSaturation() {
+ return 1;
+
+ }
+
+
+ /** Method to get the current brightness value of the bulb.
+ *
+ * @return [double] Current brightness value of the bulb as a percentage.
+ */
+ public double getBrightness() {
+ return 1;
+
+ }
+
+
+ /** Method to get the current color temperature value of the bulb.
+ *
+ * @return [double] Current color temperature value of the bulb in kelvin.
+ */
+ public int getTemperature() {
+ return 1;
+
+ }
+
+
+ /** Method to get the hue range lower bound supported by the bulb.
+ *
+ * @return [double] Hue lower bound in degrees.
+ */
+ public double getHueRangeLowerBound() {
+ return 1;
+
+ }
+
+
+ /** Method to get the hue range upper bound supported by the bulb.
+ *
+ * @return [double] Hue upper bound in degrees.
+ */
+ public double getHueRangeUpperBound() {
+ return 1;
+
+ }
+
+
+ /** Method to get the saturation range lower bound supported by the bulb.
+ *
+ * @return [double] Saturation lower bound as a percentage.
+ */
+ public double getSaturationRangeLowerBound() {
+ return 1;
+
+ }
+
+
+ /** Method to get the saturation range upper bound supported by the bulb.
+ *
+ * @return [double] Saturation upper bound as a percentage.
+ */
+ public double getSaturationRangeUpperBound() {
+ return 1;
+
+ }
+
+
+ /** Method to get the brightness range lower bound supported by the bulb.
+ *
+ * @return [double] Brightness lower bound as a percentage.
+ */
+ public double getBrightnessRangeLowerBound() {
+ return 1;
+
+ }
+
+
+ /** Method to get the brightness range upper bound supported by the bulb.
+ *
+ * @return [double] Brightness upper bound as a percentage.
+ */
+ public double getBrightnessRangeUpperBound() {
+ return 1;
+ }
+
+
+ /** Method to get the temperature range lower bound supported by the bulb.
+ *
+ * @return [int] Temperature lower bound as a percentage.
+ */
+ public int getTemperatureRangeLowerBound() {
+ return 1;
+
+ }
+
+
+ /** Method to get the temperature range upper bound supported by the bulb.
+ *
+ * @return [int] Temperature upper bound as a percentage.
+ */
+ public int getTemperatureRangeUpperBound() {
+ return 1;
+
+ }
+
+
+ /** Method to initialize the bulb, if the bulb needs to be initialized.
+ *
+ * @return [void] None.
+ */
+ public void init() {
+
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+import iotcloud.*;
+import java.util.*;
+
+class LightsController {
+
+ public static void main(String[] args) throws Exception {
+
+ LightBulb bulb1 = new LightBulb();
+ LightBulb bulb2 = new LightBulb();
+ LightBulb bulb3 = new LightBulb();
+
+
+ List<LightBulb> bulbs = new ArrayList<LightBulb>();
+ bulbs.add(bulb1);
+ bulbs.add(bulb2);
+ bulbs.add(bulb3);
+
+
+ String a1 = "bulb1";
+ String a2 = "bulb2";
+ String a3 = "bulb3";
+
+ IoTString ia1 = new IoTString(a1);
+ IoTString ia2 = new IoTString(a2);
+ IoTString ia3 = new IoTString(a3);
+
+
+ List<IoTString> keys = new ArrayList<IoTString>();
+ keys.add(ia1);
+ keys.add(ia2);
+ keys.add(ia3);
+
+
+ String valueA = "on";
+ IoTString iValueA = new IoTString(valueA);
+
+
+ String pingTimerKey = "bulbController";
+ IoTString ipingTimerKey = new IoTString(pingTimerKey);
+
+
+
+ System.out.println("Starting System");
+ int counter = 0;
+
+
+ Table t1 = null;
+ try {
+ t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, 6000);
+ t1.addLocalCommunication(1000, "192.168.2.50", 6001);
+
+ t1.rebuild();
+ } catch (Error e) {
+
+ e.printStackTrace();
+ for (int i = 0; i < 3; i++) {
+ bulbs.get(i).setColor(0, 100, 100);
+ }
+
+
+
+ while (true) {
+ for (int i = 0; i < 3; i++) {
+ bulbs.get(i).turnOff();
+ }
+ Thread.sleep(1000);
+
+ for (int i = 0; i < 3; i++) {
+ bulbs.get(i).turnOn();
+ }
+ Thread.sleep(1000);
+ }
+ }
+
+
+
+
+ // Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, -1);
+ // t2.rebuild();
+
+
+ while (true) {
+
+ try {
+
+ System.out.println("Loop");
+
+ String pingTimer = Long.toString(System.currentTimeMillis());
+ IoTString ipingTimer = new IoTString(pingTimer);
+
+ // t1.update();
+ t1.startTransaction();
+ t1.addKV(ipingTimerKey, ipingTimer);
+ t1.commitTransaction();
+
+ // // t2.update();
+ // t2.startTransaction();
+ // t2.addKV(ipingTimerKey, ipingTimer);
+ // t2.commitTransaction();
+
+
+
+
+
+
+
+ for (int i = 0; i < 3; i++) {
+ IoTString testValA1 = t1.getCommitted(keys.get(i));
+ if ((testValA1 != null) && (testValA1.equals(iValueA) == true)) {
+ bulbs.get(i).turnOn();
+ } else {
+ bulbs.get(i).turnOff();
+ }
+ }
+
+ Thread.sleep(1000);
+
+ } catch (Error e) {
+
+ e.printStackTrace();
+ for (int i = 0; i < 3; i++) {
+ bulbs.get(i).setColor(0, 100, 100);
+ }
+
+
+
+ while (true) {
+ for (int i = 0; i < 3; i++) {
+ bulbs.get(i).turnOff();
+ }
+ Thread.sleep(1000);
+
+ for (int i = 0; i < 3; i++) {
+ bulbs.get(i).turnOn();
+ }
+ Thread.sleep(1000);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+First build using:
+ ./build.bash
+
+To run this example run:
+
+ # 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>
+
+
+Dont forget to clear the cloud server directory
+
+
+
+
+https://javatutorial.net/raspberry-pi-java-tutorial
\ No newline at end of file
--- /dev/null
+import iotcloud.*;
+import java.util.*;
+import java.lang.*;
+import java.io.*;
+
+class Sensor {
+ public static void main(String[] args) throws Exception {
+
+
+ long pstart = System.currentTimeMillis();
+
+
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 361, -1);
+
+ try {
+ Thread.sleep(5000);
+ } catch (Exception e) {
+
+ }
+
+ long start = System.currentTimeMillis();
+ t1.rebuild();
+
+
+ System.out.println("Sleeping......");
+
+ try {
+ Thread.sleep(10000);
+ } catch (Exception e) {
+
+ }
+
+ System.out.println("Pulling......");
+ long stop1 = System.currentTimeMillis();
+
+
+
+
+
+ System.out.println(stop1 - pstart);
+ t1.update();
+
+
+
+
+ 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);
+
+
+
+ String a1 = "bulb1";
+ IoTString ia1 = new IoTString(a1);
+
+
+
+ IoTString senDat = new IoTString(dat);
+
+ t1.update();
+ t1.startTransaction();
+ t1.addKV(ia1, senDat);
+ t1.commitTransaction();
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ long stop2 = System.currentTimeMillis();
+
+ System.out.println("Done......");
+ System.out.println(stop1 - start);
+ System.out.println(stop2 - stop1);
+
+ // t1.startTransaction();
+ // t1.addKV(ipingTimerKey, ipingTimer);
+ // t1.addKV(ia1, senDat);
+ // t1.commitTransaction();
+
+
+
+
+
+ // 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(5000);
+
+ // } 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
--- /dev/null
+import iotcloud.*;
+import java.util.*;
+
+class Setup {
+
+ public static void main(String[] args) throws Exception {
+
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+
+
+ // for ( int i = 0; i < 150; i++) {
+
+ // System.out.println(i);
+
+ // String a1 = "bulb" + i;
+ // IoTString ia1 = new IoTString(a1);
+ // t1.createNewKey(ia1, 321);
+ // t1.update();
+
+
+ // // t1.update();
+ // // t1.startTransaction();
+ // // t1.addKV(ia1, ia1);
+ // // t1.commitTransaction();
+
+ // }
+
+
+ String a1 = "bulb1";
+ String a2 = "bulb2";
+ String a3 = "bulb3";
+ IoTString ia1 = new IoTString(a1);
+ IoTString ia2 = new IoTString(a2);
+ IoTString ia3 = new IoTString(a3);
+
+
+
+ String b1 = "wemo1";
+ String b2 = "wemo2";
+ IoTString ib1 = new IoTString(b1);
+ IoTString ib2 = new IoTString(b2);
+
+
+ String c1 = "sensor";
+ IoTString ic1 = new IoTString(c1);
+
+
+ String pingTimerKey = "bulbController";
+ IoTString ipingTimerKey = new IoTString(pingTimerKey);
+
+
+ String pingTimerKey2 = "wemoController";
+ IoTString ipingTimerKey2 = new IoTString(pingTimerKey2);
+
+
+ String pingTimerKey3 = "sensorController";
+ IoTString ipingTimerKey3 = new IoTString(pingTimerKey3);
+
+
+ t1.createNewKey(ia1, 321);
+ t1.createNewKey(ia2, 321);
+ t1.createNewKey(ia3, 321);
+ t1.createNewKey(ipingTimerKey, 321);
+
+ t1.createNewKey(ib1, 351);
+ t1.createNewKey(ib2, 351);
+ t1.createNewKey(ipingTimerKey2, 351);
+
+
+ t1.createNewKey(ic1, 361);
+ t1.createNewKey(ipingTimerKey3, 361);
+
+ t1.update();
+ }
+}
\ No newline at end of file
--- /dev/null
+// IoT Packages
+
+//import iotcode.annotation.*;
+
+// Native Java Packages
+import java.util.Iterator;
+import javax.xml.parsers.*;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import org.w3c.dom.*;
+import org.xml.sax.SAXException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.Semaphore;
+import java.util.List;
+import java.util.ArrayList;
+
+public class Wemo {
+
+ public Wemo() {
+
+ }
+
+ public void turnOff() {
+
+ }
+
+ public void turnOn() {
+ }
+}
\ No newline at end of file
--- /dev/null
+import iotcloud.*;
+import java.util.*;
+
+
+class WemoController {
+ public static void main(String[] args) throws Exception {
+
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t1.rebuild();
+
+ String a1 = "wemo1";
+ String a2 = "wemo2";
+
+ IoTString ia1 = new IoTString(a1);
+ IoTString ia2 = new IoTString(a2);
+
+ List<IoTString> keys = new ArrayList<IoTString>();
+ keys.add(ia1);
+ keys.add(ia2);
+
+ Wemo wemo1 = new Wemo();
+ Wemo wemo2 = new Wemo();
+
+ List<Wemo> wemos = new ArrayList<Wemo>();
+ wemos.add(wemo1);
+ wemos.add(wemo2);
+
+
+ String pingTimerKey = "wemoController";
+ IoTString ipingTimerKey = new IoTString(pingTimerKey);
+
+
+ String valueA = "on";
+ IoTString iValueA = new IoTString(valueA);
+
+ System.out.println("Starting System");
+ int counter = 0;
+
+
+ while (true) {
+ try {
+ String pingTimer = Long.toString(System.currentTimeMillis());
+ IoTString ipingTimer = new IoTString(pingTimer);
+
+ t1.update();
+ t1.startTransaction();
+ t1.addKV(ipingTimerKey, ipingTimer);
+ t1.commitTransaction();
+
+
+ t1.update();
+ Thread.sleep(1000);
+
+ for (int i = 0; i < 2; i++) {
+ IoTString testValA1 = t1.getCommitted(keys.get(i));
+ if ((testValA1 != null) && (testValA1.equals(iValueA) == true)) {
+ wemos.get(i).turnOn();
+ } else {
+ wemos.get(i).turnOff();
+ }
+ }
+
+ } 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
--- /dev/null
+#!/bin/sh
+
+# javac -cp .:/Users/Ali/Desktop/iotcloud/version2/src/java/iotcloud/bin *.java
+
+javac -cp .:../iotcloud/bin *.java
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+java -cp .:../iotcloud/bin LightsController
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+java -cp .:../iotcloud/bin WemoController
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+java -cp .:../iotcloud/bin Sensor
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+java -cp .:../iotcloud/bin Filler
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+java -cp .:../iotcloud/bin Filler2
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+java -cp .:../iotcloud/bin Setup
\ No newline at end of file