Adjustments to ZigbeeTest and Python files to use just 1 port for shooting Zigbee...
[iot2.git] / benchmarks / other / ZigbeeTest / ZigbeeTest_motion.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_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
17
18 //000d6f000bbd5398
19 //000d6f00057c92a7
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);
24     }
25
26     public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
27
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                 DatagramSocket socket = new DatagramSocket(12345);
35         socket.setSendBufferSize(4096);
36         socket.setReceiveBufferSize(4096);
37         socket.send(sendPacket);
38                 socket.setReuseAddress(true);
39         socket.close();
40
41         IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false);
42         IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
43
44         Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
45         zigSet.add(zigAddrLong);
46         IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
47
48         Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
49         devSet.add(zigUdpAddr);
50         IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
51         MotionSensor sen = new MotionSensor(devIotSet, zigIotSet);
52         
53         System.out.println("About to init");
54         sen.init();
55
56         ZigbeeTest_motion zTest = new ZigbeeTest_motion();
57         sen.registerCallback(zTest);
58
59         System.out.println("Loop Begin");
60         while (true) {
61
62         }
63     }
64 }