6 public class ZigbeeTestMoisture implements MoistureSensorSmartCallback {
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;
16 public ZigbeeTestMoisture() {
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);
27 public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException {
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
35 DatagramSocket socket = new DatagramSocket(12345);
36 socket.setSendBufferSize(4096);
37 socket.setReceiveBufferSize(4096);
38 socket.send(sendPacket);
39 socket.setReuseAddress(true);
42 IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false);
43 IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS);
45 Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
46 zigSet.add(zigAddrLong);
47 IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
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);
54 System.out.println("About to init");
56 System.out.println("Passed init!");
57 ZigbeeTestMoisture zTest = new ZigbeeTestMoisture();
58 sen.registerCallback(zTest);
60 System.out.println("Loop Begin");