Changing LifxLightBulb config to default to running Lifxtest application, i.e. using...
[iot2.git] / benchmarks / other / ZigbeeTest / ZigbeeTest_waterleak.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_waterleak 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     private static final int PORT_NUMBER = 5959;
17     public static final String DEVIDE_MAC_ADDRESS = "000d6f000ada75e3"; //water leak
18
19     public void newReadingAvailable(int _value, boolean _activeValue) {
20         System.out.println("New Message!!!!");
21         System.out.println("water leak : "+ _value);
22         System.out.println("active? : "+ _activeValue);
23     }
24
25     public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
26
27         String message = "type: policy_set\n";
28         message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
29         message += "port: " + PORT_NUMBER + "\n";  // port number
30         message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
31         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
32         //DatagramSocket socket = new DatagramSocket(22222);
33         DatagramSocket socket = new DatagramSocket(12345);
34         socket.setSendBufferSize(4096);
35         socket.setReceiveBufferSize(4096);
36         socket.send(sendPacket);
37         socket.setReuseAddress(true);
38         socket.close();
39
40         //IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false);
41         IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("192.168.1.192", PORT_NUMBER, 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         WaterLeakSensor sen = new WaterLeakSensor(devIotSet, zigIotSet);
52         
53         System.out.println("About to init");
54         sen.init();
55
56         ZigbeeTest_waterleak zTest = new ZigbeeTest_waterleak();
57                 sen.registerCallback(zTest);
58
59         System.out.println("Loop Begin");
60         while (true) {
61
62         }
63     }
64 }