6 public class ZigbeeTestDoorlock implements SmartthingsSensorCallback {
7 public final int SOCKET_SEND_BUFFER_SIZE = 1024;
8 public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
9 private static final String MY_IP_ADDRESS = "192.168.1.198";
10 private static final String DEVICE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor
11 private static final String GATEWAY = "192.168.1.192";
12 private static final int LOCAL_COMM_SOCKET = 5960;
14 public void newReadingAvailable(int _value, boolean _activeValue) {
16 System.out.println("New Message!!!!");
20 System.out.println("Not fully locked");
23 System.out.println("Locked");
26 System.out.println("Unlocked");
29 System.out.println("Unknown value: " + status);
34 public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException {
36 String message = "type: policy_set\n";
37 message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
38 message += "port: " + LOCAL_COMM_SOCKET + "\n"; // port number
39 message += "device_address_long: " + DEVICE_MAC_ADDRESS + "\n";
40 DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(GATEWAY), 5005); // address and port of the gateway which means Raspberry PI's IP address
41 DatagramSocket socket = new DatagramSocket(12345);
42 socket.setSendBufferSize(4096);
43 socket.setReceiveBufferSize(4096);
44 socket.send(sendPacket);
45 socket.setReuseAddress(true);
48 IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false);
49 IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS);
51 Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
52 zigSet.add(zigAddrLong);
53 IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
55 Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
56 devSet.add(zigUdpAddr);
57 IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
58 DoorlockSensor sen = new DoorlockSensor(devIotSet, zigIotSet);
60 ZigbeeTestDoorlock zTest = new ZigbeeTestDoorlock();
61 sen.registerCallback(zTest);
63 System.out.println("About to init");
66 System.out.println("Loop Begin");