7 import iotruntime.zigbee.*;
9 //import iotcode.interfaces.*;
10 import java.rmi.RemoteException;
12 public class ZigbeeTest_motion 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 public static final String DEVIDE_MAC_ADDRESS = "000d6f00057c92a7"; //motion
20 public void newReadingAvailable(int _value, boolean _activeValue) {
21 System.out.println("New Message!!!!");
22 System.out.println("motion : "+ _value);
23 System.out.println("active? : "+ _activeValue);
26 public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
28 String message = "type: policy_set\n";
29 message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
30 message += "port: " + "5956\n"; // port number
31 message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
32 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
33 DatagramSocket socket = new DatagramSocket(11222);
34 socket.setSendBufferSize(4096);
35 socket.setReceiveBufferSize(4096);
36 socket.send(sendPacket);
38 IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false);
39 IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
41 Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
42 zigSet.add(zigAddrLong);
43 IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
45 Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
46 devSet.add(zigUdpAddr);
47 IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
48 MotionSensor sen = new MotionSensor(devIotSet, zigIotSet);
50 System.out.println("About to init");
53 ZigbeeTest_motion zTest = new ZigbeeTest_motion();
54 sen.registerCallback(zTest);
56 System.out.println("Loop Begin");