7 import iotruntime.zigbee.*;
9 //import iotcode.interfaces.*;
10 import java.rmi.RemoteException;
12 public class ZigbeeTest implements MoistureSensorSmartCallback {
14 public final int SOCKET_SEND_BUFFER_SIZE = 1024;
15 public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
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);
33 public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
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
44 DatagramSocket socket = new DatagramSocket();
45 socket.setSendBufferSize(4096);
46 socket.setReceiveBufferSize(4096);
48 socket.send(sendPacket);
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");
57 Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
58 zigSet.add(zigAddrLong);
59 IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
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);
66 System.out.println("About to init");
69 ZigbeeTest zTest = new ZigbeeTest();
71 sen.registerCallback(zTest);
74 System.out.println("Loop Begin");