Testing Smartthings sensors with some adjustments for 4th benchmark
[iot2.git] / benchmarks / other / ZigbeeTest / ZigbeeTest_waterleak.java
1 import java.util.Map;
2 import java.net.*;
3 import java.io.*;
4 import java.util.*;
5
6 import iotruntime.*;
7 import iotruntime.zigbee.*;
8
9 //import iotcode.interfaces.*;
10 import java.rmi.RemoteException;
11
12 public class ZigbeeTest_waterleak implements SmartthingsSensorCallback {
13     public final int SOCKET_SEND_BUFFER_SIZE = 1024;
14     public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
15     private static final String MY_IP_ADDRESS = "192.168.2.108";
16     private static final int PORT_NUMBER = 5959;
17     public static final String DEVIDE_MAC_ADDRESS = "000d6f000ada75e3"; //water leak
18
19     public void newReadingAvailable(int _value, boolean _activeValue) {
20         System.out.println("New Message!!!!");
21         System.out.println("water leak : "+ _value);
22         System.out.println("active? : "+ _activeValue);
23     }
24
25     public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
26
27         String message = "type: policy_set\n";
28         message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
29         message += "port: " + PORT_NUMBER + "\n";  // port number
30         message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
31         DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005); // address and port of the gateway which means Raspberry PI's IP address
32         DatagramSocket socket = new DatagramSocket(22222);
33         socket.setSendBufferSize(4096);
34         socket.setReceiveBufferSize(4096);
35         socket.send(sendPacket);
36
37         IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false);
38         IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
39
40         Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
41         zigSet.add(zigAddrLong);
42         IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
43
44         Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
45         devSet.add(zigUdpAddr);
46         IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
47         WaterLeakSensor sen = new WaterLeakSensor(devIotSet, zigIotSet);
48         
49         System.out.println("About to init");
50         sen.init();
51
52         ZigbeeTest_waterleak zTest = new ZigbeeTest_waterleak();
53                 sen.registerCallback(zTest);
54
55         System.out.println("Loop Begin");
56         while (true) {
57
58         }
59     }
60 }