Adding config file for sharing.
[iot2.git] / benchmarks / other / ZigbeeTest / ZigbeeTestMoisture.java
1 import java.util.Map;
2 import java.net.*;
3 import java.io.*;
4 import java.util.*;
5
6 public class ZigbeeTestMoisture implements MoistureSensorSmartCallback {
7
8     public final int SOCKET_SEND_BUFFER_SIZE = 1024;
9     public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
10     private static final String MY_IP_ADDRESS = "192.168.1.198";
11     private static final String DEVICE_MAC_ADDRESS = "000d6f0003ebf2ee"; //doorlock sensor
12     private static final String GATEWAY = "192.168.1.192";
13     private static final int LOCAL_COMM_SOCKET = 5557;
14
15
16     public ZigbeeTestMoisture() {
17     }
18
19
20     public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) {
21         System.out.println("New Message!!!!");
22         System.out.println(moisture);
23         System.out.println("Reading time: " + timeStampOfLastReading);
24     }
25
26
27     public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException {
28
29         String message = "type: policy_set\n";
30             message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
31             message += "port: " + LOCAL_COMM_SOCKET + "\n";  // port number
32         message += "device_address_long: " + DEVICE_MAC_ADDRESS + "\n";
33         DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(GATEWAY), 5005); // address and port of the gateway
34
35         DatagramSocket socket = new DatagramSocket(12345);
36         socket.setSendBufferSize(4096);
37         socket.setReceiveBufferSize(4096);
38         socket.send(sendPacket);
39         socket.setReuseAddress(true);
40         socket.close();
41
42         IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false);
43         IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_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         SpruceSensor sen = new SpruceSensor(devIotSet, zigIotSet);
53         
54         System.out.println("About to init");
55         sen.init();
56         System.out.println("Passed init!");
57         ZigbeeTestMoisture zTest = new ZigbeeTestMoisture();
58         sen.registerCallback(zTest);
59
60         System.out.println("Loop Begin");
61         while (true) {
62
63         }
64     }
65 }