Adding config file for sharing.
[iot2.git] / benchmarks / other / ZigbeeTest / ZigbeeTestDoorlock.java
1 import java.util.Map;
2 import java.net.*;
3 import java.io.*;
4 import java.util.*;
5
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;
13
14         public void newReadingAvailable(int _value, boolean _activeValue) {
15
16                 System.out.println("New Message!!!!");
17                 int status = _value;
18                 switch (status) {
19                         case 0:
20                                 System.out.println("Not fully locked");
21                                 break;
22                         case 1:
23                                 System.out.println("Locked");
24                                 break;
25                         case 2:
26                                 System.out.println("Unlocked");
27                                 break;
28                         default:
29                                 System.out.println("Unknown value: " + status);
30                                 break;
31                 }
32         }
33
34     public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException {
35
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);
46         socket.close();
47
48         IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false);
49         IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS);
50
51         Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
52         zigSet.add(zigAddrLong);
53         IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
54
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);
59         
60         ZigbeeTestDoorlock zTest = new ZigbeeTestDoorlock();
61         sen.registerCallback(zTest);
62
63         System.out.println("About to init");
64         sen.init();
65
66         System.out.println("Loop Begin");
67         while (true) {
68
69         }
70     }
71
72 }