b19eca912deba5cc3f0ba1ad64fb6b3622e4724b
[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.1.198";
16     public static final String DEVIDE_MAC_ADDRESS = "000d6f000bbd5398"; //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.1.192"), 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         IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("192.168.1.192", 5956, 5005,false,false);
43         IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
44
45         Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
46         zigSet.add(zigAddrLong);
47         IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
48
49         Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
50         devSet.add(zigUdpAddr);
51         IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
52         MotionSensor sen = new MotionSensor(devIotSet, zigIotSet);
53         
54         System.out.println("About to init");
55         sen.init();
56
57         ZigbeeTest_motion zTest = new ZigbeeTest_motion();
58         sen.registerCallback(zTest);
59
60         System.out.println("Loop Begin");
61         while (true) {
62
63         }
64     }
65 }