telefonicaid / lightweightm2m-iotagent

IoT Agent accepting COAP requests. Designed to be a bridge between the OMA Lightweight M2M protocol and the NGSI interface.
https://fiware-iotagent-lwm2m.rtfd.io/
GNU Affero General Public License v3.0
24 stars 30 forks source link

Information Report Problem: IoTAgent cannot observe desired resource #175

Closed arilwan closed 5 years ago

arilwan commented 5 years ago

I am trying to observe temperature changes from my LWM2M client.

  1. I provisioned the device as follows:
    [root@fiware fiware]# curl -X POST \
    >   http://localhost:4041/iot/devices \
    >   -H 'Content-Type: application/json' \
    >   -H 'fiware-service: smartGondor' \
    >   -H 'fiware-servicepath: /gardens' \
    >   -d '{
    >     "devices": [{
    >         "device_id": "raspiSensorTV",
    >         "entity_type": "Device",
    >         "attributes": [{
    >             "object_id": "Temperature Sensor",
    >             "name": "Temperature Sensor",
    >             "type": "Float"
    >         }]
    >     }]
    > }'
    {}[root@fiware fiware]#
  2. Then start the LwM2M client running, At this stage, Agent log shows it is observing /3303/0/0. However, the resource I want to observe, which is explicitly declared in my 3303 object is 5700 i.e. /3303/0/5700. Agent log:
    time=2019-02-15T11:15:31.452Z | lvl=DEBUG | corr=8d177c69-ae8d-4f50-81a7-b997f1cd7186 | trans=8d177c69-ae8d-4f50-81a7-b997f1cd7186 | op=IoTAgentNGSI.DeviceService | srv=n/a | subsrv=n/a | msg=Registration success. | comp=IoTAgent
    time=2019-02-15T11:15:31.454Z | lvl=DEBUG | corr=8d177c69-ae8d-4f50-81a7-b997f1cd7186 | trans=8d177c69-ae8d-4f50-81a7-b997f1cd7186 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=n/a | subsrv=n/a | msg=Looking for device with id [raspiSensorTV]. | comp=IoTAgent
    time=2019-02-15T11:15:31.487Z | lvl=DEBUG | corr=n/a | trans=n/a | op=LWM2MLib.Registration | msg=Registration request ended successfully
    time=2019-02-15T11:15:31.537Z | lvl=DEBUG | corr=n/a | trans=n/a | op=LWM2MLib.InformationReporting | msg=Observing value from resource /3303/0/0 in device [1]

    As you can see, the Agent is observing a wrong resource /3303/0/0instead of /3303/0/5700. After like 3-4minutes, the Agent then reports following error in the log: {"time":"2019-02-15T11:19:38.548Z","lvl":"ERROR","msg":"Could not complete the observer creation processes due to the following error: [object Object]"} Client then stopped. Client's log:

    
    [transaction_step:433] Entering
    [lwm2m_step:478] Final timeoutP: 124592845859279952
    [lwm2m_step:480] Final state: STATE_READY
    -> State: STATE_READY
    18 bytes received from [193.136.29.17]:53151
    44 01 1C 96  A8 32 DB B2  60 54 33 33  30 33 01 30   D....2..`T3303.0
    01 30                                                .0
    [lwm2m_handle_packet:209] Entering
    [lwm2m_handle_packet:214] Parsed: ver 1, type 0, tkl 4, code 0.01, mid 7318, Content type: 0
    [lwm2m_handle_packet:215] Payload:
    [handle_request:114] Entering
    [uri_decode:102] altPath: "(null)"
    [uri_decode:198] /3303/0/0
    [dm_handleRequest:171] Code: 01, server status: STATE_REGISTERED
    [dm_handleRequest:172] /3303/0/0
    [object_readData:141] /3303/0/0
    [lwm2m_data_new:143] size: 1
    [lwm2m_resource_value_changed:447] /3303/0/5700
    Segmentation fault
As you can see, client's log shows agent is following resource `/3303/0/0`. And immediately the client makes a `lwm2m_resource_value_changed` call to notify Agent of temperature change, it breaks with `Segmentation fault`report.
What could be responsible for this please? 
Device with Agent at device provision stage (i.e before starting client)

[root@fiware fiware]# curl -X GET 'http://localhost:4041/iot/devices' -H 'fiware-service: smartGondor' -H 'fiware-servicepath: /gardens' {"count":1,"devices":[{"device_id":"raspiSensorTV","service":"smartGondor","service_path":"/gardens","entity_name":"Device:raspiSensorTV","entity_type":"Device","attributes":[{"object_id":"Temperature Sensor","name":"Temperature Sensor","type":"Float"}],"lazy":[],"commands":[],"static_attributes":[]}]}

Device with Agent when client is started:

[root@fiware fiware]# curl -X GET 'http://localhost:4041/iot/devices' -H 'fiware-service: smartGondor' -H 'fiware-servicepath: /gardens' {"count":1,"devices":[{"device_id":"raspiSensorTV","service":"smartGondor","service_path":"/gardens","entity_name":"Device:raspiSensorTV","entity_type":"Device","attributes":[{"object_id":"Temperature Sensor","name":"Temperature Sensor","type":"Float"}],"lazy":[{"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":"Object ID","type":"Integer"},{"name":"Object Instance ID","type":"Integer"},{"name":"ACL","type":"Integer"},{"name":"Access Control Owner","type":"Integer"},{"name":"Manufacturer","type":"String"},{"name":"Model Number","type":"String"},{"name":"Serial Number","type":"String"},{"name":"Firmware Version","type":"String"},{"name":"Reboot","type":""},{"name":"Factory Reset","type":""},{"name":"Available Power Sources","type":"Integer"},{"name":"Power Source Voltage","type":"Integer"},{"name":"Power Source Current","type":"Integer"},{"name":"Battery Level","type":"Integer"},{"name":"Memory Free","type":"Integer"},{"name":"Error Code","type":"Integer"},{"name":"Reset Error Code","type":""},{"name":"Current Time","type":"Time"},{"name":"UTC Offset","type":"String"},{"name":"Timezone","type":"String"},{"name":"Supported Binding and Modes","type":"String"},{"name":"Network Bearer","type":"Integer"},{"name":"Available Network Bearer","type":"Integer"},{"name":"Radio Signal Strength","type":"Integer"},{"name":"Link Quality","type":"Integer"},{"name":"IP Addresses","type":"String"},{"name":"Router IP Addresse","type":"String"},{"name":"Link Utilization","type":"Integer"},{"name":"APN","type":"String"},{"name":"Cell ID","type":"Integer"},{"name":"SMNC","type":"Integer"},{"name":"SMCC","type":"Integer"},{"name":"Package","type":"Opaque"},{"name":"Package URI","type":"String"},{"name":"Update","type":""},{"name":"State","type":"Integer"},{"name":"Update Supported Objects","type":"Boolean"},{"name":"Update Result","type":"Integer"},{"name":"Latitude","type":"String"},{"name":"Longitude","type":"String"},{"name":"Altitude","type":"String"},{"name":"Uncertainty","type":"String"},{"name":"Velocity","type":"Opaque"},{"name":"Timestamp","type":"Time"},{"name":"SMS Tx Counter","type":"Integer"},{"name":"SMS Rx Counter","type":"Integer"},{"name":"Tx Data","type":"Integer"},{"name":"Rx Data","type":"Integer"},{"name":"Max Message Size","type":"Integer"},{"name":"Average Message Size","type":"Integer"},{"name":"StartOrReset","type":""},{"name":"Temperature Sensor#0","type":"string"}],"commands":[],"static_attributes":[]}]}


You may notice from above, after client starts, I have` attributes":[{"object_id":"Temperature Sensor","name":"Temperature Sensor","type":"Float"}]` and then in the lazy attributes `"lazy":[...,{"name":"Temperature Sensor#0","type":"string"}],"commands":[],"static_attributes":[]}]`. Is this the responsible for the problem?
arilwan commented 5 years ago

@dcalvoalonso Do you please understand why I have this problem?

arilwan commented 5 years ago

I tried changing the value of resource that Agent is currently observing (from client terminal) , that too isn't permissible, as shown below:

>change /3303/0/0 35
buffer = /3303/0/0 35
[lwm2m_stringToUri:215] buffer_len: 9, buffer: "/3303/0/0"
[lwm2m_stringToUri:268] Parsed characters: 9
[lwm2m_stringToUri:269] /3303/0/0
write not supported for specified resource!
arilwan commented 5 years ago

This issue is solved using resource internal mapping on device provision as shown below: time=2019-02-15T15:59:52.832Z | lvl=DEBUG | corr=n/a | trans=n/a | op=LWM2MLib.InformationReporting | msg=Observing value from resource /3303/0/5700 in device [1] Issue closed.