From b81f06bd8ca4858189639814bdb3ae3a4a539dd5 Mon Sep 17 00:00:00 2001 From: Ali Younis Date: Fri, 6 Oct 2017 11:23:15 -0700 Subject: [PATCH] Deviceless Benchmark --- .../BulbSwitch.java | 68 ++++++ .../Filler.java | 45 ++++ .../Filler2.java | 44 ++++ .../IoTAddress.java | 77 +++++++ .../IoTDeviceAddress.java | 151 +++++++++++++ .../IoTHTTP.java | 150 +++++++++++++ .../IoTSet.java | 79 +++++++ .../IoTUDP.java | 133 +++++++++++ .../LightBulb.java | 210 ++++++++++++++++++ .../LightsController.java | 141 ++++++++++++ .../light_fan_embed_fake_benchmark/README.txt | 22 ++ .../Sensor.java | 172 ++++++++++++++ .../light_fan_embed_fake_benchmark/Setup.java | 76 +++++++ .../light_fan_embed_fake_benchmark/Wemo.java | 31 +++ .../WemoController.java | 79 +++++++ .../light_fan_embed_fake_benchmark/build.bash | 5 + .../light_fan_embed_fake_benchmark/run1.bash | 3 + .../light_fan_embed_fake_benchmark/run2.bash | 3 + .../light_fan_embed_fake_benchmark/run3.bash | 3 + .../runFiller.bash | 3 + .../runFiller2.bash | 3 + .../runSetup.bash | 3 + 22 files changed, 1501 insertions(+) create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/BulbSwitch.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/Filler.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/Filler2.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/IoTAddress.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/IoTDeviceAddress.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/IoTHTTP.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/IoTSet.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/IoTUDP.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/LightBulb.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/LightsController.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/README.txt create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/Sensor.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/Setup.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/Wemo.java create mode 100644 version2/src/java/light_fan_embed_fake_benchmark/WemoController.java create mode 100755 version2/src/java/light_fan_embed_fake_benchmark/build.bash create mode 100755 version2/src/java/light_fan_embed_fake_benchmark/run1.bash create mode 100755 version2/src/java/light_fan_embed_fake_benchmark/run2.bash create mode 100755 version2/src/java/light_fan_embed_fake_benchmark/run3.bash create mode 100755 version2/src/java/light_fan_embed_fake_benchmark/runFiller.bash create mode 100755 version2/src/java/light_fan_embed_fake_benchmark/runFiller2.bash create mode 100755 version2/src/java/light_fan_embed_fake_benchmark/runSetup.bash diff --git a/version2/src/java/light_fan_embed_fake_benchmark/BulbSwitch.java b/version2/src/java/light_fan_embed_fake_benchmark/BulbSwitch.java new file mode 100644 index 0000000..172446d --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/BulbSwitch.java @@ -0,0 +1,68 @@ + + +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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/Filler.java b/version2/src/java/light_fan_embed_fake_benchmark/Filler.java new file mode 100644 index 0000000..82871f5 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/Filler.java @@ -0,0 +1,45 @@ + + + +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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/Filler2.java b/version2/src/java/light_fan_embed_fake_benchmark/Filler2.java new file mode 100644 index 0000000..0e84979 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/Filler2.java @@ -0,0 +1,44 @@ + + + +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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/IoTAddress.java b/version2/src/java/light_fan_embed_fake_benchmark/IoTAddress.java new file mode 100644 index 0000000..ee96322 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/IoTAddress.java @@ -0,0 +1,77 @@ + +// Java packages +import java.net.Socket; +import java.net.ServerSocket; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** Class IoTAddress is a wrapper class to pass + * IoTSet of any addresses from master to slave + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-04-22 + */ +public class IoTAddress { + + /** + * IoTDeviceAddress class properties + */ + protected final InetAddress inetAddress; + + /** + * Class constructor + * + * @param sAddress String address + */ + protected IoTAddress(String sAddress) throws UnknownHostException { + + inetAddress = InetAddress.getByName(sAddress); + } + + /** + * getHostAddress() method + * + * @return String + */ + public String getHostAddress() { + + return inetAddress.getHostAddress(); + + } + + /** + * getHostName() method + * + * @return String + */ + public String getHostName() { + + return inetAddress.getHostName(); + + } + + /** + * getUrl() method + * + * @return String + */ + public String getURL(String strURLComplete) { + + //e.g. http:// + inetAddress.getHostAddress() + strURLComplete + // http://192.168.2.254/cgi-bin/mjpg/video.cgi? + return "http://" + inetAddress.getHostAddress() + strURLComplete; + + } + + /** + * getCompleteAddress() method + * + * @return String + */ + public String getCompleteAddress() { + + return inetAddress.toString(); + + } +} diff --git a/version2/src/java/light_fan_embed_fake_benchmark/IoTDeviceAddress.java b/version2/src/java/light_fan_embed_fake_benchmark/IoTDeviceAddress.java new file mode 100644 index 0000000..d738f3f --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/IoTDeviceAddress.java @@ -0,0 +1,151 @@ +// Java packages +import java.net.Socket; +import java.net.ServerSocket; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** Class IoTDeviceAddress is a wrapper class to pass + * IoTSet of device addresses from master to slave + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-02-18 + */ +public class IoTDeviceAddress extends IoTAddress { + + /** + * IoTDeviceAddress class properties + */ + private int iSrcPort; + private int iDstPort; + private final String sAddress; + + // the wildcard status of this address + private final boolean isSrcPortWildCard; + private final boolean isDstPortWildCard; + + + /** + * Class constructor + * + * @param sAddress String address + * @param _iSrcPort Source port number + * @param _iDstPort Destination port number + * @param _isSrcPortWildCard Is this source port a wild card (=can change port number)? + * @param _isDstPortWildCard Is this destination port a wild card (=can change port number)? + */ + protected IoTDeviceAddress(String _sAddress, int _iSrcPort, int _iDstPort, boolean _isSrcPortWildCard, + boolean _isDstPortWildCard) throws UnknownHostException { + + super(_sAddress); + sAddress = _sAddress; + iSrcPort = _iSrcPort; + iDstPort = _iDstPort; + + isSrcPortWildCard = _isSrcPortWildCard; + isDstPortWildCard = _isDstPortWildCard; + } + + /** + * getSourcePortNumber() method + * + * @return int + */ + public int getSourcePortNumber() { + + return iSrcPort; + + } + + /** + * getDestinationPortNumber() method + * + * @return int + */ + public int getDestinationPortNumber() { + + return iDstPort; + + } + + /** + * setSrcPort() method + * + * @param port Port number + * @return void + */ + public void setSrcPort(int port) { + if (isSrcPortWildCard) { + iSrcPort = port; + } + } + + /** + * setDstPort() method + * + * @param port Port number + * @return void + */ + public void setDstPort(int port) { + if (isDstPortWildCard) { + iDstPort = port; + } + } + + /** + * getAddress() method + * + * @return String + */ + public String getAddress() { + return sAddress; + } + + /** + * getHostAddress() method + * + * @return String + */ + public static String getLocalHostAddress() { + + String strLocalHostAddress = null; + try { + strLocalHostAddress = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException ex) { + ex.printStackTrace(); + } + return strLocalHostAddress; + } + + /** + * getIsSrcPortWildcard() method + * + * @return boolean + */ + public boolean getIsSrcPortWildcard() { + return isSrcPortWildCard; + } + + /** + * getIsDstPortWildcard() method + * + * @return boolean + */ + public boolean getIsDstPortWildcard() { + return isDstPortWildCard; + } + + + /** + * getUrl() method + * + * @return String + */ + public String getURL(String strURLComplete) { + + //e.g. http:// + inetAddress.getHostAddress() + strURLComplete + // http://192.168.2.254/cgi-bin/mjpg/video.cgi? + return "http://" + inetAddress.getHostAddress() + ":" + iDstPort + strURLComplete; + + } +} diff --git a/version2/src/java/light_fan_embed_fake_benchmark/IoTHTTP.java b/version2/src/java/light_fan_embed_fake_benchmark/IoTHTTP.java new file mode 100644 index 0000000..c364c4e --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/IoTHTTP.java @@ -0,0 +1,150 @@ + +// Java packages +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.UnknownHostException; +import java.net.URL; +import java.net.ProtocolException; + + +/** Class IoTHTTP is a wrapper class that provides + * minimum interfaces for user to interact with IoT + * devices in our system + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-02-18 + */ +public class IoTHTTP { + + /** + * IoTHTTP class properties + */ + private IoTDeviceAddress iotDevAdd; + private URL url; + private HttpURLConnection httpConnection; + + /** + * Class constructor + */ + public IoTHTTP(IoTDeviceAddress _iotDevAdd) { + + iotDevAdd = _iotDevAdd; + url = null; + httpConnection = null; + } + + /** + * setURL() method + * + * @param strUrlComplete String to complete the URL + * @return void + */ + public void setURL(String strUrlComplete) throws MalformedURLException { + + url = new URL(iotDevAdd.getURL(strUrlComplete)); + System.out.println(url.toString()); + + } + + /** + * openConnection() method + */ + public void openConnection() throws IOException { + + httpConnection = (HttpURLConnection) url.openConnection(); + + } + + /** + * setDoInput() method inherited from HttpURLConnection class + * + * @param bSetDoInput + * @return void + */ + public void setDoInput(boolean bSetDoInput) { + + httpConnection.setDoInput(bSetDoInput); + + } + + /** + * setRequestProperty() method inherited from HttpURLConnection class + * + * @param strProperty String property + * @param strHttpAuthCredentials String HTTP authentication credentials + * @return void + */ + public void setRequestProperty(String strProperty, String strHttpAuthCredentials) { + + httpConnection.setRequestProperty(strProperty, strHttpAuthCredentials); + + } + + /** + * setRequestMethod() method inherited from HttpURLConnection class + * + * @param strMethod String method + * @return void + */ + public void setRequestMethod(String strMethod) throws ProtocolException { + + httpConnection.setRequestMethod(strMethod); + + } + + /** + * setDoOutput() method inherited from HttpURLConnection class + * + * @param doOut + * @return void + */ + public void setDoOutput(boolean doOut) { + + httpConnection.setDoOutput(doOut); + + } + + /** + * getOutputStream() method inherited from HttpURLConnection class + * + * @return OutputStream + */ + public OutputStream getOutputStream() throws IOException { + + return httpConnection.getOutputStream(); + + } + + /** + * getInputStream() method inherited from HttpURLConnection class + * + * @return InputStream + */ + public InputStream getInputStream() throws IOException { + + return httpConnection.getInputStream(); + + } + + /** + * connect() method inherited from HttpURLConnection class + */ + public void connect() throws IOException { + + httpConnection.connect(); + + } + + /** + * disconnect() method inherited from HttpURLConnection class + */ + public void disconnect() throws IOException { + + httpConnection.disconnect(); + + } +} diff --git a/version2/src/java/light_fan_embed_fake_benchmark/IoTSet.java b/version2/src/java/light_fan_embed_fake_benchmark/IoTSet.java new file mode 100644 index 0000000..ccf8543 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/IoTSet.java @@ -0,0 +1,79 @@ +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 to implement; we don't provide interfaces to modify + * the contents, but we do provide means to read them out + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2015-12-01 + */ +public final class IoTSet { + + /** + * Reference to an object Set + */ + private Set set; + + /** + * Class constructor (pass the reference to this immutable wrapper) + */ + protected IoTSet(Set 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 iterator() { + + return new HashSet(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 values() { + + return new HashSet(set); + + } +} diff --git a/version2/src/java/light_fan_embed_fake_benchmark/IoTUDP.java b/version2/src/java/light_fan_embed_fake_benchmark/IoTUDP.java new file mode 100644 index 0000000..e8966e8 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/IoTUDP.java @@ -0,0 +1,133 @@ + +// 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 + * @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."); + } + + } +} diff --git a/version2/src/java/light_fan_embed_fake_benchmark/LightBulb.java b/version2/src/java/light_fan_embed_fake_benchmark/LightBulb.java new file mode 100644 index 0000000..a4070e1 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/LightBulb.java @@ -0,0 +1,210 @@ +/** Class LightBulb interface for the light bulb devices. + * + * @author Ali Younis + * @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() { + + } + +} + + + + + + + + + + + + + + diff --git a/version2/src/java/light_fan_embed_fake_benchmark/LightsController.java b/version2/src/java/light_fan_embed_fake_benchmark/LightsController.java new file mode 100644 index 0000000..00f265f --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/LightsController.java @@ -0,0 +1,141 @@ +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 bulbs = new ArrayList(); + 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 keys = new ArrayList(); + 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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/README.txt b/version2/src/java/light_fan_embed_fake_benchmark/README.txt new file mode 100644 index 0000000..2cb2d35 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/README.txt @@ -0,0 +1,22 @@ +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 + + +Dont forget to clear the cloud server directory + + + + +https://javatutorial.net/raspberry-pi-java-tutorial \ No newline at end of file diff --git a/version2/src/java/light_fan_embed_fake_benchmark/Sensor.java b/version2/src/java/light_fan_embed_fake_benchmark/Sensor.java new file mode 100644 index 0000000..a9c9e45 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/Sensor.java @@ -0,0 +1,172 @@ +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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/Setup.java b/version2/src/java/light_fan_embed_fake_benchmark/Setup.java new file mode 100644 index 0000000..f32c70a --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/Setup.java @@ -0,0 +1,76 @@ +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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/Wemo.java b/version2/src/java/light_fan_embed_fake_benchmark/Wemo.java new file mode 100644 index 0000000..7e15c27 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/Wemo.java @@ -0,0 +1,31 @@ +// 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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/WemoController.java b/version2/src/java/light_fan_embed_fake_benchmark/WemoController.java new file mode 100644 index 0000000..750ebb6 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/WemoController.java @@ -0,0 +1,79 @@ +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 keys = new ArrayList(); + keys.add(ia1); + keys.add(ia2); + + Wemo wemo1 = new Wemo(); + Wemo wemo2 = new Wemo(); + + List wemos = new ArrayList(); + 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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/build.bash b/version2/src/java/light_fan_embed_fake_benchmark/build.bash new file mode 100755 index 0000000..6fb96e8 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/build.bash @@ -0,0 +1,5 @@ +#!/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 diff --git a/version2/src/java/light_fan_embed_fake_benchmark/run1.bash b/version2/src/java/light_fan_embed_fake_benchmark/run1.bash new file mode 100755 index 0000000..6f97f18 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/run1.bash @@ -0,0 +1,3 @@ +#!/bin/sh + +java -cp .:../iotcloud/bin LightsController \ No newline at end of file diff --git a/version2/src/java/light_fan_embed_fake_benchmark/run2.bash b/version2/src/java/light_fan_embed_fake_benchmark/run2.bash new file mode 100755 index 0000000..c12e81c --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/run2.bash @@ -0,0 +1,3 @@ +#!/bin/sh + +java -cp .:../iotcloud/bin WemoController \ No newline at end of file diff --git a/version2/src/java/light_fan_embed_fake_benchmark/run3.bash b/version2/src/java/light_fan_embed_fake_benchmark/run3.bash new file mode 100755 index 0000000..0b71cec --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/run3.bash @@ -0,0 +1,3 @@ +#!/bin/sh + +java -cp .:../iotcloud/bin Sensor \ No newline at end of file diff --git a/version2/src/java/light_fan_embed_fake_benchmark/runFiller.bash b/version2/src/java/light_fan_embed_fake_benchmark/runFiller.bash new file mode 100755 index 0000000..a687509 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/runFiller.bash @@ -0,0 +1,3 @@ +#!/bin/sh + +java -cp .:../iotcloud/bin Filler \ No newline at end of file diff --git a/version2/src/java/light_fan_embed_fake_benchmark/runFiller2.bash b/version2/src/java/light_fan_embed_fake_benchmark/runFiller2.bash new file mode 100755 index 0000000..7a37caf --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/runFiller2.bash @@ -0,0 +1,3 @@ +#!/bin/sh + +java -cp .:../iotcloud/bin Filler2 \ No newline at end of file diff --git a/version2/src/java/light_fan_embed_fake_benchmark/runSetup.bash b/version2/src/java/light_fan_embed_fake_benchmark/runSetup.bash new file mode 100755 index 0000000..1b0a696 --- /dev/null +++ b/version2/src/java/light_fan_embed_fake_benchmark/runSetup.bash @@ -0,0 +1,3 @@ +#!/bin/sh + +java -cp .:../iotcloud/bin Setup \ No newline at end of file -- 2.34.1