7 import iotruntime.zigbee.*;
9 import iotcode.interfaces.*;
10 import java.rmi.RemoteException;
12 //public class ZigbeeTest_doorlock implements IoTZigbeeCallback {
13 public class ZigbeeTest_doorlock implements SmartthingsSensorCallback {
14 public final int SOCKET_SEND_BUFFER_SIZE = 1024;
15 public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
16 private static final String MY_IP_ADDRESS = "192.168.1.198";
17 public static final String DEVIDE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor
19 //public void newReadingAvailable(SmartthingsSensor _sensor) {
20 public void newReadingAvailable(int _value, boolean _activeValue) {
22 System.out.println("New Message!!!!");
23 //int status = ((DoorlockSensor)_sensor).getStatus();
27 System.out.println("Not fully locked");
30 System.out.println("Locked");
33 System.out.println("Unlocked");
36 System.out.println("Unknown value: " + status);
41 public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
43 String message = "type: policy_set\n";
44 message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
45 message += "port: " + "5959\n"; // port number
46 message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
47 DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("127.0.0.1"), 5005); // address and port of the gateway which means Raspberry PI's IP address
48 DatagramSocket socket = new DatagramSocket(12345/*test number*/);
49 socket.setSendBufferSize(4096);
50 socket.setReceiveBufferSize(4096);
51 socket.send(sendPacket);
52 socket.setReuseAddress(true);
55 IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5959, 5005,false,false);
56 IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
58 Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
59 zigSet.add(zigAddrLong);
60 IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
62 Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
63 devSet.add(zigUdpAddr);
64 IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
65 DoorlockSensor sen = new DoorlockSensor(devIotSet, zigIotSet);
67 ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock();
68 sen.registerCallback(zTest);
70 System.out.println("About to init");
73 // ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock();
74 // sen.registerCallback(zTest);
77 System.out.println("Loop Begin");