Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-15555

[fiware-stackoverflow] FIWARE - Android Leshan-based Client to LwM2MIoTAgent

    Details

      Description

      Created question in FIWARE Q/A platform on 11-03-2019 at 18:03
      Please, ANSWER this question AT https://stackoverflow.com/questions/55107058/fiware-android-leshan-based-client-to-lwm2miotagent

      Question:
      FIWARE - Android Leshan-based Client to LwM2MIoTAgent

      Description:
      My experiment consists of using an Android Client (https://github.com/ApplicationPlatformForIoT/LwM2MDemoClientAndroid) and make it interact with the FIWARE LwM2MIoT Agent (https://github.com/telefonicaid/lightweightm2m-iotagent)

      1) I am able to establish communication between the client and the Agent.

      2) I am NOT able to find the attributes I defined in the Android client;

      3) Hence, I can´t ensure the interaction between the client(s) and the broker (Update the attributes values, query the lazies values in the broker).

      =>===> Any hint to overcome this situation would be welcome!

      The main details of the experiments, I hope, are given in the SEVEN steps below.

      • ONE: I start by provisioning the following device: *

      {
      "count": 1,
      "devices": [
      {
      "device_id": "Illuminance",
      "service": "factory",
      "service_path": "/robots",
      "entity_name": "Robot:Illuminance",
      "entity_type": "Robot",
      "attributes": [

      { "object_id": "Value", "name": "Value", "type": "Float" }

      ],
      "lazy": [

      { "object_id": "Type", "name": "Type", "type": "String" }

      ],
      "commands": [],
      "static_attributes": [],
      "internal_attributes": {
      "lwm2mResourceMapping": {
      "Value":

      { "objectType": 3301, "objectInstance": 0, "objectResource": 5700 }

      ,
      "Application":

      { "objectType": 3301, "objectInstance": 0, "objectResource": 5750 }

      }
      }
      }
      ]
      }

      • TWO: I configured the device in the client Android as follows : *

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <LWM2M xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://openmobilealliance.org/tech/profiles/LWM2M.xsd">
      <Object ObjectType="MODefinition">
      <Name>Illuminance</Name>
      <Description1>Illuminance sensor, example units = lx</Description1>
      <ObjectID>3301</ObjectID>
      <ObjectURN>urn:oma:lwm2m:ext:3301</ObjectURN>
      <MultipleInstances>Multiple</MultipleInstances>
      <Mandatory>Optional</Mandatory>
      <MandatoryBoolean>false</MandatoryBoolean>
      <Resources>
      <Item ID="5700">
      <Name>Sensor Value</Name>
      <Operations>R</Operations>
      <MultipleInstances>Single</MultipleInstances>
      <Mandatory>Mandatory</Mandatory>
      <MandatoryBoolean>true</MandatoryBoolean>
      <Type>Float</Type>
      <RangeEnumeration/>
      <Units>Defined by “Units” resource.</Units>
      <Description>The current value of the luminosity sensor.</Description>
      </Item>
      <Item ID="5750">
      <Name>Application Type</Name>
      <Operations>RW</Operations>
      <MultipleInstances>Single</MultipleInstances>
      <Mandatory>Optional</Mandatory>
      <MandatoryBoolean>false</MandatoryBoolean>
      <Type>String</Type>
      <RangeEnumeration/>
      <Units/>
      <Description>The application type of the sensor or actuator as a string, for instance "Air Pressure".</Description>
      </Item>
      </Resources>
      <Description2/>
      </Object>
      </LWM2M>

      • THREE: My java file for the sensor is : *

      public class Illuminance extends GenericSensor implements SensorEventListener {
      public static final String TAG = "Illuminance";
      public static final int ID = 3301;
      private SensorManager sensorManager;
      private TextView txtIlluminance;
      private Handler handler;
      private long latestMeasurement = 0;
      private String application;

      public Illuminance(int instanceId, SensorManager sensorManager, TextView txtIlluminance)

      { super(instanceId); this.txtIlluminance = txtIlluminance; this.sensorManager = sensorManager; super.setUnits("lx"); handler = new Handler(); }

      @Override
      public void start() {
      Sensor lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
      if(lightSensor != null)

      { sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL); setMaxRangeValue(lightSensor.getMaximumRange()); setMinRangeValue(lightSensor.getMinDelay()); }

      else

      { Log.d(TAG, "No light sensor found."); }

      }
      @Override
      public ReadResponse read(int resourceid) {
      switch (resourceid)

      { case 5700: //sensor value return ReadResponse.success(resourceid, getSensorValue()); case 5750: // return ReadResponse.success(resourceid, getApplication()); default: return super.read(resourceid); }

      }

      @Override
      public WriteResponse write(int resourceid, LwM2mResource value) {
      switch (resourceid)

      { case 5750: setApplication((String) value.getValue()); fireResourcesChange(resourceid); return WriteResponse.success(); default: return super.write(resourceid, value); }

      }

      @Override
      public void stop()

      { sensorManager.unregisterListener(this); }

      public double getSensorValue()

      { return latestMeasurement; }

      private void setApplication(String t)

      { application = t; }

      public String getApplication()

      { return application; }

      @Override
      public void onSensorChanged(final SensorEvent event) {
      if(System.currentTimeMillis() - latestMeasurement > 10000) {
      Log.v(TAG, "Light value: " + event.values[0]);
      setValue(event.values[0]);
      handler.post(new Runnable() {
      public void run()

      { txtIlluminance.setText(Float.toString(event.values[0])); }

      });
      latestMeasurement = System.currentTimeMillis();
      }
      }

      @Override
      public void onAccuracyChanged(Sensor sensor, int accuracy) {

      }
      }

      • FOUR: As or the "init" method in the MAin Activity, I have the following configurations in he original Android code: *

      // Instance of sensor service
      SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

      // Leveraged EB sensors

      Illuminance illuminance = new Illuminance(0, sensorManager, txtIlluminance);
      addSmartObject(illuminance);

      //Parse xml into java by
      //Loading the .xml raw resource models into a single List of ObjectModels

      List<ObjectModel> models = ObjectLoader.loadDefault();
      InputStream is = getResources().openRawResource(R.raw.illuminance);
      ObjectModel oModel = ObjectLoader.loadDdfFile(is, "modelstream");
      models.add(oModel);

          • FIVE. When I connect the Andoid client device to the Server, it is registered but I can´t find my Active , neither the LAzy attributes. ***
      {"op":"LWM2MLib.COAPRouter","time":"2019-03-11T11:39:49.836Z","lvl":"DEBUG","msg":"Handling request with method [POST] on url [/rd?b=U&lwm2m=1.0&lt=3600&ep=Illuminance] with messageId [50]"} {"op":"LWM2MLib.COAPUtils","time":"2019-03-11T11:39:49.837Z","lvl":"DEBUG","msg":"Extracting query parameters from request"} {"op":"LWM2MLib.COAPUtils","time":"2019-03-11T11:39:49.838Z","lvl":"DEBUG","msg":"Processing query [b=U&lwm2m=1.0&lt=3600&ep=Illuminance]"} {"op":"LWM2MLib.Registration","time":"2019-03-11T11:39:49.839Z","lvl":"DEBUG","msg":"Handling registration request"} {"op":"LWM2MLib.COAPUtils","time":"2019-03-11T11:39:49.840Z","lvl":"DEBUG","msg":"Checking for the existence of the following parameters [[\"ep\"]]"}

      {"op":"LWM2MLib.Registration","time":"2019-03-11T11:39:49.841Z","lvl":"DEBUG","msg":"Storing the following device in the db:\n

      {\n \"name\": \"Illuminance\",\n \"lifetime\": \"3600\",\n \"address\": \"10.3.1.121\",\n \"port\": 5683,\n \"creationDate\": \"2019-03-11T11:39:49.841Z\"\n}

      "}

      {"op":"LWM2MLib.Registration","time":"2019-03-11T11:39:49.842Z","lvl":"DEBUG","msg":"Registered device [Illuminance] with type [Robot]"} {"op":"LWM2MLib.Registration","time":"2019-03-11T11:39:49.844Z","lvl":"DEBUG","msg":"Calling user handler for registration actions for device [Illuminance]"} {"op":"IOTAgent.LWM2MHandlers","time":"2019-03-11T11:39:49.845Z","lvl":"DEBUG","msg":"Handling registration of the device"}

      time=2019-03-11T11:39:49.847Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.MongoDBGroupRegister | srv=n/a | subsrv=n/a | msg=Looking for group params ["resource","apikey"] with queryObj {} | comp=IoTAgent
      time=2019-03-11T11:39:49.859Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.MongoDBGroupRegister | srv=n/a | subsrv=n/a | msg=Device group for fields [["resource","apikey"]] not found: [{}] | comp=IoTAgent
      time=2019-03-11T11:39:49.861Z | lvl=ERROR | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.Alarms | srv=n/a | subsrv=n/a | msg=Raising [MONGO-ALARM]:

      {"name":"DEVICE_GROUP_NOT_FOUND","message":"Couldn\t find device group","code":404}

      | comp=IoTAgent
      time=2019-03-11T11:39:49.863Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=n/a | subsrv=n/a | msg=Looking for device with id [Illuminance]. | comp=IoTAgent
      time=2019-03-11T11:39:49.878Z | lvl=ERROR | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.Alarms | srv=n/a | subsrv=n/a | msg=Releasing [MONGO-ALARM] | comp=IoTAgent

      {"op":"IOTAgent.LWM2MHandlers","time":"2019-03-11T11:39:49.880Z","lvl":"DEBUG","msg":"Preregistered device found."}

      time=2019-03-11T11:39:49.882Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.DeviceService | srv=n/a | subsrv=n/a | msg=Update provisioned device in Device Service | comp=IoTAgent
      time=2019-03-11T11:39:49.883Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=n/a | subsrv=n/a | msg=Looking for device with id [Illuminance]. | comp=IoTAgent
      time=2019-03-11T11:39:49.888Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.DeviceService | srv=n/a | subsrv=n/a | msg=Creating initial entity in the Context Broker:
      {
      "url": "http://orionunified:1026/v1/updateContext",
      "method": "POST",
      "json": {
      "contextElements": [

      { "type": "Robot", "isPattern": "false", "id": "Robot:Illuminance", "attributes": [] }

      ],
      "updateAction": "APPEND"
      },
      "headers":

      { "fiware-service": "factory", "fiware-servicepath": "/robots", "fiware-correlator": "78d63062-e5c9-4fde-b6b8-db73adc5a003" }

      } | comp=IoTAgent
      time=2019-03-11T11:39:49.917Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.DeviceService | srv=n/a | subsrv=n/a | msg=Initial entity created successfully. | comp=IoTAgent
      time=2019-03-11T11:39:49.920Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.DeviceService | srv=n/a | subsrv=n/a | msg=Sending device registrations to Context Broker at http://orionunified:1026/NGSI9/registerContext | comp=IoTAgent
      time=2019-03-11T11:39:49.922Z | lvl=DEBUG | corr=78d63062-e5c9-4fde-b6b8-db73adc5a003 | trans=78d63062-e5c9-4fde-b6b8-db73adc5a003 | op=IoTAgentNGSI.DeviceService | srv=n/a | subsrv=n/a | msg=Using the following request:

      {
      "url": "http://orionunified:1026/NGSI9/registerContext",
      "method": "POST",
      "json": {
      "contextRegistrations": [
      {
      "entities": [

      { "type": "Robot", "isPattern": "false", "id": "Robot:Illuminance" }

      ],
      "attributes": [

      { "name": "Application Type", "type": "String" }

      ,

      { "name": "Short Server ID", "type": "Integer" }

      ,

      { "name": "Lifetime", "type": "Integer" }

      ,

      { "name": "Default Minimum Period", "type": "Integer" }

      ,

      { "name": "Default Maximum Period", "type": "Integer" }

      ,

      { "name": "Disable", "type": "" }

      ,

      { "name": "Disable Timeout", "type": "Integer" }

      ,

      { "name": "Notification Storing When Disabled or Offline", "type": "Boolean" }

      ,

      { "name": "Binding", "type": "String" }

      ,

      { "name": "Registration Update Trigger", "type": "" }

      ,

      { "name": "Luminosity Sensor#0", "type": "string" }

      ],
      "providingApplication": "http://idaslwm2m:4041"
      }
      ],
      "duration": "P1Y",
      "registrationId": "5c8642fa684ccedc01ce71bf"
      },
      "headers":

      { "fiware-service": "factory", "fiware-servicepath": "/robots" }

      }

      • SIX : Via wireshark, I also noticed that the Android client payload is "application/link-format" when connecting to the server and " application/vnd.oma.lwm2m+tlv" when transfering the data. *

      DEVICE CONNECTION TO THE SERVER

      Frame 21417: 129 bytes on wire (1032 bits), 129 bytes captured (1032 bits) on interface 0
      Ethernet II, Src: TctMobil_3b:1e:48 (d0:9d:ab:3b:1e:48), Dst: Vmware_11:0a:d0 (00:0c:29:11:0a:d0)
      Internet Protocol Version 4, Src: 10.3.1.121, Dst: 10.3.3.43
      User Datagram Protocol, Src Port: 5684, Dst Port: 5683
      Constrained Application Protocol, Confirmable, POST, MID:390
      01.. .... = Version: 1
      ..00 .... = Type: Confirmable (0)
      .... 1000 = Token Length: 8
      Code: POST (2)
      Message ID: 390
      Token: 41542d95d7dde946
      Opt Name: #1: Uri-Path: rd
      Opt Name: #2: Content-Format: application/link-format
      Opt Name: #3: Uri-Query: b=U
      Opt Name: #4: Uri-Query: lwm2m=1.0
      Opt Name: #5: Uri-Query: lt=3600
      Opt Name: #6: Uri-Query: ep=robot2
      End of options marker: 255
      [Response In: 21439]
      [Uri-Path: /rd]
      Payload: Payload Content-Format: application/link-format, Length: 37
      Payload Desc: application/link-format
      [Payload Length: 37]

      DATA TRANSFERT

      Frame 23950: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
      Ethernet II, Src: TctMobil_3b:1e:48 (d0:9d:ab:3b:1e:48), Dst: Vmware_11:0a:d0 (00:0c:29:11:0a:d0)
      Internet Protocol Version 4, Src: 10.3.1.121, Dst: 10.3.3.43
      User Datagram Protocol, Src Port: 5684, Dst Port: 5683
      Constrained Application Protocol, Non-Confirmable, 2.05 Content, MID:398
      01.. .... = Version: 1
      ..01 .... = Type: Non-Confirmable (1)
      .... 0100 = Token Length: 4
      Code: 2.05 Content (69)
      Message ID: 398
      Token: 115744a3
      Opt Name: #1: Observe: 36
      Opt Name: #2: Content-Format: application/vnd.oma.lwm2m+tlv
      End of options marker: 255
      [Request In: 22145]
      [Response Time: 99.920193000 seconds]
      [Uri-Path: /3301/0/5700]
      Payload: Payload Content-Format: application/vnd.oma.lwm2m+tlv, Length: 12
      Payload Desc: application/vnd.oma.lwm2m+tlv
      [Payload Length: 12]
      Lightweight M2M TLV (1 element)

      DEVICE CONNECTION TO THE SERVER

      Frame 14476: 112 bytes on wire (896 bits), 112 bytes captured (896 bits) on interface 0
      Ethernet II, Src: fa:16:3e:25:bf:4a (fa:16:3e:25:bf:4a), Dst: Vmware_11:0a:d0 (00:0c:29:11:0a:d0)
      Internet Protocol Version 4, Src: 10.3.4.22, Dst: 10.3.3.43
      User Datagram Protocol, Src Port: 43649, Dst Port: 5683
      Constrained Application Protocol, Confirmable, POST, MID:62716
      01.. .... = Version: 1
      ..00 .... = Type: Confirmable (0)
      .... 0100 = Token Length: 4
      Code: POST (2)
      Message ID: 62716
      Token: 6d4d85f8
      Opt Name: #1: Uri-Path: rd
      Opt Name: #2: Uri-Query: ep=Illuminance
      Opt Name: #3: Uri-Query: lt=85671
      Opt Name: #4: Uri-Query: lwm2m=1.0
      Opt Name: #5: Uri-Query: b=U
      End of options marker: 255
      [Response In: 14496]
      [Uri-Path: /rd]
      Payload: Payload Content-Format: application/octet-stream (no Content-Format), Length: 1
      Payload Desc: application/octet-stream
      [Payload Length: 19]
      Data (19 bytes)
      Data: 3c2f333333332f303e2c3c2f333330312f303e
      [Length: 19]

      DATA TRANSFERT

      Frame 25895: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
      Ethernet II, Src: fa:16:3e:25:bf:4a (fa:16:3e:25:bf:4a), Dst: Vmware_11:0a:d0 (00:0c:29:11:0a:d0)
      Internet Protocol Version 4, Src: 10.3.4.22, Dst: 10.3.3.43
      User Datagram Protocol, Src Port: 43649, Dst Port: 5683
      Constrained Application Protocol, Acknowledgement, 2.05 Content, MID:23556
      01.. .... = Version: 1
      ..10 .... = Type: Acknowledgement (2)
      .... 0100 = Token Length: 4
      Code: 2.05 Content (69)
      Message ID: 23556
      Token: 958d27cd
      End of options marker: 255
      [Request In: 25865]
      [Response Time: 0.003624000 seconds]
      [Uri-Path: /3301/0/5700]
      Payload: Payload Content-Format: application/octet-stream (no Content-Format), Length: 3
      Payload Desc: application/octet-stream
      [Payload Length: 3]
      Data (3 bytes)
      Data: 333035
      [Length: 3]

      • EIGHT=> entilties it broker before and After connecting the client (connect serverIP 5684 Illuminance /) *

      {
      "id": "Robot:Illuminance",
      "type": "Robot",
      "Value": {
      "type": "Float",
      "value": " ",
      "metadata": {}
      }
      }

        Activity

        Hide
        backlogmanager Backlog Manager added a comment -

        2019-03-11 21:05|CREATED monitor | # answers= 0, accepted answer= False

        Show
        backlogmanager Backlog Manager added a comment - 2019-03-11 21:05|CREATED monitor | # answers= 0, accepted answer= False

          People

          • Assignee:
            fermin Fermín Galán
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: