private final int TIMEOUT_FOR_RESEND_MSEC = 900;
private IoTZigbee zigConnection = null;
-
- private int status = 0;
private boolean didClose; // make sure that the clean up was done correctly
- //private boolean detectStatus = false;
+ private boolean detectStatus = false;
- //private int detectedValue = 0;
+ private int detectedValue = 0;
private Date timestampOfLastDetecting = null;
private AtomicBoolean didAlreadyClose = new AtomicBoolean(true);
private AtomicBoolean didAlreadyInit = new AtomicBoolean(false);
private AtomicBoolean didWriteAttrb = new AtomicBoolean(false);
- //private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
+ private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
private AtomicBoolean didBind = new AtomicBoolean(false);
private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); //made by Jiawei
static Semaphore gettingLatestDataMutex = new Semaphore(1);
}
// made by Jiawei
- public int getStatus() {
+ //public int getStatus() {
+ public int getValue() {
int tmp = 0;
try {
gettingLatestDataMutex.acquire();
- tmp = status;
+ tmp = detectedValue;
} catch (Exception e) {
e.printStackTrace();
return tmp;
}
+ public boolean isActiveValue() {
+
+ int tmp = getValue();
+ if (tmp == 1)
+ detectStatus = true; // Door is locked
+ else
+ detectStatus = false; // Door is not locked/not fully locked
+ return detectStatus;
+ }
+
public void close() {
if (didAlreadyClose.compareAndSet(false, true) == false) {
try {
gettingLatestDataMutex.acquire();
- status = value;
+ detectedValue = value;
timestampOfLastDetecting = new Date();
} catch (Exception e) {
e.printStackTrace();
try {
for (SmartthingsSensorCallback cb : callbackList) {
- cb.newReadingAvailable(this);
+ cb.newReadingAvailable(this.getValue(), this.isActiveValue());
}
} catch (Exception e) {
e.printStackTrace();
public class ZigbeeTest_doorlock implements SmartthingsSensorCallback {
public final int SOCKET_SEND_BUFFER_SIZE = 1024;
public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
- private static final String MY_IP_ADDRESS = "127.0.0.1";
+ private static final String MY_IP_ADDRESS = "192.168.1.198";
public static final String DEVIDE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor
- public void newReadingAvailable(SmartthingsSensor _sensor) {
- //public void newReadingAvailable(SmartthingsSensor _sensor) throws RemoteException {
- System.out.println("New Message!!!!");
- int status = ((DoorlockSensor)_sensor).getStatus();
- switch (status) {
- case 0:
- System.out.println("Not fully locked");
- break;
- case 1:
- System.out.println("Locked");
- break;
- case 2:
- System.out.println("Unlocked");
- break;
- default:
- System.out.println("Unknown value: " + status);
- break;
- }
- }
+ //public void newReadingAvailable(SmartthingsSensor _sensor) {
+ public void newReadingAvailable(int _value, boolean _activeValue) {
+
+ System.out.println("New Message!!!!");
+ //int status = ((DoorlockSensor)_sensor).getStatus();
+ int status = _value;
+ switch (status) {
+ case 0:
+ System.out.println("Not fully locked");
+ break;
+ case 1:
+ System.out.println("Locked");
+ break;
+ case 2:
+ System.out.println("Unlocked");
+ break;
+ default:
+ System.out.println("Unknown value: " + status);
+ break;
+ }
+ }
public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
socket.setReuseAddress(true);
socket.close();
- IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("127.0.0.1", 5959, 5005,false,false);
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5959, 5005,false,false);
IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
--- /dev/null
+//package iotcode.DoorlockSensor;
+
+// Standard Java Packages
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.Semaphore;
+
+// Checker annotations
+//import iotchecker.qual.*;
+import iotcode.annotation.*;
+
+// IoT Packages
+import iotruntime.slave.*;
+import iotcode.interfaces.*;
+import iotruntime.zigbee.*;
+
+/** Class Smartthings sensor driver for Smartthings sensor devices.
+ *
+ * @author Changwoo Lee, Rahmadi Trimananda <rtrimana @ uci.edu>
+ * @version 1.0
+ * @since 2016-12-01
+ */
+public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor {
+
+ private final int TIMEOUT_FOR_RESEND_MSEC = 900;
+
+ private IoTZigbee zigConnection = null;
+ private boolean didClose; // make sure that the clean up was done correctly
+ private boolean detectStatus = false;
+
+ private int detectedValue = 0;
+ private Date timestampOfLastDetecting = null;
+
+ private AtomicBoolean didAlreadyClose = new AtomicBoolean(true);
+ private AtomicBoolean didAlreadyInit = new AtomicBoolean(false);
+ private AtomicBoolean didWriteAttrb = new AtomicBoolean(false);
+ private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
+ private AtomicBoolean didBind = new AtomicBoolean(false);
+ private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); //made by Jiawei
+ static Semaphore gettingLatestDataMutex = new Semaphore(1);
+
+ private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > ();
+
+ private int sensorId = 0;
+
+ @config private IoTSet<IoTDeviceAddress> DoorlockSensorUdpAddress; //
+ @config private IoTSet<IoTZigbeeAddress> DoorlockSensorZigbeeAddress;//
+
+ public DoorlockSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
+ DoorlockSensorUdpAddress = dSet;
+ DoorlockSensorZigbeeAddress = zigSet;
+ }
+
+ public DoorlockSensor() {
+ }
+
+ public void init() {
+
+ if (didAlreadyInit.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyClose.set(false);
+
+ try {
+ Iterator itrUdp = DoorlockSensorUdpAddress.iterator();
+ Iterator itrZig = DoorlockSensorZigbeeAddress.iterator();
+
+ zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next());
+
+ // DEBUG
+ System.out.println("DEBUG: Allocate iterators to print out addresses!");
+ Iterator itrDebugUdp = DoorlockSensorUdpAddress.iterator();
+ IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next();
+ System.out.println("IP address: " + iotaddDebug.getCompleteAddress());
+ System.out.println("Source port: " + iotaddDebug.getSourcePortNumber());
+ System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber());
+
+ Iterator itrDebugZig = DoorlockSensorZigbeeAddress.iterator();
+ IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next();
+ System.out.println("Zigbee address: " + iotzbaddDebug.getAddress());
+
+ zigConnection.registerCallback(this);
+ System.out.println("Register callback!");
+ zigConnection.init();
+ System.out.println("Initialized!");
+
+
+
+ //made by changwoo
+ sleep(10);
+
+ // System.out.println("BroadcastingRouteRecordRequest ");
+ // zigConnection.sendBroadcastingRouteRecordRequest(0x0001);
+ // sleep(6);
+
+ System.out.println("Sending Management Permit Joining Request");
+ // for(int z=0; z<3; z++){
+ zigConnection.sendManagementPermitJoiningRequest(0x0002, 0x0036, 0x00);
+ sleep(0);
+ // }
+
+
+ while(!didBind.get()){
+ System.out.println("Sending Bind Request");
+ zigConnection.sendBindRequest(0x0003, 0x0101, 0x02);
+ sleep(0);
+ }
+
+ while(!didDoorLockConfigureReporting.get()){
+ System.out.println("Sending Door Lock: Configure Reporting");
+ zigConnection.sendConfigureReportingCommand(0x0004, 0x0101, 0x0104, 0x01, 0x02, 0x0000, 0x30, 0x0000, 0x100E, null);
+ sleep(0);
+ }
+
+ while(true){
+ Scanner in = new Scanner(System.in);
+ System.out.println("\nUnlock door: 0");
+ System.out.println("Lock door: 1");
+ System.out.println("Read status: 2 (or anything else)");
+ String str = in.next();
+ if(str.equals("1")) {
+ System.out.println("the doorlock sensor is locking");
+ zigConnection.sendLockOrUnlockDoorRequest(0x0005, 0x0101, 0x0104, 0x02, 0);
+ sleep(0);
+ }else if(str.equals("0")){
+ System.out.println("the doorlock sensor is unlocking");
+ zigConnection.sendLockOrUnlockDoorRequest(0x0005, 0x0101, 0x0104, 0x02, 1);
+ sleep(0);
+ }else{
+ System.out.println("Let's see the doorlock sensor's status currently");
+ zigConnection.sendReadDoorStatusRequest(0x0005, 0x0101, 0x0104, 0x02, 0x10, 0x00, 0x0000);
+ sleep(0);
+ }
+ }
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ //made by changwoo
+ private void sleep(int multipleTime){
+ if(multipleTime<=0){
+ multipleTime=1;
+ }
+ try{
+ Thread.sleep(TIMEOUT_FOR_RESEND_MSEC*multipleTime);
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ // made by Jiawei
+ //public int getStatus() {
+ public int getValue() {
+ int tmp = 0;
+
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = detectedValue;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+
+ return tmp;
+ }
+
+ public boolean isActiveValue() {
+
+ int tmp = getValue();
+ if (tmp == 1)
+ detectStatus = true; // Door is locked
+ else
+ detectStatus = false; // Door is not locked/not fully locked
+ return detectStatus;
+ }
+
+ public void close() {
+
+ if (didAlreadyClose.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyInit.set(false);
+
+
+ try {
+ zigConnection.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void Finalize() {
+ if (!didClose) {
+ close();
+ }
+ }
+
+ public void setId(int id) {
+
+ sensorId = id;
+
+ }
+
+ public int getId() {
+
+ return sensorId;
+
+ }
+
+
+ public long getTimestampOfLastReading() {
+
+ Date tmp = null;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = (Date)timestampOfLastDetecting.clone();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+ long retLong = tmp.getTime();
+
+ return retLong;
+ }
+
+ public void newMessageAvailable(IoTZigbeeMessage _zm) {
+
+ //made by yuting
+ if (_zm instanceof IoTZigbeeMessageZdoBindResponse) {
+ IoTZigbeeMessageZdoBindResponse message = (IoTZigbeeMessageZdoBindResponse)_zm;
+ if (message.getSucceeded()) {
+ didBind.set(true);
+ }
+ }
+ else if (_zm instanceof IoTZigbeeMessageZclConfigureReportingResponse){
+ IoTZigbeeMessageZclConfigureReportingResponse message = (IoTZigbeeMessageZclConfigureReportingResponse)_zm;
+ if (message.getAllSuccess()) {
+ didDoorLockConfigureReporting.set(true);
+ }
+ }
+ else if (_zm instanceof IoTZigbeeMessageZclReadAttributesResponse) {
+ IoTZigbeeMessageZclReadAttributesResponse message = (IoTZigbeeMessageZclReadAttributesResponse)_zm;
+ List <IoTZigbeeMessageZclReadAttributesResponse.Attribute> attrList = message.getAttributes();
+
+ if (attrList.size() == 1) {
+ if(attrList.get(0).getAttributeId() == 0) {
+ byte[] data = attrList.get(0).getData();
+ int value = data[0];
+
+ try {
+ gettingLatestDataMutex.acquire();
+ detectedValue = value;
+ timestampOfLastDetecting = new Date();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+
+ try {
+ for (SmartthingsSensorCallback cb : callbackList) {
+ cb.newReadingAvailable(this.getValue(), this.isActiveValue());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ //public void registerCallback(SmartthingsSensorSmartCallback _callbackTo) {
+ public void registerCallback(SmartthingsSensorCallback _callbackTo) {
+ callbackList.add(_callbackTo);
+ }
+}
socket.send(sendPacket);
}
+ //made by Jiawei
+ public void sendLockOrUnlockDoorRequest(int packetId, int clusterId, int profileId, int deviceEndpoint, int value) throws IOException {
+ String message = "type: zcl_lock_or_unlock_door_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "value: " + String.format("%01x", value) + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by Jiawei
+ public void sendReadDoorStatusRequest(int packetId, int clusterId, int profileId, int deviceEndpoint, int framecontrol, int commandframe, int attribute_id) throws IOException {
+ String message = "type: zcl_read_door_status_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "framecontrol: " + String.format("%02x", framecontrol) + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ message += "commandframe: " + String.format("%02x", commandframe) + "\n";
+ message += "attribute_id: " + String.format("%04x", attribute_id) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
//made by changwoo
public void sendBroadcastingRouteRecordRequest(int packetId) throws IOException {
String message = "type: zdo_broadcast_route_record_request\n";
socket.send(sendPacket);
}
- public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int deviceEndpoint, int attributeId, int dataType, int minReportingInterval, int maxReportingInterval, byte[] reportableChange) throws IOException {
+ public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int src_endpoint, int dest_endpoint, int attributeId, int dataType, int minReportingInterval, int maxReportingInterval, byte[] reportableChange) throws IOException {
String message = "type: zcl_configure_reporting\n";
message += "packet_id: " + String.format("%04x", packetId) + "\n";
message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
message += "profile_id: " + String.format("%04x", profileId) + "\n";
- message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ message += "src_endpoint: " + String.format("%02x", src_endpoint) + "\n";
+ message += "device_endpoint: " + String.format("%02x", dest_endpoint) + "\n";
message += "attribute_id: " + String.format("%04x", attributeId) + "\n";
message += "data_type: " + String.format("%02x", dataType) + "\n";
message += "min_reporting_interval: " + String.format("%04x", minReportingInterval) + "\n";
socket.send(sendPacket);
}
+ public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int dest_endpoint, int attributeId, int dataType, int minReportingInterval, int maxReportingInterval, byte[] reportableChange) throws IOException {
+ sendConfigureReportingCommand(packetId, clusterId, profileId, 0x00, dest_endpoint, attributeId, dataType, minReportingInterval, maxReportingInterval, reportableChange);
+ }
+
public void registerCallback(IoTZigbeeCallback callbackTo) {
callbackList.add(callbackTo);
String message = "type: send_address\n";
message += "packet_id: 00\n";
message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ System.out.println(message);
DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
socket.send(sendPacket);
}
if(packetData.get("attributes").equals("success")) successOrFail=true;
callbackMessage = new IoTZigbeeMessageZclZoneStatusChangeNotification(packetId, clusterId, profileId, status, successOrFail);
+ // made by yuting
+ }else if (packetData.get("type").equals("zcl_change_switch_response")){
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ int clusterId = Integer.parseInt(packetData.get("cluster_id"), 16);
+ int profileId = Integer.parseInt(packetData.get("profile_id"), 16);
+ int status = Integer.parseInt(packetData.get("status"), 10);
+ boolean successOrFail = false;
+ if(packetData.get("attributes").equals("success")) successOrFail=true;
+ callbackMessage = new IoTZigbeeMessageZclChangeSwitchResponse(packetId, clusterId, profileId, status, successOrFail);
+
//made by changwoo
} else if (packetData.get("type").equals("zcl_write_attributes_response")) {
--- /dev/null
+/** Zigbee Message Zcl Change Switch Response
+ *
+ * @author Yuting Tan <ytan5 @ uci.edu>
+ * @version 1.0
+ * @since 2017-2-28
+ */
+public class IoTZigbeeMessageZclChangeSwitchResponse extends IoTZigbeeMessage {
+
+ private boolean SuccessOrFail=false;
+ private int clusterId;
+ private int profileId;
+ private int status;
+
+ public IoTZigbeeMessageZclChangeSwitchResponse(int _packetId, int _clusterId, int _profileId, int _status, boolean _SuccessOrFail){
+ super(_packetId);
+
+ clusterId = _clusterId;
+ profileId = _profileId;
+ status = _status;
+ SuccessOrFail = _SuccessOrFail;
+ }
+ public boolean getSuccessOrFail(){
+ return SuccessOrFail;
+ }
+
+ public int getClusterId() {
+ return clusterId;
+ }
+
+ public int getProfileId() {
+ return profileId;
+ }
+
+ public int getStatus(){
+ return status;
+ }
+}
private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > ();
- private int sensorId = 0;
-
@config private IoTSet<IoTDeviceAddress> devUdpAddress;
@config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
//made by changwoo
sleep(10);
- System.out.println("Sending Management Permit Joining Request");
+ //System.out.println("Sending Management Permit Joining Request");
for(int z=0; z<3; z++){
zigConnection.sendManagementPermitJoiningRequest(0x0001, 0x0036, 0x00);
+ System.out.println("Sending Management Permit Joining Request");
sleep(0);
}
}
}
- public void setId(int id) {
-
- sensorId = id;
-
- }
-
- public int getId() {
-
- return sensorId;
-
- }
-
public int getValue() {
int tmp = 0;
gettingLatestDataMutex.release();
try {
for (SmartthingsSensorCallback cb : callbackList) {
- cb.newReadingAvailable(this.getId(), this.getValue(), this.isActiveValue());
+ cb.newReadingAvailable(this.getValue(), this.isActiveValue());
}
} catch (Exception e) {
e.printStackTrace();
private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > ();
- private int sensorId = 0;
-
@config private IoTSet<IoTDeviceAddress> devUdpAddress;
@config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
}
}
- public void setId(int id) {
-
- sensorId = id;
-
- }
-
- public int getId() {
-
- return sensorId;
-
- }
-
public int getValue() {
int tmp = 0;
gettingLatestDataMutex.release();
try {
for (SmartthingsSensorCallback cb : callbackList) {
- cb.newReadingAvailable(this.getId(), this.getValue(), this.isActiveValue());
+ cb.newReadingAvailable(this.getValue(), this.isActiveValue());
}
} catch (Exception e) {
e.printStackTrace();
*/
public void init() throws RemoteException;
- public void setId(int id);
-
- public int getId();
/** Register an object to retrieve callbacks when new sensor reading is available
*
public interface SmartthingsSensorCallback {
- public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue);
+ //public void newReadingAvailable(@NonLocalRemote SmartthingsSensor _sensor) throws RemoteException;
+ public void newReadingAvailable(int _value, boolean _activeValue);
}
while (!didBind.get()) {
zigConnection.sendBindRequest(0x0001, 0x0405, 0x01);
+ System.out.println("Sending bind request!");
try {
Thread.sleep(TIMEOUT_FOR_RESEND_MSEC);
} catch (Exception e) {
@config private IoTSet<IoTDeviceAddress> devUdpAddress;
@config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
- private int sensorId = 0;
-
public WaterLeakSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
devUdpAddress = dSet;
devZigbeeAddress = zigSet;
}
}
- public void setId(int id) {
-
- sensorId = id;
-
- }
-
- public int getId() {
-
- return sensorId;
-
- }
-
public int getValue() {
int tmp = 0;
gettingLatestDataMutex.release();
try {
for (SmartthingsSensorCallback cb : callbackList) {
- cb.newReadingAvailable(this.getId(), this.getValue(), this.isActiveValue());
+ cb.newReadingAvailable(this.getValue(), this.isActiveValue());
}
} catch (Exception e) {
e.printStackTrace();
public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
String message = "type: policy_set\n";
- //message += "ip_address: " + "192.168.1.1\n"; // local ip address
- message += "ip_address: " + "192.168.2.108\n"; // local ip address
+ message += "ip_address: " + "192.168.2.108\n"; // local ip address
//message += "port: " + "5959\n"; // port number
- message += "port: " + "5557\n"; // port number
+ message += "port: " + "5557\n"; // port number
message += "device_address_long: " + "000d6f0003ebf2ee" + "\n";
//DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("128.195.204.110"), 5005); // address and port of the gateway
- DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005); // address and port of the gateway
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.192"), 5005); // address and port of the gateway
DatagramSocket socket = new DatagramSocket();
socket.setSendBufferSize(4096);
//IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("128.195.204.110", 5557, 5005,false,false);
- IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5557, 5005,false,false);
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.192", 5557, 5005,false,false);
IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress("000d6f0003ebf2ee");
Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
System.out.println("About to init");
sen.init();
-
+ System.out.println("Passed init!");
ZigbeeTest zTest = new ZigbeeTest();
-
+ System.out.println("ZigbeeTest created!");
sen.registerCallback(zTest);
--- /dev/null
+import java.util.Map;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+import iotruntime.*;
+import iotruntime.zigbee.*;
+
+import iotcode.interfaces.*;
+import java.rmi.RemoteException;
+
+//public class ZigbeeTest_doorlock implements IoTZigbeeCallback {
+public class ZigbeeTest_doorlock implements SmartthingsSensorCallback {
+ public final int SOCKET_SEND_BUFFER_SIZE = 1024;
+ public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
+ private static final String MY_IP_ADDRESS = "192.168.1.198";
+ public static final String DEVIDE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor
+
+ //public void newReadingAvailable(SmartthingsSensor _sensor) {
+ public void newReadingAvailable(int _value, boolean _activeValue) {
+
+ System.out.println("New Message!!!!");
+ //int status = ((DoorlockSensor)_sensor).getStatus();
+ int status = _value;
+ switch (status) {
+ case 0:
+ System.out.println("Not fully locked");
+ break;
+ case 1:
+ System.out.println("Locked");
+ break;
+ case 2:
+ System.out.println("Unlocked");
+ break;
+ default:
+ System.out.println("Unknown value: " + status);
+ break;
+ }
+ }
+
+ public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
+
+ String message = "type: policy_set\n";
+ message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
+ message += "port: " + "5959\n"; // port number
+ message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address
+ DatagramSocket socket = new DatagramSocket(12345/*test number*/);
+ socket.setSendBufferSize(4096);
+ socket.setReceiveBufferSize(4096);
+ socket.send(sendPacket);
+ socket.setReuseAddress(true);
+ socket.close();
+
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5959, 5005,false,false);
+ IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
+
+ Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
+ zigSet.add(zigAddrLong);
+ IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
+
+ Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
+ devSet.add(zigUdpAddr);
+ IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
+ DoorlockSensor sen = new DoorlockSensor(devIotSet, zigIotSet);
+
+ ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock();
+ sen.registerCallback(zTest);
+
+ System.out.println("About to init");
+ sen.init();
+
+ // ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock();
+ // sen.registerCallback(zTest);
+
+
+ System.out.println("Loop Begin");
+ while (true) {
+
+ }
+ }
+
+}
public class ZigbeeTest_motion implements SmartthingsSensorCallback {
public final int SOCKET_SEND_BUFFER_SIZE = 1024;
public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
- private static final String MY_IP_ADDRESS = "192.168.2.108";
- public static final String DEVIDE_MAC_ADDRESS = "000d6f00057c92a7"; //motion
+ private static final String MY_IP_ADDRESS = "192.168.1.198";
+ public static final String DEVIDE_MAC_ADDRESS = "000d6f000bbd5398"; //motion
//000d6f000bbd5398
//000d6f00057c92a7
- public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
+ public void newReadingAvailable(int _value, boolean _activeValue) {
System.out.println("New Message!!!!");
System.out.println("motion : "+ _value);
System.out.println("active? : "+ _activeValue);
message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
message += "port: " + "5956\n"; // port number
message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
- DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005); // address and port of the gateway which means Raspberry PI's IP address
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address
//DatagramSocket socket = new DatagramSocket(11222);
- DatagramSocket socket = new DatagramSocket(12345);
+ DatagramSocket socket = new DatagramSocket(12345);
socket.setSendBufferSize(4096);
socket.setReceiveBufferSize(4096);
socket.send(sendPacket);
- socket.setReuseAddress(true);
- socket.close();
+ socket.setReuseAddress(true);
+ socket.close();
- IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false);
+ //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false);
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5956, 5005,false,false);
IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
public class ZigbeeTest_multipurpose implements SmartthingsSensorCallback {
public final int SOCKET_SEND_BUFFER_SIZE = 1024;
public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
- private static final String MY_IP_ADDRESS = "192.168.2.108";
+ private static final String MY_IP_ADDRESS = "192.168.1.198";
public static final String DEVIDE_MAC_ADDRESS = "000d6f000bbd3413"; //Multipurpose sensor
- public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
+ public void newReadingAvailable(int _value, boolean _activeValue) {
System.out.println("New Message!!!!");
System.out.println("multipurpose : "+ _value);
System.out.println("active? : "+ _activeValue);
String message = "type: policy_set\n";
message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
message += "port: " + "5957\n"; // port number
+ //message += "port: " + "5956\n"; // port number
message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
- DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005);
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005);
//DatagramSocket socket = new DatagramSocket(11111);
- DatagramSocket socket = new DatagramSocket(12345);
+ DatagramSocket socket = new DatagramSocket(12345);
socket.setSendBufferSize(4096);
socket.setReceiveBufferSize(4096);
socket.send(sendPacket);
- socket.setReuseAddress(true);
- socket.close();
+ socket.setReuseAddress(true);
+ socket.close();
- IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5957, 5005,false,false);
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5957, 5005,false,false);
+ //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false);
IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
public class ZigbeeTest_waterleak implements SmartthingsSensorCallback {
public final int SOCKET_SEND_BUFFER_SIZE = 1024;
public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
- private static final String MY_IP_ADDRESS = "192.168.2.108";
+ private static final String MY_IP_ADDRESS = "192.168.1.198";
private static final int PORT_NUMBER = 5959;
public static final String DEVIDE_MAC_ADDRESS = "000d6f000ada75e3"; //water leak
- public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) {
+ public void newReadingAvailable(int _value, boolean _activeValue) {
System.out.println("New Message!!!!");
System.out.println("water leak : "+ _value);
System.out.println("active? : "+ _activeValue);
message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
message += "port: " + PORT_NUMBER + "\n"; // port number
message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
- DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005); // address and port of the gateway which means Raspberry PI's IP address
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address
//DatagramSocket socket = new DatagramSocket(22222);
- DatagramSocket socket = new DatagramSocket(12345);
+ DatagramSocket socket = new DatagramSocket(12345);
socket.setSendBufferSize(4096);
socket.setReceiveBufferSize(4096);
socket.send(sendPacket);
- socket.setReuseAddress(true);
- socket.close();
+ socket.setReuseAddress(true);
+ socket.close();
- IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false);
+ //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false);
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", PORT_NUMBER, 5005,false,false);
IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
--- /dev/null
+java -cp ./../iotjava:./../../../bin:. ZigbeeTest_doorlock