Changing LifxLightBulb config to default to running Lifxtest application, i.e. using...
[iot2.git] / benchmarks / other / ZigbeeTest / ZigbeeTest_doorlock.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_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
18
19     //public void newReadingAvailable(SmartthingsSensor _sensor) {
20         public void newReadingAvailable(int _value, boolean _activeValue) {
21
22                 System.out.println("New Message!!!!");
23                 //int status = ((DoorlockSensor)_sensor).getStatus();
24                 int status = _value;
25                 switch (status) {
26                         case 0:
27                                 System.out.println("Not fully locked");
28                                 break;
29                         case 1:
30                                 System.out.println("Locked");
31                                 break;
32                         case 2:
33                                 System.out.println("Unlocked");
34                                 break;
35                         default:
36                                 System.out.println("Unknown value: " + status);
37                                 break;
38                 }
39         }
40
41     public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
42
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("192.168.1.192"), 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);
53         socket.close();
54
55         IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("192.168.1.192", 5959, 5005,false,false);
56         IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
57
58         Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
59         zigSet.add(zigAddrLong);
60         IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
61
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);
66         
67         ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock();
68         sen.registerCallback(zTest);
69
70         System.out.println("About to init");
71         sen.init();
72
73         // ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock();
74         // sen.registerCallback(zTest);
75
76
77         System.out.println("Loop Begin");
78         while (true) {
79
80         }
81     }
82
83 }