Testing Smartthings sensors with some adjustments for 4th benchmark
[iot2.git] / benchmarks / other / ZigbeeTest / ZigbeeTest.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 implements MoistureSensorSmartCallback {
13
14     public final int SOCKET_SEND_BUFFER_SIZE = 1024;
15     public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
16
17
18     public ZigbeeTest() {
19     }
20
21
22     public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) {
23         System.out.println("New Message!!!!");
24         System.out.println(moisture);
25         System.out.println("Reading time: " + timeStampOfLastReading);
26     }
27
28
29
30
31
32
33     public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
34
35         String message = "type: policy_set\n";
36         //message += "ip_address: " + "192.168.1.1\n"; // local ip address
37                 message += "ip_address: " + "192.168.2.108\n"; // local ip address
38         //message += "port: " + "5959\n";  // port number
39                 message += "port: " + "5557\n";  // port number
40         message += "device_address_long: " + "000d6f0003ebf2ee" + "\n";
41         //DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("128.195.204.110"), 5005); // address and port of the gateway
42                 DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005); // address and port of the gateway
43
44         DatagramSocket socket = new DatagramSocket();
45         socket.setSendBufferSize(4096);
46         socket.setReceiveBufferSize(4096);
47
48         socket.send(sendPacket);
49
50
51
52
53         //IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("128.195.204.110", 5557, 5005,false,false);
54                 IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("192.168.2.227", 5557, 5005,false,false);
55         IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress("000d6f0003ebf2ee");
56
57         Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
58         zigSet.add(zigAddrLong);
59         IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
60
61         Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
62         devSet.add(zigUdpAddr);
63         IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
64         SpruceSensor sen = new SpruceSensor(devIotSet, zigIotSet);
65         
66         System.out.println("About to init");
67         sen.init();
68
69         ZigbeeTest zTest = new ZigbeeTest();
70
71         sen.registerCallback(zTest);
72
73
74         System.out.println("Loop Begin");
75         while (true) {
76
77         }
78     }
79 }