7 import iotruntime.zigbee.*;
9 import iotcode.interfaces.*;
10 import java.rmi.RemoteException;
12 //public class ZigbeeTest_outlet implements IoTZigbeeCallback {
13 public class ZigbeeTest_outlet implements SmartthingsSensorCallback {
14 public final int SOCKET_SEND_BUFFER_SIZE = 1024;
15 public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
16 private static final String MY_IP_ADDRESS = "127.0.0.1";
17 public static final String DEVIDE_MAC_ADDRESS = "000d6f0005782e31"; //outlet sensor
19 public void newReadingAvailable(SmartthingsSensor _sensor) {
20 //public void newReadingAvailable(SmartthingsSensor _sensor) throws RemoteException {
21 System.out.println("New Message!!!!");
22 System.out.println(((OutletSensor)_sensor).getWatts());
25 public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
27 String message = "type: policy_set\n";
28 message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
29 message += "port: " + "5959\n"; // port number
30 message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
31 DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("127.0.0.1"), 5005); // address and port of the gateway which means Raspberry PI's IP address
32 DatagramSocket socket = new DatagramSocket(12345/*test number*/);
33 socket.setSendBufferSize(4096);
34 socket.setReceiveBufferSize(4096);
35 socket.send(sendPacket);
36 socket.setReuseAddress(true);
39 IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("127.0.0.1", 5959, 5005,false,false);
40 IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
42 Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
43 zigSet.add(zigAddrLong);
44 IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
46 Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
47 devSet.add(zigUdpAddr);
48 IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
49 OutletSensor sen = new OutletSensor(devIotSet, zigIotSet);
51 System.out.println("About to init");
54 ZigbeeTest_outlet zTest = new ZigbeeTest_outlet();
55 sen.registerCallback(zTest);
59 System.out.println("Watt:");
60 System.out.println(sen.getWatts());
62 System.out.println("Loop Begin");