Adjusting and cleaning up ZigbeeTest to install Vigilia ZigBee gateway and devices.
[iot2.git] / benchmarks / other / ZigbeeTest / ZigbeeTestMoisture.java
diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestMoisture.java b/benchmarks/other/ZigbeeTest/ZigbeeTestMoisture.java
new file mode 100644 (file)
index 0000000..6c07a7e
--- /dev/null
@@ -0,0 +1,65 @@
+import java.util.Map;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+public class ZigbeeTestMoisture implements MoistureSensorSmartCallback {
+
+    public final int SOCKET_SEND_BUFFER_SIZE = 1024;
+    public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
+    private static final String MY_IP_ADDRESS = "192.168.1.198";
+    private static final String DEVICE_MAC_ADDRESS = "000d6f0003ebf2ee"; //doorlock sensor
+    private static final String GATEWAY = "192.168.1.192";
+    private static final int LOCAL_COMM_SOCKET = 5557;
+
+
+    public ZigbeeTestMoisture() {
+    }
+
+
+    public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) {
+        System.out.println("New Message!!!!");
+        System.out.println(moisture);
+        System.out.println("Reading time: " + timeStampOfLastReading);
+    }
+
+
+    public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException {
+
+        String message = "type: policy_set\n";
+           message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
+           message += "port: " + LOCAL_COMM_SOCKET + "\n";  // port number
+        message += "device_address_long: " + DEVICE_MAC_ADDRESS + "\n";
+       DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(GATEWAY), 5005); // address and port of the gateway
+
+        DatagramSocket socket = new DatagramSocket(12345);
+        socket.setSendBufferSize(4096);
+        socket.setReceiveBufferSize(4096);
+        socket.send(sendPacket);
+        socket.setReuseAddress(true);
+        socket.close();
+
+       IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false);
+        IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS);
+
+        Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
+        zigSet.add(zigAddrLong);
+        IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
+
+        Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
+        devSet.add(zigUdpAddr);
+        IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
+        SpruceSensor sen = new SpruceSensor(devIotSet, zigIotSet);
+        
+        System.out.println("About to init");
+        sen.init();
+       System.out.println("Passed init!");
+        ZigbeeTestMoisture zTest = new ZigbeeTestMoisture();
+        sen.registerCallback(zTest);
+
+        System.out.println("Loop Begin");
+        while (true) {
+
+        }
+    }
+}