Bläddra i källkod

Double type issue related to JSONObject.toString() was fixed but it needs to be test with doPostDeviceResource() by BridgeService Client.

Trishia 4 år sedan
förälder
incheckning
ec8df30fe5

+ 2 - 2
app/build.gradle

@@ -7,8 +7,8 @@ android {
         applicationId "org.iotivity.bridge.homeserver"
         applicationId "org.iotivity.bridge.homeserver"
         minSdkVersion 23
         minSdkVersion 23
         targetSdkVersion 26
         targetSdkVersion 26
-        versionCode 2
-        versionName "1.0"
+        versionCode 3
+        versionName "1.0.2"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
     }
     buildTypes {
     buildTypes {

+ 34 - 2
app/src/main/java/org/iotivity/bridge/homeserver/BridgeServer.java

@@ -99,7 +99,9 @@ public class BridgeServer {
     }
     }
 
 
     public void resetBridgeServer() {
     public void resetBridgeServer() {
+
         OCMain.resetDevice(Bridge.BRIDGE_INDEX);
         OCMain.resetDevice(Bridge.BRIDGE_INDEX);
+        // or ocPlatform.reset();
 
 
         // this below logic has some issue for now so don't use
         // this below logic has some issue for now so don't use
         //ocPlatform.reset();
         //ocPlatform.reset();
@@ -370,7 +372,7 @@ public class BridgeServer {
                 bridge.addOrReplaceVirtualOCFDevice(vod);
                 bridge.addOrReplaceVirtualOCFDevice(vod);
 
 
                 // Add Light Device Resources and Handler
                 // Add Light Device Resources and Handler
-                OCResource res_light = OCMain.newResource(devicename, "/light", (short)1, (long) vod_index);
+                OCResource res_light = OCMain.newResource("Light Switch", "/light", (short)1, (long)vod_index);
                 OCMain.resourceBindResourceType(res_light, "oic.r.switch.binary");  // BinarySwitch Resource Type
                 OCMain.resourceBindResourceType(res_light, "oic.r.switch.binary");  // BinarySwitch Resource Type
                 OCMain.resourceBindResourceInterface(res_light, OCInterfaceMask.RW);
                 OCMain.resourceBindResourceInterface(res_light, OCInterfaceMask.RW);
                 OCMain.resourceSetDefaultInterface(res_light, OCInterfaceMask.RW);
                 OCMain.resourceSetDefaultInterface(res_light, OCInterfaceMask.RW);
@@ -385,7 +387,7 @@ public class BridgeServer {
                 vod.addOCResource(res_light);
                 vod.addOCResource(res_light);
 
 
                 // Add Dimming Resource
                 // Add Dimming Resource
-                OCResource res_dimming = OCMain.newResource(devicename, "/dimming", (short) 1, (long) vod_index);
+                OCResource res_dimming = OCMain.newResource("Dimming Control", "/dimming", (short) 1, (long)vod_index);
                 OCMain.resourceBindResourceType(res_dimming, "oic.r.light.dimming");
                 OCMain.resourceBindResourceType(res_dimming, "oic.r.light.dimming");
                 OCMain.resourceBindResourceInterface(res_dimming, OCInterfaceMask.RW);
                 OCMain.resourceBindResourceInterface(res_dimming, OCInterfaceMask.RW);
                 OCMain.resourceSetDefaultInterface(res_dimming, OCInterfaceMask.RW);
                 OCMain.resourceSetDefaultInterface(res_dimming, OCInterfaceMask.RW);
@@ -399,6 +401,36 @@ public class BridgeServer {
                 OCMain.addResource(res_dimming);
                 OCMain.addResource(res_dimming);
                 vod.addOCResource(res_dimming);
                 vod.addOCResource(res_dimming);
 
 
+                // Add ColorTemperature Resource
+                OCResource res_colortemp = OCMain.newResource(Light.RESOURCE_NAME_COLORTMEP, Light.URI_COLORTMEP, (short) 1, (long)vod_index);
+                OCMain.resourceBindResourceType(res_colortemp, Light.RT_COLORTEMP);
+                OCMain.resourceBindResourceInterface(res_colortemp, OCInterfaceMask.A);
+                OCMain.resourceSetDefaultInterface(res_colortemp, OCInterfaceMask.A);
+                OCMain.resourceSetDiscoverable(res_colortemp, true);
+                OCMain.resourceSetObservable(res_colortemp, true);
+                //TODO : check if it is needed for notifying to client
+                //OCMain.resourceSetPeriodicObservable(res_dimming, 60); // seconds
+                OCMain.resourceSetRequestHandler(res_colortemp, OCMethod.OC_GET, new GetLightRequestHandler(service, light));
+                OCMain.resourceSetRequestHandler(res_colortemp, OCMethod.OC_POST, new PostLightRequestHandler(service, light));
+                OCMain.resourceSetRequestHandler(res_colortemp, OCMethod.OC_PUT, new PutLightRequestHandler(service, light));
+                OCMain.addResource(res_colortemp);
+                vod.addOCResource(res_colortemp);
+
+                // Add EnergyConsumption Resource
+                OCResource res_energy = OCMain.newResource(Light.RESOURCE_NAME_ENERGY, Light.URI_ENERGY, (short)1, (long)vod_index);
+                OCMain.resourceBindResourceType(res_energy, Light.RT_ENERGY);
+                OCMain.resourceBindResourceInterface(res_energy, OCInterfaceMask.A);
+                OCMain.resourceSetDefaultInterface(res_energy, OCInterfaceMask.A);
+                OCMain.resourceSetDiscoverable(res_energy, true);
+                OCMain.resourceSetObservable(res_energy, true);
+                //TODO : check if it is needed for notifying to client
+                //OCMain.resourceSetPeriodicObservable(res_dimming, 60); // seconds
+                OCMain.resourceSetRequestHandler(res_energy, OCMethod.OC_GET, new GetLightRequestHandler(service, light));
+                OCMain.resourceSetRequestHandler(res_energy, OCMethod.OC_POST, new PostLightRequestHandler(service, light));
+                OCMain.resourceSetRequestHandler(res_energy, OCMethod.OC_PUT, new PutLightRequestHandler(service, light));
+                OCMain.addResource(res_energy);
+                vod.addOCResource(res_energy);
+
                 // set immutable device id for Platform Independent Identifier (piid)
                 // set immutable device id for Platform Independent Identifier (piid)
                 OCMain.setImmutableDeviceIdentifier(vod_index, OCUuidUtil.stringToUuid(virtual_di));
                 OCMain.setImmutableDeviceIdentifier(vod_index, OCUuidUtil.stringToUuid(virtual_di));
                 Log.d(TAG, "Virtual Device [" + vod_info.getIndex() + "] "
                 Log.d(TAG, "Virtual Device [" + vod_info.getIndex() + "] "

+ 15 - 1
app/src/main/java/org/iotivity/bridge/homeserver/BridgeServerActivity.java

@@ -10,6 +10,7 @@ import android.content.ServiceConnection;
 import android.net.Uri;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Bundle;
 
 
+import android.os.Handler;
 import android.os.IBinder;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.os.RemoteException;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.app.AppCompatActivity;
@@ -182,12 +183,25 @@ public class BridgeServerActivity extends AppCompatActivity {
 
 
             Log.d(TAG, "onServiceConnected ComponentName=" + name + ", IBinder=" + service.toString());
             Log.d(TAG, "onServiceConnected ComponentName=" + name + ", IBinder=" + service.toString());
             if (service instanceof IBridgeService.Stub) {
             if (service instanceof IBridgeService.Stub) {
-
                 remoteBinder = IBridgeService.Stub.asInterface(service);
                 remoteBinder = IBridgeService.Stub.asInterface(service);
 
 
                 try {
                 try {
                     remoteBinder.registerActivityCallback(aCallback);
                     remoteBinder.registerActivityCallback(aCallback);
                     remoteBinder.registerBridgeServiceCallback(sCallback);
                     remoteBinder.registerBridgeServiceCallback(sCallback);
+                    // for test
+                    /*new Handler().postDelayed(new Runnable() {
+                        @Override
+                        public void run() {
+                            // test code
+                            try {
+                                String res = remoteBinder.retrieveAllDevices();
+                                Log.d(TAG, "remoteBinder.retrieveAllDevices() = " + res);
+                            } catch (RemoteException e) {
+                                e.printStackTrace();
+                                Log.e(TAG, "remoteBinder : ", e);
+                            }
+                        }
+                    }, 35 * 1000);*/
                 } catch (RemoteException ex) {
                 } catch (RemoteException ex) {
                     Log.e(TAG, "Register Callbacks", ex);
                     Log.e(TAG, "Register Callbacks", ex);
                     // In this case the service has crashed before we could even
                     // In this case the service has crashed before we could even

+ 2 - 0
app/src/main/java/org/iotivity/bridge/homeserver/BridgeService.java

@@ -1047,6 +1047,8 @@ public class BridgeService extends IntentService {
                             root.setLong(key, (Long)value);
                             root.setLong(key, (Long)value);
                         } else if (value instanceof Double) {
                         } else if (value instanceof Double) {
                             root.setDouble(key, (Double)value);
                             root.setDouble(key, (Double)value);
+                        } else if (value instanceof Float) {
+                            root.setDouble(key, (Double)value);
                         } else if (value instanceof String) {
                         } else if (value instanceof String) {
                             root.setTextString(key, (String)value);
                             root.setTextString(key, (String)value);
                         }
                         }

+ 2 - 2
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/GetLight2ResponseHandler.java

@@ -67,9 +67,9 @@ public class GetLight2ResponseHandler implements OCResponseHandler {
                     activity.msg("\t" + rep.getName() + " = " + rep.getValue().getString());
                     activity.msg("\t" + rep.getName() + " = " + rep.getValue().getString());
                     props.add(new Pair(rep.getName(), rep.getValue().getString()));
                     props.add(new Pair(rep.getName(), rep.getValue().getString()));
                     if(Light.URI_LIGHT.equalsIgnoreCase(resource.getUri())) {
                     if(Light.URI_LIGHT.equalsIgnoreCase(resource.getUri())) {
-                        light.setLightResourceName(rep.getValue().getString());
+                        //light.setLightResourceName(rep.getValue().getString());
                     } else if(Light.URI_DIMMING.equalsIgnoreCase(resource.getUri())) {
                     } else if(Light.URI_DIMMING.equalsIgnoreCase(resource.getUri())) {
-                        light.setDimmingResourceName(rep.getValue().getString());
+                        //light.setDimmingResourceName(rep.getValue().getString());
                     }
                     }
                     break;
                     break;
                 default:
                 default:

+ 13 - 4
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/GetLightResponseHandler.java

@@ -5,6 +5,7 @@ import android.util.Pair;
 
 
 import org.iotivity.OCClientResponse;
 import org.iotivity.OCClientResponse;
 import org.iotivity.OCQos;
 import org.iotivity.OCQos;
+import org.iotivity.OCRep;
 import org.iotivity.OCRepresentation;
 import org.iotivity.OCRepresentation;
 import org.iotivity.OCResponseHandler;
 import org.iotivity.OCResponseHandler;
 import org.iotivity.OCStatus;
 import org.iotivity.OCStatus;
@@ -47,6 +48,8 @@ public class GetLightResponseHandler implements OCResponseHandler {
         final ArrayList<Pair<String, Object>> props = new ArrayList<>();
         final ArrayList<Pair<String, Object>> props = new ArrayList<>();
 
 
         OCRepresentation rep = response.getPayload();
         OCRepresentation rep = response.getPayload();
+        String json = OCRep.toJSON(rep, false); // boolean : prettyPrint or not
+        Log.d(TAG, "GET "+resource.getUri()+" Response : " + json);
         while (rep != null) {
         while (rep != null) {
             switch (rep.getType()) {
             switch (rep.getType()) {
                 case OC_REP_BOOL:
                 case OC_REP_BOOL:
@@ -70,10 +73,16 @@ public class GetLightResponseHandler implements OCResponseHandler {
                 case OC_REP_STRING:
                 case OC_REP_STRING:
                     activity.msg("\t" + rep.getName() + " = " + rep.getValue().getString());
                     activity.msg("\t" + rep.getName() + " = " + rep.getValue().getString());
                     props.add(new Pair(rep.getName(), rep.getValue().getString()));
                     props.add(new Pair(rep.getName(), rep.getValue().getString()));
-                    if(Light.URI_LIGHT.equalsIgnoreCase(resource.getUri())) {
-                        light.setLightResourceName(rep.getValue().getString());
-                    } else if(Light.URI_DIMMING.equalsIgnoreCase(resource.getUri())) {
-                        light.setDimmingResourceName(rep.getValue().getString());
+                    break;
+                case OC_REP_DOUBLE:
+                    activity.msg("\t" + rep.getName() + " = " + rep.getValue().getDouble());
+                    props.add(new Pair(rep.getName(), rep.getValue().getDouble()));
+                    if(Light.URI_ENERGY.equalsIgnoreCase(resource.getUri())) {
+                       if(Light.POWER_KEY.equalsIgnoreCase(rep.getName())) {
+                           light.setPower(rep.getValue().getDouble());
+                       } else if(Light.ENERGY_KEY.equalsIgnoreCase(rep.getName())) {
+                           light.setEnergy(rep.getValue().getDouble());
+                       }
                     }
                     }
                     break;
                     break;
                 default:
                 default:

+ 19 - 2
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/GetResponseHandler.java

@@ -40,13 +40,30 @@ public class GetResponseHandler implements OCResponseHandler {
         String json = OCRep.toJSON(rep, false); // boolean : prettyPrint or not
         String json = OCRep.toJSON(rep, false); // boolean : prettyPrint or not
         Log.d(TAG, "GET "+resource.getUri()+" Response : " + json);
         Log.d(TAG, "GET "+resource.getUri()+" Response : " + json);
 
 
+        try {
+            StringBuffer sb = new StringBuffer();
+            sb.append("{");
+            sb.append("\"id\":\"" + resource.getAnchor() + resource.getUri() + "\",");
+            sb.append("\"di\":\"" + Utils.getDIFromAnchor(resource.getAnchor()) + "\",");
+            sb.append("\"uri\":\"" + resource.getUri() + "\",");
+            sb.append("\"res_type\":\"" + BridgeService.ResponseType.GET.name() + "\",");
+            sb.append("\"res_data\":" + json);
+            sb.append("}");
+
+            String result_str = sb.toString().replace("\\", "");
+            service.broadcastResult(BridgeService.ResultType.OK.ordinal(), result_str);
+
+        } catch (Exception ex) {
+            Log.e(TAG, "JSON Error : ", ex);
+        }
+        /*
         try {
         try {
             JSONObject props = new JSONObject(json);
             JSONObject props = new JSONObject(json);
             JSONObject result = new JSONObject();
             JSONObject result = new JSONObject();
             result.put("id", resource.getAnchor() + resource.getUri());
             result.put("id", resource.getAnchor() + resource.getUri());
             result.put("di", Utils.getDIFromAnchor(resource.getAnchor()));
             result.put("di", Utils.getDIFromAnchor(resource.getAnchor()));
             result.put("uri", resource.getUri());
             result.put("uri", resource.getUri());
-            result.put("res_type", BridgeService.ResponseType.GET.name());
+            result.put("res_type", res_type.name());
             result.put("res_data", props);
             result.put("res_data", props);
 
 
             String result_str = result.toString().replace("\\", "");
             String result_str = result.toString().replace("\\", "");
@@ -54,7 +71,7 @@ public class GetResponseHandler implements OCResponseHandler {
 
 
         } catch (JSONException ex) {
         } catch (JSONException ex) {
             Log.e(TAG, "JSON Error : ", ex);
             Log.e(TAG, "JSON Error : ", ex);
-        }
+        }*/
 
 
         // for test
         // for test
         /*service.doPostDeviceResource(Utils.getDIFromAnchor(resource.getAnchor()),
         /*service.doPostDeviceResource(Utils.getDIFromAnchor(resource.getAnchor()),

+ 11 - 4
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/ObserveLightResponseHandler.java

@@ -1,5 +1,7 @@
 package org.iotivity.bridge.homeserver.handler.client;
 package org.iotivity.bridge.homeserver.handler.client;
 
 
+import android.util.Pair;
+
 import org.iotivity.OCClientResponse;
 import org.iotivity.OCClientResponse;
 import org.iotivity.OCRepresentation;
 import org.iotivity.OCRepresentation;
 import org.iotivity.OCResponseHandler;
 import org.iotivity.OCResponseHandler;
@@ -46,10 +48,15 @@ public class ObserveLightResponseHandler implements OCResponseHandler {
                     break;
                     break;
                 case OC_REP_STRING:
                 case OC_REP_STRING:
                     activity.msg("\t" + rep.getName() + " = " + rep.getValue().getString());
                     activity.msg("\t" + rep.getName() + " = " + rep.getValue().getString());
-                    if(Light.URI_LIGHT.equals(resource.getUri())) {
-                        light.setLightResourceName(rep.getValue().getString());
-                    } else if(Light.URI_DIMMING.equals(resource.getUri())) {
-                        light.setDimmingResourceName(rep.getValue().getString());
+                    break;
+                case OC_REP_DOUBLE:
+                    activity.msg("\t" + rep.getName() + " = " + rep.getValue().getDouble());
+                    if(Light.URI_ENERGY.equalsIgnoreCase(resource.getUri())) {
+                        if(Light.POWER_KEY.equalsIgnoreCase(rep.getName())) {
+                            light.setPower(rep.getValue().getDouble());
+                        } else if(Light.ENERGY_KEY.equalsIgnoreCase(rep.getName())) {
+                            light.setEnergy(rep.getValue().getDouble());
+                        }
                     }
                     }
                     break;
                     break;
                 default:
                 default:

+ 18 - 1
app/src/main/java/org/iotivity/bridge/homeserver/handler/client/ObserveResponseHandler.java

@@ -47,6 +47,23 @@ public class ObserveResponseHandler implements OCResponseHandler {
         String json = OCRep.toJSON(rep, false); // boolean : prettyPrint or not
         String json = OCRep.toJSON(rep, false); // boolean : prettyPrint or not
         Log.d(TAG, "OBSERVE "+resource.getUri()+" Response : " + json);
         Log.d(TAG, "OBSERVE "+resource.getUri()+" Response : " + json);
 
 
+        try {
+            StringBuffer sb = new StringBuffer();
+            sb.append("{");
+            sb.append("\"id\":\"" + resource.getAnchor() + resource.getUri() + "\",");
+            sb.append("\"di\":\"" + Utils.getDIFromAnchor(resource.getAnchor()) + "\",");
+            sb.append("\"uri\":\"" + resource.getUri() + "\",");
+            sb.append("\"res_type\":\"" + BridgeService.ResponseType.GET.name() + "\",");
+            sb.append("\"res_data\":" + json);
+            sb.append("}");
+
+            String result_str = sb.toString().replace("\\", "");
+            service.broadcastResult(BridgeService.ResultType.OK.ordinal(), result_str);
+
+        } catch (Exception ex) {
+            Log.e(TAG, "JSON Error : ", ex);
+        }
+        /*
         try {
         try {
             JSONObject props = new JSONObject(json);
             JSONObject props = new JSONObject(json);
             JSONObject result = new JSONObject();
             JSONObject result = new JSONObject();
@@ -61,6 +78,6 @@ public class ObserveResponseHandler implements OCResponseHandler {
 
 
         } catch (JSONException ex) {
         } catch (JSONException ex) {
             Log.e(TAG, "JSON Error : ", ex);
             Log.e(TAG, "JSON Error : ", ex);
-        }
+        }*/
     }
     }
 }
 }

+ 22 - 4
app/src/main/java/org/iotivity/bridge/homeserver/handler/server/GetLightRequestHandler.java

@@ -40,25 +40,43 @@ public class GetLightRequestHandler implements OCRequestHandler {
             case OCInterfaceMask.A:
             case OCInterfaceMask.A:
                 if(Light.URI_LIGHT.equalsIgnoreCase(request.getResource().getUri())) {
                 if(Light.URI_LIGHT.equalsIgnoreCase(request.getResource().getUri())) {
                     // Light Switch Optional Resource (read only)
                     // Light Switch Optional Resource (read only)
-                    root.setTextString(Light.RESOURCE_NAME_KEY, light.getLightResourceName());
+                    root.setTextString(Light.RESOURCE_NAME_KEY, Light.RESOURCE_NAME_SWITCH);
                     // Light Switch (Switch Binary) Required Resource (read write)
                     // Light Switch (Switch Binary) Required Resource (read write)
                     root.setBoolean(Light.SWITCH_KEY, light.isSwitchOn());
                     root.setBoolean(Light.SWITCH_KEY, light.isSwitchOn());
 
 
-                    service.msg("\t\t" + Light.RESOURCE_NAME_KEY + ": " + light.getLightResourceName());
+                    service.msg("\t\t" + Light.RESOURCE_NAME_KEY + ": " + Light.RESOURCE_NAME_SWITCH);
                     service.msg("\t\t" + Light.SWITCH_KEY + ": " + light.isSwitchOn());
                     service.msg("\t\t" + Light.SWITCH_KEY + ": " + light.isSwitchOn());
                 } else if (Light.URI_DIMMING.equalsIgnoreCase(request.getResource().getUri())) {
                 } else if (Light.URI_DIMMING.equalsIgnoreCase(request.getResource().getUri())) {
                     // Dimming Optional Resource (read only)
                     // Dimming Optional Resource (read only)
-                    root.setTextString(Light.RESOURCE_NAME_KEY, light.getDimmingResourceName());
+                    root.setTextString(Light.RESOURCE_NAME_KEY, Light.RESOURCE_NAME_DIMMING);
                     // Dimming Required Resource (read write)
                     // Dimming Required Resource (read write)
                     root.setLong(Light.DIMMING_SETTING_KEY, (long)light.getDimmingLevel());
                     root.setLong(Light.DIMMING_SETTING_KEY, (long)light.getDimmingLevel());
                     // Dimming Optional Resources (read only)
                     // Dimming Optional Resources (read only)
                     root.setLong(Light.DIMMING_RANGE_KEY, (long)light.getDimmingRange());
                     root.setLong(Light.DIMMING_RANGE_KEY, (long)light.getDimmingRange());
                     root.setLong(Light.DIMMING_STEP_KEY, (long)light.getDimmingStep());
                     root.setLong(Light.DIMMING_STEP_KEY, (long)light.getDimmingStep());
 
 
-                    service.msg("\t\t" + Light.RESOURCE_NAME_KEY + ": " + light.getDimmingResourceName());
+                    service.msg("\t\t" + Light.RESOURCE_NAME_KEY + ": " + Light.RESOURCE_NAME_DIMMING);
                     service.msg("\t\t" + Light.DIMMING_SETTING_KEY + ": " + light.getDimmingLevel());
                     service.msg("\t\t" + Light.DIMMING_SETTING_KEY + ": " + light.getDimmingLevel());
                     service.msg("\t\t" + Light.DIMMING_RANGE_KEY + ": " + light.getDimmingRange());
                     service.msg("\t\t" + Light.DIMMING_RANGE_KEY + ": " + light.getDimmingRange());
                     service.msg("\t\t" + Light.DIMMING_STEP_KEY + ": " + light.getDimmingStep());
                     service.msg("\t\t" + Light.DIMMING_STEP_KEY + ": " + light.getDimmingStep());
+                } else if (Light.URI_COLORTMEP.equalsIgnoreCase(request.getResource().getUri())) {
+                    root.setTextString(Light.RESOURCE_NAME_KEY, Light.RESOURCE_NAME_COLORTMEP);
+                    root.setLong(Light.CT_KEY, (long)light.getColorTemperature());
+                    root.setLong(Light.CT_RANGE_KEY, (long)light.getCTRange());
+                    root.setLong(Light.CT_STEP_KEY, (long)light.getCTStep());
+
+                    service.msg("\t\t" + Light.RESOURCE_NAME_KEY + ": " + Light.RESOURCE_NAME_COLORTMEP);
+                    service.msg("\t\t" + Light.CT_KEY + ": " + light.getColorTemperature());
+                    service.msg("\t\t" + Light.CT_RANGE_KEY + ": " + light.getCTRange());
+                    service.msg("\t\t" + Light.CT_STEP_KEY + ": " + light.getCTStep());
+                } else if (Light.URI_ENERGY.equalsIgnoreCase(request.getResource().getUri())) {
+                    root.setTextString(Light.RESOURCE_NAME_KEY, Light.RESOURCE_NAME_ENERGY);
+                    root.setDouble(Light.POWER_KEY, (double)light.getPower());
+                    root.setDouble(Light.ENERGY_KEY, (double)light.getEnergy());
+
+                    service.msg("\t\t" + Light.RESOURCE_NAME_KEY + ": " + Light.RESOURCE_NAME_ENERGY);
+                    service.msg("\t\t" + Light.POWER_KEY + ": " + light.getPower());
+                    service.msg("\t\t" + Light.ENERGY_KEY + ": " + light.getEnergy());
                 }
                 }
                 break;
                 break;
             default:
             default:

+ 23 - 8
app/src/main/java/org/iotivity/bridge/homeserver/handler/server/PostLightRequestHandler.java

@@ -33,14 +33,29 @@ public class PostLightRequestHandler implements OCRequestHandler {
 
 
         OCRepresentation rep = request.getRequestPayload();
         OCRepresentation rep = request.getRequestPayload();
         while (rep != null) {
         while (rep != null) {
-            if (Light.SWITCH_KEY.equalsIgnoreCase(rep.getName())) {
-                light.setSwitchOn(rep.getValue().getBool());
-                service.msg("\t\t" + Light.SWITCH_KEY + ": " + light.isSwitchOn());
-            }
-
-            if (Light.DIMMING_SETTING_KEY.equalsIgnoreCase(rep.getName())) {
-                light.setDimmingLevel((int) rep.getValue().getInteger());
-                service.msg("\t\t" + Light.DIMMING_SETTING_KEY + ": " + light.getDimmingLevel());
+            if(request.getResource().getUri().equalsIgnoreCase(Light.URI_LIGHT)) {
+                if (Light.SWITCH_KEY.equalsIgnoreCase(rep.getName())) {
+                    light.setSwitchOn(rep.getValue().getBool());
+                    service.msg("\t\t" + Light.SWITCH_KEY + ": " + light.isSwitchOn());
+                }
+            } else if(request.getResource().getUri().equalsIgnoreCase(Light.URI_DIMMING)) {
+                if (Light.DIMMING_SETTING_KEY.equalsIgnoreCase(rep.getName())) {
+                    light.setDimmingLevel((int) rep.getValue().getInteger());
+                    service.msg("\t\t" + Light.DIMMING_SETTING_KEY + ": " + light.getDimmingLevel());
+                }
+            } else if(request.getResource().getUri().equalsIgnoreCase(Light.URI_COLORTMEP)) {
+                if (Light.CT_KEY.equalsIgnoreCase(rep.getName())) {
+                    light.setColorTemperature((int) rep.getValue().getInteger());
+                    service.msg("\t\t" + Light.CT_KEY + ": " + light.getColorTemperature());
+                }
+            } else if(request.getResource().getUri().equalsIgnoreCase(Light.URI_ENERGY)) {
+                if (Light.ENERGY_KEY.equalsIgnoreCase(rep.getName())) {
+                    light.setEnergy((double) rep.getValue().getDouble());
+                    service.msg("\t\t" + Light.ENERGY_KEY + ": " + light.getEnergy());
+                } else if (Light.POWER_KEY.equalsIgnoreCase(rep.getName())) {
+                    light.setPower((double) rep.getValue().getDouble());
+                    service.msg("\t\t" + Light.POWER_KEY + ": " + light.getPower());
+                }
             }
             }
             rep = rep.getNext();
             rep = rep.getNext();
         }
         }

+ 76 - 27
app/src/main/java/org/iotivity/bridge/homeserver/model/Light.java

@@ -5,34 +5,57 @@ import org.iotivity.OCEndpoint;
 public class Light {
 public class Light {
 
 
     // Device : oic.d.light
     // Device : oic.d.light
-    static public final String DT_LIGHT = "oic.d.light";
-    // Resources : oic.r.switch.binary, oic.r.light.dimming
-    static public final String RT_BINARYSWITCH = "oic.r.switch.binary";    // required
-    static public final String RT_DIMMING = "oic.r.light.dimming";    // optional
-    // Properties of BinarySwitch Resource(oic.r.switch.binary)
-    static public final String SWITCH_KEY = "value";    // required
-    // Properties of Dimming Resource(oic.r.light.dimming)
-    static public final String DIMMING_SETTING_KEY = "dimmingSetting"; // required
-    static public final String DIMMING_STEP_KEY = "step" ;  // optional, default 5
-    static public final String DIMMING_RANGE_KEY = "range" ; // optional, default [0, 100]
-    // Properties of light resource name
-    static public final String RESOURCE_NAME_KEY = "n" ;  // optional
+    public static final String DT_LIGHT = "oic.d.light";
+    // Resources of Device : oic.r.switch.binary, oic.r.light.dimming, oic.r.colour.colourtemperature, oic.r.energy.consumption
+    public static final String RT_BINARYSWITCH = "oic.r.switch.binary";             // required
+    public static final String RT_DIMMING = "oic.r.light.dimming";                  // optional
+    public static final String RT_COLORTEMP = "oic.r.colour.colourtemperature";     // optional
+    public static final String RT_ENERGY = "oic.r.energy.consumption";              // optional
 
 
     public static final String URI_LIGHT = "/light" ;
     public static final String URI_LIGHT = "/light" ;
     public static final String URI_DIMMING = "/dimming" ;
     public static final String URI_DIMMING = "/dimming" ;
+    public static final String URI_COLORTMEP = "/ColourTemperatureResURI" ;
+    public static final String URI_ENERGY = "/EnergyConsumptionResURI" ;
 
 
-    private String device_name;
+    // Properties of resource name
+    static public final String RESOURCE_NAME_KEY = "n" ;  // optional
+
+    public static final String RESOURCE_NAME_SWITCH = "Light Switch";  // Switch Binary resource Name
+    public static final String RESOURCE_NAME_DIMMING = "Dimming Control";  // Dimming resource Name
+    public static final String RESOURCE_NAME_COLORTMEP = "Color Temperature";  // Color Temperature resource Name
+    public static final String RESOURCE_NAME_ENERGY = "Energy Consumption";  // Energy Consumption resource Name
+
+    // Properties of BinarySwitch Resource(oic.r.switch.binary)
+    public static final String SWITCH_KEY = "value";    // required
+    // Properties of Dimming Resource(oic.r.light.dimming)
+    public static final String DIMMING_SETTING_KEY = "dimmingSetting"; // required
+    public static final String DIMMING_STEP_KEY = "step" ;  // optional, default 5
+    public static final String DIMMING_RANGE_KEY = "range" ; // optional, default [0, 100]
+
+    // Properties of Color Temperature Resource(oic.r.colour.colourtemperature)
+    public static final String CT_KEY = "ct"; // required
+    public static final String CT_STEP_KEY = "step" ;  // optional, default 5
+    public static final String CT_RANGE_KEY = "range" ; // optional, default [0, 1000] (?)
 
 
-    private String resource_name_light = "Light Switch";  // Dimming resource Name
-    private String resource_name_dimming = "Dimming Control";  // Dimming resource Name
+    // Properties of Color Temperature Resource(oic.r.colour.colourtemperature)
+    public static final String ENERGY_KEY = "energy"; // required
+    public static final String POWER_KEY = "power" ;  // required
+
+    private String device_name;
 
 
+    // Light Switch
     private boolean switch_value = false;   // default switch value : false
     private boolean switch_value = false;   // default switch value : false
+    // Dimming Control
     private int dimming_level = 30 ;        // default dimming level : 30
     private int dimming_level = 30 ;        // default dimming level : 30
     private int dimming_range = 100;        // dimming range : 0 ~ 99
     private int dimming_range = 100;        // dimming range : 0 ~ 99
     private int dimming_step = 10;          // dimming step : 10
     private int dimming_step = 10;          // dimming step : 10
-
-    //private OCEndpoint serverEndpoint;
-    //private String serverUri;
+    // Color Temperature
+    private int ct_value = 457 ;
+    private int ct_range = 1000 ;
+    private int ct_step = 1 ;
+    // Energy Consumption
+    private double power = 20.0 ;
+    private double energy = 350.4 ;
 
 
     public Light() {
     public Light() {
 
 
@@ -49,15 +72,6 @@ public class Light {
         device_name = name ;
         device_name = name ;
     }
     }
 
 
-    public String getLightResourceName() { return resource_name_light; }
-    public void setLightResourceName(String resource_name) {
-        this.resource_name_light = resource_name ;
-    }
-
-    public String getDimmingResourceName() { return resource_name_dimming; }
-    public void setDimmingResourceName(String resource_name) {
-        this.resource_name_dimming = resource_name ;
-    }
 
 
     public boolean isSwitchOn() {
     public boolean isSwitchOn() {
         return switch_value;
         return switch_value;
@@ -87,4 +101,39 @@ public class Light {
         this.dimming_range = range;
         this.dimming_range = range;
     }
     }
 
 
+    public int getColorTemperature() {
+        return ct_value;
+    }
+    public void setColorTemperature(int ct) {
+        this.ct_value = ct;
+    }
+
+    public int getCTStep() {
+        return ct_step;
+    }
+    public void setCTStep(int ct_step) {
+        this.ct_step = ct_step;
+    }
+
+    public int getCTRange() {
+        return ct_range;
+    }
+    public void setCTRange(int ct_range) {
+        this.ct_range = ct_range;
+    }
+
+    public double getPower() {
+        return power;
+    }
+    public void setPower(double current_power) {
+        this.power = current_power;
+    }
+
+    public double getEnergy() {
+        return energy;
+    }
+    public void setEnergy(double calulated_energy) {
+        this.energy = calulated_energy;
+    }
+
 }
 }