|
@@ -30,6 +30,7 @@ import org.iotivity.bridge.homeserver.handler.client.DeviceDiscoveryHandler;
|
|
|
import org.iotivity.bridge.homeserver.handler.client.GetResponseHandler;
|
|
|
import org.iotivity.bridge.homeserver.handler.client.ObserveResponseHandler;
|
|
|
import org.iotivity.bridge.homeserver.handler.client.PostResponseHandler;
|
|
|
+import org.iotivity.bridge.homeserver.handler.client.PutResponseHandler;
|
|
|
import org.iotivity.bridge.homeserver.model.Bridge;
|
|
|
import org.iotivity.bridge.homeserver.utils.Utils;
|
|
|
import org.iotivity.oc.OcCborEncoder;
|
|
@@ -565,8 +566,9 @@ public class BridgeService extends IntentService {
|
|
|
OcRemoteResource resource = bridgeServer.getPairwisedResource(device_uuid, resource_uri);
|
|
|
if(resource==null) return false ;
|
|
|
|
|
|
- PostResponseHandler postLight = new PostResponseHandler(getService(), resource);
|
|
|
- if (OcUtils.initPost(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, postLight, OCQos.LOW_QOS)) {
|
|
|
+ Log.d(TAG,"Post Request called.");
|
|
|
+ PostResponseHandler post = new PostResponseHandler(getService(), resource);
|
|
|
+ if (OcUtils.initPost(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, post, OCQos.LOW_QOS)) {
|
|
|
|
|
|
try {
|
|
|
JSONObject json = new JSONObject(prop_data);
|
|
@@ -577,20 +579,15 @@ public class BridgeService extends IntentService {
|
|
|
Object value = json.get(key);
|
|
|
|
|
|
if (value instanceof Boolean) {
|
|
|
- Log.d(TAG, "type = " + Boolean.class.toString());
|
|
|
- root.setBoolean(key, (Boolean) value);
|
|
|
+ root.setBoolean(key, (Boolean)value);
|
|
|
} else if (value instanceof Integer) {
|
|
|
- Log.d(TAG, "type = " + Integer.class.toString());
|
|
|
- root.setLong(key, (Integer) value);
|
|
|
+ root.setLong(key, (Integer)value);
|
|
|
} else if (value instanceof Long) {
|
|
|
- Log.d(TAG, "type = " + Long.class.toString());
|
|
|
- root.setLong(key, (Long) value);
|
|
|
+ root.setLong(key, (Long)value);
|
|
|
} else if (value instanceof Double) {
|
|
|
- Log.d(TAG, "type = " + Double.class.toString());
|
|
|
- root.setDouble(key, (Double) value);
|
|
|
+ root.setDouble(key, (Double)value);
|
|
|
} else if (value instanceof String) {
|
|
|
- Log.d(TAG, "type = " + String.class.toString());
|
|
|
- root.setTextString(key, (String) value);
|
|
|
+ root.setTextString(key, (String)value);
|
|
|
}
|
|
|
}
|
|
|
root.done();
|
|
@@ -599,20 +596,67 @@ public class BridgeService extends IntentService {
|
|
|
}
|
|
|
|
|
|
if (OcUtils.doPost()) {
|
|
|
- msg("\tSent POST request");
|
|
|
- printLine();
|
|
|
+ Log.d(TAG, "\tSent POST request");
|
|
|
return true ;
|
|
|
} else {
|
|
|
- msg("\tCould not send POST request");
|
|
|
- printLine();
|
|
|
+ Log.d(TAG, "\tCould not send POST request");
|
|
|
return false ;
|
|
|
}
|
|
|
} else {
|
|
|
- msg("\tCould not init POST request");
|
|
|
- printLine();
|
|
|
+ Log.d(TAG, "\tCould not init POST request");
|
|
|
return false ;
|
|
|
}
|
|
|
+ }
|
|
|
+ return false ;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean doPutDeviceResource(String device_uuid, String resource_uri, String prop_data) {
|
|
|
+
|
|
|
+ if(bridgeServer!=null) {
|
|
|
+
|
|
|
+ OcRemoteResource resource = bridgeServer.getPairwisedResource(device_uuid, resource_uri);
|
|
|
+ if(resource==null) return false ;
|
|
|
+
|
|
|
+ Log.d(TAG,"Put Request called.");
|
|
|
+ PutResponseHandler put = new PutResponseHandler(getService(), resource);
|
|
|
+ if (OcUtils.initPut(resource.getUri(), Utils.getCoapsEndpoint(resource.getEndpoints()), null, put, OCQos.LOW_QOS)) {
|
|
|
|
|
|
+ try {
|
|
|
+ JSONObject json = new JSONObject(prop_data);
|
|
|
+ Iterator<String> it = json.keys();
|
|
|
+ OcCborEncoder root = OcCborEncoder.createOcCborEncoder(OcCborEncoder.EncoderType.ROOT);
|
|
|
+ while (it.hasNext()) {
|
|
|
+ String key = it.next();
|
|
|
+ Object value = json.get(key);
|
|
|
+
|
|
|
+ if (value instanceof Boolean) {
|
|
|
+ root.setBoolean(key, (Boolean)value);
|
|
|
+ } else if (value instanceof Integer) {
|
|
|
+ root.setLong(key, (Integer)value);
|
|
|
+ } else if (value instanceof Long) {
|
|
|
+ root.setLong(key, (Long)value);
|
|
|
+ } else if (value instanceof Double) {
|
|
|
+ root.setDouble(key, (Double)value);
|
|
|
+ } else if (value instanceof String) {
|
|
|
+ root.setTextString(key, (String)value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ root.done();
|
|
|
+ } catch (JSONException ex) {
|
|
|
+ Log.d(TAG, "Json Parsing Error : ", ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OcUtils.doPut()) {
|
|
|
+ Log.d(TAG, "\tSent PUT request");
|
|
|
+ return true ;
|
|
|
+ } else {
|
|
|
+ Log.d(TAG, "\tCould not send PUT request");
|
|
|
+ return false ;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log.d(TAG, "\tCould not init PUT request");
|
|
|
+ return false ;
|
|
|
+ }
|
|
|
}
|
|
|
return false ;
|
|
|
}
|
|
@@ -622,10 +666,8 @@ public class BridgeService extends IntentService {
|
|
|
OcRemoteDevice remoteDevice = findPairwisedRemoteDevice(device_uuid);
|
|
|
if (remoteDevice == null) return false ;
|
|
|
|
|
|
- /* TODO : Observe only device specfic resources until shutdown or until stop Observe.
|
|
|
- * This may cause too many observing to the device
|
|
|
- * To avoid this issue, I think Resource Observing list should be managed in BridgeService
|
|
|
- * or stop Observing before Observing */
|
|
|
+ /* Observe only device specfic resources until shutdown or until stop Observe.
|
|
|
+ */
|
|
|
int count = 0 ;
|
|
|
for(OcRemoteResource resource : remoteDevice.getResources()) {
|
|
|
if(Utils.isDeviceSpecificResource(resource.getTypes())) {
|