|
@@ -38,6 +38,7 @@ import org.iotivity.bridge.homeserver.handler.client.ObserveResponseHandler;
|
|
import org.iotivity.bridge.homeserver.handler.client.PostResponseHandler;
|
|
import org.iotivity.bridge.homeserver.handler.client.PostResponseHandler;
|
|
import org.iotivity.bridge.homeserver.handler.client.PutResponseHandler;
|
|
import org.iotivity.bridge.homeserver.handler.client.PutResponseHandler;
|
|
import org.iotivity.bridge.homeserver.model.Bridge;
|
|
import org.iotivity.bridge.homeserver.model.Bridge;
|
|
|
|
+import org.iotivity.bridge.homeserver.model.OCFDevice;
|
|
import org.iotivity.bridge.homeserver.model.VirtualOCFDevice;
|
|
import org.iotivity.bridge.homeserver.model.VirtualOCFDevice;
|
|
import org.iotivity.bridge.homeserver.utils.Utils;
|
|
import org.iotivity.bridge.homeserver.utils.Utils;
|
|
import org.iotivity.oc.OcCborEncoder;
|
|
import org.iotivity.oc.OcCborEncoder;
|
|
@@ -326,42 +327,44 @@ public class BridgeService extends IntentService {
|
|
JSONArray array = new JSONArray(devices);
|
|
JSONArray array = new JSONArray(devices);
|
|
|
|
|
|
for (int index = 0 ; index < array.length(); index++) {
|
|
for (int index = 0 ; index < array.length(); index++) {
|
|
- JSONObject obj = array.getJSONObject(index);
|
|
|
|
- Iterator<String> it = obj.keys();
|
|
|
|
|
|
+ JSONObject devs = array.getJSONObject(index);
|
|
|
|
+ Iterator<String> it_devs = devs.keys();
|
|
String n = null, sn = null, rt = null, state = null ;
|
|
String n = null, sn = null, rt = null, state = null ;
|
|
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- String key = it.next();
|
|
|
|
- Object value = obj.get(key);
|
|
|
|
|
|
+ while (it_devs.hasNext()) {
|
|
|
|
+ String key = it_devs.next();
|
|
|
|
+ Object value = devs.get(key);
|
|
if (key.equals("n") && value instanceof String) {
|
|
if (key.equals("n") && value instanceof String) {
|
|
n = (String)value;
|
|
n = (String)value;
|
|
- Log.d(TAG, "Light Control : n = " + n);
|
|
|
|
|
|
+ Log.d(TAG, "Light Device : n = " + n);
|
|
} else if (key.equals("sn") && value instanceof String) {
|
|
} else if (key.equals("sn") && value instanceof String) {
|
|
sn = (String)value;
|
|
sn = (String)value;
|
|
- Log.d(TAG, "Light Control : sn = " + sn);
|
|
|
|
|
|
+ Log.d(TAG, "Light Device : sn = " + sn);
|
|
} else if (key.equals("rt") && value instanceof JSONArray) {
|
|
} else if (key.equals("rt") && value instanceof JSONArray) {
|
|
- rt = ((JSONArray)value).toString();
|
|
|
|
- Log.d(TAG, "Light Control : rt = " + rt);
|
|
|
|
|
|
+ Log.d(TAG, "Light Device : rt(org) = " + ((JSONArray)value).toString());
|
|
|
|
+ rt = ((JSONArray)value).getString(0);
|
|
|
|
+ Log.d(TAG, "Light Device : rt = " + rt);
|
|
} else if (key.equals("state") && value instanceof String) {
|
|
} else if (key.equals("state") && value instanceof String) {
|
|
state = (String)value;
|
|
state = (String)value;
|
|
- Log.d(TAG, "Light Control : state = " + state);
|
|
|
|
|
|
+ Log.d(TAG, "Light Device : state = " + state);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// add device on ocf platform
|
|
// add device on ocf platform
|
|
- VirtualOCFDevice device = bridgeServer.addVirtualOCFDevice(sn, n, rt, ECO_NAME);
|
|
|
|
|
|
+ VirtualOCFDevice device = bridgeServer.addVirtualOCFDevice(n, sn, rt, ECO_NAME);
|
|
|
|
+ if(device==null) continue;
|
|
|
|
|
|
String resources = lightControlBinder.retrieveAllResources(sn);
|
|
String resources = lightControlBinder.retrieveAllResources(sn);
|
|
Log.d(TAG, "Light Control retrieveAllResources() : " + resources);
|
|
Log.d(TAG, "Light Control retrieveAllResources() : " + resources);
|
|
if(resources!=null) {
|
|
if(resources!=null) {
|
|
- JSONArray aArr = new JSONArray(resources);
|
|
|
|
- for (int loop = 0 ; loop < aArr.length(); loop++) {
|
|
|
|
- JSONObject ob = aArr.getJSONObject(loop);
|
|
|
|
- Iterator<String> keys = ob.keys();
|
|
|
|
|
|
+ JSONArray resArr = new JSONArray(resources);
|
|
|
|
+ for (int loop = 0 ; loop < resArr.length(); loop++) {
|
|
|
|
+ JSONObject res = resArr.getJSONObject(loop);
|
|
|
|
+ Iterator<String> rKeys = res.keys();
|
|
String rName = null, rUri = null, rRT = null, rIF = null ;
|
|
String rName = null, rUri = null, rRT = null, rIF = null ;
|
|
|
|
|
|
- while (keys.hasNext()) {
|
|
|
|
- String rKey = keys.next();
|
|
|
|
- Object rValue = ob.get(rKey);
|
|
|
|
|
|
+ while (rKeys.hasNext()) {
|
|
|
|
+ String rKey = rKeys.next();
|
|
|
|
+ Object rValue = res.get(rKey);
|
|
if (rKey.equals("n") && rValue instanceof String) {
|
|
if (rKey.equals("n") && rValue instanceof String) {
|
|
rName = (String)rValue;
|
|
rName = (String)rValue;
|
|
Log.d(TAG, "Light Resource : n = " + rName);
|
|
Log.d(TAG, "Light Resource : n = " + rName);
|
|
@@ -369,7 +372,8 @@ public class BridgeService extends IntentService {
|
|
rUri = (String)rValue;
|
|
rUri = (String)rValue;
|
|
Log.d(TAG, "Light Resource : uri = " + rUri);
|
|
Log.d(TAG, "Light Resource : uri = " + rUri);
|
|
} else if (rKey.equals("rt") && rValue instanceof JSONArray) {
|
|
} else if (rKey.equals("rt") && rValue instanceof JSONArray) {
|
|
- rRT = ((JSONArray)rValue).toString();
|
|
|
|
|
|
+ Log.d(TAG, "Light Resource : rt(org) = " + ((JSONArray)rValue).toString());
|
|
|
|
+ rRT = ((JSONArray)rValue).getString(0);
|
|
Log.d(TAG, "Light Resource : rt = " + rRT);
|
|
Log.d(TAG, "Light Resource : rt = " + rRT);
|
|
} else if (rKey.equals("if") && rValue instanceof String) {
|
|
} else if (rKey.equals("if") && rValue instanceof String) {
|
|
rIF = (String)rValue;
|
|
rIF = (String)rValue;
|
|
@@ -378,15 +382,22 @@ public class BridgeService extends IntentService {
|
|
}
|
|
}
|
|
// add resource on the device
|
|
// add resource on the device
|
|
bridgeServer.addVirtualDeviceResource(device, rName, rUri, rRT, rIF);
|
|
bridgeServer.addVirtualDeviceResource(device, rName, rUri, rRT, rIF);
|
|
- Log.d(TAG, "Light Control doGetResourceProperties("+sn+", "+rUri+") : "+lightControlBinder.doGetResourceProperties(sn, rUri));
|
|
|
|
|
|
|
|
|
|
+ // get resource properties
|
|
|
|
+ String properites = lightControlBinder.doGetResourceProperties(sn, rUri);
|
|
|
|
+ Log.d(TAG, "Light Control doGetResourceProperties("+sn+", "+rUri+") : " + properites);
|
|
|
|
+
|
|
|
|
+ JSONObject props = new JSONObject(properites);
|
|
|
|
+ Iterator<String> pKeys = props.keys();
|
|
|
|
+ while(pKeys.hasNext()) {
|
|
|
|
+ String pKey = pKeys.next();
|
|
|
|
+ Object pValue = props.get(pKey);
|
|
|
|
+ // update properties state
|
|
|
|
+ device.addProperty(rUri, pKey, pValue);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //Log.d(TAG, "Light Control doGetResourceProperties() : "+lightControlBinder.doGetResourceProperties("2b32e152-3756-4fb6-b3f2-d8db7aafe39f", "/light"));
|
|
|
|
- //Log.d(TAG, "Light Control doGetResourceProperties() : "+lightControlBinder.doGetResourceProperties("2b32e152-3756-4fb6-b3f2-d8db7aafe39f", "/dimming"));
|
|
|
|
- //Log.d(TAG, "Light Control doPostResourceProperties() : "+lightControlBinder.doPostResourceProperties("2b32e152-3756-4fb6-b3f2-d8db7aafe39f", "/light", null));
|
|
|
|
- //Log.d(TAG, "Light Control doPostResourceProperties() : "+lightControlBinder.doPostResourceProperties("2b32e152-3756-4fb6-b3f2-d8db7aafe39f", "/dimming", null));
|
|
|
|
}
|
|
}
|
|
} catch (RemoteException | JSONException ex) {
|
|
} catch (RemoteException | JSONException ex) {
|
|
Log.e(TAG, "Register Callback", ex);
|
|
Log.e(TAG, "Register Callback", ex);
|
|
@@ -434,8 +445,8 @@ public class BridgeService extends IntentService {
|
|
String res_type = obj.getString("res_type"); // GET, POST, PUT
|
|
String res_type = obj.getString("res_type"); // GET, POST, PUT
|
|
String res_data = obj.getString("res_data"); // Properties
|
|
String res_data = obj.getString("res_data"); // Properties
|
|
|
|
|
|
- Log.d(TAG, "Light Control doPostResourceProperties() : "+lightControlBinder.doPostResourceProperties(sn, uri, res_data));
|
|
|
|
-
|
|
|
|
|
|
+ VirtualOCFDevice device = bridgeServer.getVirtualOCFDevice(sn);
|
|
|
|
+ device.addProperties(uri, res_data);
|
|
}
|
|
}
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
@@ -467,12 +478,12 @@ public class BridgeService extends IntentService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String retrieveAllDevices() throws RemoteException {
|
|
public String retrieveAllDevices() throws RemoteException {
|
|
- return "[{\"n\":\"Light Switch\", \"rt\":[\"oic.d.light\"], \"sn\":\"2b32e152-3756-4fb6-b3f2-d8db7aafe39f\", \"state\":\"on-line\"}]";
|
|
|
|
|
|
+ return "[{\"n\":\"Light Control\", \"rt\":[\"oic.d.light\"], \"sn\":\""+BridgeServer.LIGHT2_UUID+"\", \"state\":\"on-line\"}]";
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String retrieveAllResources(String device_uuid) throws RemoteException {
|
|
public String retrieveAllResources(String device_uuid) throws RemoteException {
|
|
- if("2b32e152-3756-4fb6-b3f2-d8db7aafe39f".equalsIgnoreCase(device_uuid)) {
|
|
|
|
|
|
+ if(BridgeServer.LIGHT2_UUID.equalsIgnoreCase(device_uuid)) {
|
|
return "[{\"n\":\"Light Switch\", \"uri\":\"/light\", \"rt\":[\"oic.r.switch.binary\"], \"if\":\"RW\"},\n" +
|
|
return "[{\"n\":\"Light Switch\", \"uri\":\"/light\", \"rt\":[\"oic.r.switch.binary\"], \"if\":\"RW\"},\n" +
|
|
"{\"n\":\"Dimming Control\",\"uri\":\"/dimming\",\"rt\":[\"oic.r.light.dimming\"], \"if\":\"RW\"},\n" +
|
|
"{\"n\":\"Dimming Control\",\"uri\":\"/dimming\",\"rt\":[\"oic.r.light.dimming\"], \"if\":\"RW\"},\n" +
|
|
"{\"n\":\"Energy Consumption\", \"uri\":\"/EnergyConsumptionResURI\", \"rt\": [\"oic.r.energy.consumption\"], \"if\":\"S\"},\n" +
|
|
"{\"n\":\"Energy Consumption\", \"uri\":\"/EnergyConsumptionResURI\", \"rt\": [\"oic.r.energy.consumption\"], \"if\":\"S\"},\n" +
|
|
@@ -483,7 +494,7 @@ public class BridgeService extends IntentService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String doGetResourceProperties(String device_uuid, String resource_uri) throws RemoteException {
|
|
public String doGetResourceProperties(String device_uuid, String resource_uri) throws RemoteException {
|
|
- if("2b32e152-3756-4fb6-b3f2-d8db7aafe39f".equalsIgnoreCase(device_uuid)) {
|
|
|
|
|
|
+ if(BridgeServer.LIGHT2_UUID.equalsIgnoreCase(device_uuid)) {
|
|
if("/light".equalsIgnoreCase(resource_uri)) {
|
|
if("/light".equalsIgnoreCase(resource_uri)) {
|
|
return "{\"n\":\"Light Switch\", \"value\":true}" ;
|
|
return "{\"n\":\"Light Switch\", \"value\":true}" ;
|
|
} else if("/dimming".equalsIgnoreCase(resource_uri)) {
|
|
} else if("/dimming".equalsIgnoreCase(resource_uri)) {
|
|
@@ -498,22 +509,25 @@ public class BridgeService extends IntentService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public boolean doPostResourceProperties(String device_uuid, String resource_uri, String prop_data) throws RemoteException {
|
|
|
|
- if("2b32e152-3756-4fb6-b3f2-d8db7aafe39f".equalsIgnoreCase(device_uuid)) {
|
|
|
|
|
|
+ public boolean doPostResourceProperties(String device_sn, String resource_uri, String prop_data) throws RemoteException {
|
|
|
|
+
|
|
|
|
+ Log.d(TAG, "doPostResourceProperties called : device_sn = " + device_sn);
|
|
|
|
+ if(BridgeServer.LIGHT2_UUID.equalsIgnoreCase(device_sn)) {
|
|
|
|
+ Log.d(TAG, "Light Control Service : doPostResourceProperties() uri = " + resource_uri+ ", properites = " + prop_data);
|
|
if("/light".equalsIgnoreCase(resource_uri)) {
|
|
if("/light".equalsIgnoreCase(resource_uri)) {
|
|
- String res_data = makeResultData(device_uuid, resource_uri, "{\"n\":\"Light Switch\", \"value\":true}");
|
|
|
|
|
|
+ String res_data = makeResultData(device_sn, resource_uri, prop_data);
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_LIGHT_RESULT, ResultType.OK.ordinal(), 0, res_data));
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_LIGHT_RESULT, ResultType.OK.ordinal(), 0, res_data));
|
|
return true ;
|
|
return true ;
|
|
} else if("/dimming".equalsIgnoreCase(resource_uri)) {
|
|
} else if("/dimming".equalsIgnoreCase(resource_uri)) {
|
|
- String res_data = makeResultData(device_uuid, resource_uri, "{\"n\":\"Dimming Control\",\"dimmingSetting\":100,\"range\":100,\"step\":10}");
|
|
|
|
|
|
+ String res_data = makeResultData(device_sn, resource_uri, prop_data);
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_LIGHT_RESULT, ResultType.OK.ordinal(), 0, res_data));
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_LIGHT_RESULT, ResultType.OK.ordinal(), 0, res_data));
|
|
return true ;
|
|
return true ;
|
|
} else if("/EnergyConsumptionResURI".equalsIgnoreCase(resource_uri)) {
|
|
} else if("/EnergyConsumptionResURI".equalsIgnoreCase(resource_uri)) {
|
|
- String res_data = makeResultData(device_uuid, resource_uri, "{\"n\":\"Energy Consumption\",\"power\":200.1,\"energy\":3500.4}") ;
|
|
|
|
|
|
+ String res_data = makeResultData(device_sn, resource_uri, prop_data) ;
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_LIGHT_RESULT, ResultType.OK.ordinal(), 0, res_data));
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_LIGHT_RESULT, ResultType.OK.ordinal(), 0, res_data));
|
|
return true ;
|
|
return true ;
|
|
} else if("/ColourTemperatureResURI".equalsIgnoreCase(resource_uri)) {
|
|
} else if("/ColourTemperatureResURI".equalsIgnoreCase(resource_uri)) {
|
|
- String res_data = makeResultData(device_uuid, resource_uri, "{\"n\":\"Color Temperature\", \"ct\":457, \"range\":1000, \"step\":1}") ;
|
|
|
|
|
|
+ String res_data = makeResultData(device_sn, resource_uri, prop_data) ;
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_LIGHT_RESULT, ResultType.OK.ordinal(), 0, res_data));
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_LIGHT_RESULT, ResultType.OK.ordinal(), 0, res_data));
|
|
return true ;
|
|
return true ;
|
|
}
|
|
}
|
|
@@ -561,9 +575,35 @@ public class BridgeService extends IntentService {
|
|
return null ;
|
|
return null ;
|
|
}
|
|
}
|
|
|
|
|
|
- public void doPostLightControlResource(String device_uuid, String resource_uri, String prop_data) {
|
|
|
|
|
|
+ public void doGetLightControlResources() {
|
|
|
|
+
|
|
|
|
+ // TODO : doGetProperties with Light Control Service
|
|
|
|
+ if(bridgeServer != null && lightBinder != null) {
|
|
|
|
+ ArrayList<VirtualOCFDevice> vods = bridgeServer.getVirtualOCFDeviceList();
|
|
|
|
+ for (VirtualOCFDevice vod : vods) {
|
|
|
|
+ if (vod.getEcoName().equals(LightControlServiceConnection.ECO_NAME) && vod.isDiscovered()
|
|
|
|
+ && bridgeServer.isOwnedVirtualOCFDevice(vod.getVODIndex())) {
|
|
|
|
+ String device_sn = vod.getVirtualDeviceId();
|
|
|
|
+ for (OCFDevice.Resource resource : vod.getResources()) {
|
|
|
|
+ try {
|
|
|
|
+ lightBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
|
|
|
|
+ } catch (RemoteException e) {
|
|
|
|
+ Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void doPostLightControlResource(long device_index, String device_id, String resource_uri, String prop_data) {
|
|
try {
|
|
try {
|
|
- lightBinder.doPostResourceProperties(device_uuid, resource_uri, prop_data);
|
|
|
|
|
|
+ OCUuid piid = OCCoreRes.getDeviceInfo(device_index).getPiid();
|
|
|
|
+ String device_sn = OCUuidUtil.uuidToString(piid); // same with vod_id(Virtual Device Id) of VirtualOCFDevice
|
|
|
|
+
|
|
|
|
+ Log.d(TAG, "doPostLightControlResource() called.");
|
|
|
|
+ lightBinder.doPostResourceProperties(device_sn, resource_uri, prop_data);
|
|
|
|
+
|
|
} catch (RemoteException e) {
|
|
} catch (RemoteException e) {
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
}
|
|
}
|
|
@@ -725,19 +765,19 @@ public class BridgeService extends IntentService {
|
|
Log.d(TAG, msg);
|
|
Log.d(TAG, msg);
|
|
}
|
|
}
|
|
Log.d(TAG, "DeviceDiscovery ScheduledTask per 60sec was called.");
|
|
Log.d(TAG, "DeviceDiscovery ScheduledTask per 60sec was called.");
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
}, 10, 90, TimeUnit.SECONDS); //90 sec interval after 10sec delay
|
|
}, 10, 90, TimeUnit.SECONDS); //90 sec interval after 10sec delay
|
|
|
|
|
|
- /*executorService.scheduleAtFixedRate(new Runnable() {
|
|
|
|
|
|
+ executorService.scheduleAtFixedRate(new Runnable() {
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
- // TODO
|
|
|
|
- bridgeServer.loadPairwisedDeviceUUIDs();
|
|
|
|
|
|
+ // TODO : Pairwised device UUID
|
|
|
|
+ // bridgeServer.loadPairwisedDeviceUUIDs();
|
|
|
|
+ // TODO : Getting Properites of Light Control Service
|
|
|
|
+ doGetLightControlResources();
|
|
}
|
|
}
|
|
- }, 30, 60, TimeUnit.SECONDS); // 30sec interval after 30sec delay
|
|
|
|
- */
|
|
|
|
|
|
+ }, 30, 180, TimeUnit.SECONDS); // 30sec interval after 30sec delay
|
|
|
|
+
|
|
/*executorService.schedule(new Runnable() {
|
|
/*executorService.schedule(new Runnable() {
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|