7 import iotruntime.zigbee.*;
9 //import iotcode.interfaces.*;
10 import java.rmi.RemoteException;
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.1.198";
16 private static final int PORT_NUMBER = 5959;
17 public static final String DEVIDE_MAC_ADDRESS = "000d6f000ada75e3"; //water leak
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);
25 public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
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.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address
32 //DatagramSocket socket = new DatagramSocket(22222);
33 DatagramSocket socket = new DatagramSocket(12345);
34 socket.setSendBufferSize(4096);
35 socket.setReceiveBufferSize(4096);
36 socket.send(sendPacket);
37 socket.setReuseAddress(true);
40 //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false);
41 IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", PORT_NUMBER, 5005,false,false);
42 IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
44 Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
45 zigSet.add(zigAddrLong);
46 IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
48 Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
49 devSet.add(zigUdpAddr);
50 IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
51 WaterLeakSensor sen = new WaterLeakSensor(devIotSet, zigIotSet);
53 System.out.println("About to init");
56 ZigbeeTest_waterleak zTest = new ZigbeeTest_waterleak();
57 sen.registerCallback(zTest);
59 System.out.println("Loop Begin");