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 31 forks source link

Problem with configuration group for devices #113

Open pasquy73 opened 6 years ago

pasquy73 commented 6 years ago

Hi all, I'm testing the configuration provisioning at this link https://github.com/Fiware/iot.IoTagent-LWM2M/blob/1cdf6abc96654aca2f912cad01d5fdfcd21d7ec8/docs/configurationProvisioning.md and I'm using the configuration group for devices with type WeatherBaloon. I noticed that there was a change from 'attributes' to 'active' in the payload of REST call (curl localhost:4041/iot/services ...) and my old test doesn't work.

I'm not sure if this is the right solution, but I've added back 'registeredDevice.attributes' in the commonLwm2m.js file as follow:

if (registeredDevice.active) {
    activeAttributes = registeredDevice.active;
}else if (registeredDevice.attributes) {
    activeAttributes = registeredDevice.attributes;
} else if (commons.getConfig().ngsi.types[registeredDevice.type]) {
    activeAttributes = commons.getConfig().ngsi.types[registeredDevice.type].attributes;
}

So with these changes, my tests work for both service and device (https://github.com/Fiware/iot.IoTagent-LWM2M/blob/1cdf6abc96654aca2f912cad01d5fdfcd21d7ec8/docs/deviceProvisioning.md) configuration. Please let me know if I'm right or not.

fgalan commented 6 years ago

Did grunt test goes ok after the proposed change?

pasquy73 commented 6 years ago

I'm using the doc: I start the IoT Agent (node bin/lwm2mAgent.js) with my configuration and I run my JS Client to create/update object and connect to the server ... the same steps that the doc provides (LWM2M-Client> ...)

fgalan commented 6 years ago

Maybe I'm not making my point clearly... :)

Apart from the test you describe, note this repository includes a set of unit tests that act as regression for any new change. The command grunt test runs this regressions and reports any potencial error.

(Note however this is a necessary but not sufficient condition. Unit tests are not perfect and doesn't cover all the possible cases so grunt test could be ok and the modification of the code introduce some bug/issue. However, let's have at least that minimal check).

If the grunt test goes ok, I'd suggest as next step you create a pull request with the proposed change. Eventually that PR will be reviewed and merged.

Thanks!

dcalvoalonso commented 6 years ago

Dear @pasquy73,

I think that the problem is that https://github.com/Fiware/iot.IoTagent-LWM2M/blob/1cdf6abc96654aca2f912cad01d5fdfcd21d7ec8/docs/configurationProvisioning.md is not updated.

As you can see in the reference documentation for the IoT Agents https://github.com/telefonicaid/iotagent-node-lib#configurationapi, the payload field to define active attributes is now active.

Could you please check if the example works using active instead of attributes? If it does, I will submit a PR to upload the example.

Thanks in advance and BR.

Daniel

pasquy73 commented 6 years ago

Here the installation and execution steps of my test on my Win7 with active attribute in the payload for "Power Control" in configuration provisioning and no change in the commonLwm2m.js (only registeredDevice.active):

git clone https://github.com/Fiware/iot.IoTagent-LWM2M.git
cd iot.IoTagent-LWM2M
npm install

start the server node bin/lwm2mAgent.js config-blank.js

git clone https://github.com/telefonicaid/lwm2m-node-lib.git
cd lwm2m-node-lib
npm install

start the client node bin/iotagent-lwm2m-client.js

run the test 1) configuration provisioning (https://github.com/Fiware/iot.IoTagent-LWM2M/blob/1cdf6abc96654aca2f912cad01d5fdfcd21d7ec8/docs/configurationProvisioning.md):

LWM2M-Client> create /6/0
LWM2M-Client> create /3303/0
LWM2M-Client> create /3312/0
LWM2M-Client> set /6/0 0 12
LWM2M-Client> set /6/0 1 -4
LWM2M-Client> set /3303/0 0 23
LWM2M-Client> set /3312/0 0 On

connection LWM2M-Client> connect localhost 5684 weather1 /weatherBaloon

test in orion curl -v http://orion:1026/v2/entities/weather1:WeatherBaloon -s -S --header "fiware-service: smartGondor" --header "fiware-servicepath: /gardens"

response (Power Control empty - I expected "On" value) {"id":"weather1:WeatherBaloon","type":"WeatherBaloon","Power Control":{"type":"Boolean","value":" ","metadata":{}}}

2) device provisioning (https://github.com/Fiware/iot.IoTagent-LWM2M/blob/1cdf6abc96654aca2f912cad01d5fdfcd21d7ec8/docs/deviceProvisioning.md)

bin/iotagent-lwm2m-client.js

LWM2M-Client> create /7392/0

LWM2M-Client> set /7392/0 1 89
LWM2M-Client> set /7392/0 2 "First robot here"
LWM2M-Client> set /7392/0 3 "[0, 0]"

connection LWM2M-Client> connect localhost 5684 robot1 /

update battery attribute: LWM2M-Client> set /7392/0 1 67

curl -v http://orion:1026/v2/entities/Robot:robot1/attrs/Battery -s -S --header "fiware-service: smartGondor" --header "fiware-servicepath: /gardens"

response (OK) {"type":"number","value":"67","metadata":{}}

Please note that both the tests I've this error: ... An error occurred creating COAP Listener: {"code":"EACCES", "errno":"EACCES","syscall":"bind","address":"0.0.0.0","port":53517} but at the end ... ... COAP Server started successfully

pasquy73 commented 6 years ago

Anyway, if I use the LWM2M 0.3.0, then my test works both device and service provisioning:

git clone https://github.com/Fiware/iot.IoTagent-LWM2M.git iot.IoTagent-LWM2M-0.3.0 --branch 0.3.0 --single-branch

fgalan commented 6 years ago

Fixed by PR https://github.com/telefonicaid/lightweightm2m-iotagent/pull/119

fgalan commented 6 years ago

PR #119 has been merged into master and we understand this issue is solved (so the issue is closed). Could you confirm @pasquy73 ?

pasquy73 commented 6 years ago

Hi all, I repeated the test above and it doesn't still work, but the query to orion provides: {"error":"NotFound","description":"The requested entity has not been found. Check type and id"}

fgalan commented 6 years ago

@pasquy73 thanks for the report. I'm reopening the issue.

@dcalvoalonso , as author of the PR that addressed this issue (PR #119), what do you think on this?

dcalvoalonso commented 6 years ago

Hi @pasquy73 , could you please confirm that you are using FIWARE service and subservice with lowercases in all the requests? It would be also good that you delete old MongoDB databases.

pasquy73 commented 6 years ago

Hi Alonso, yes I'm using lowercase for service and subservice; I deleted the data in mongo (/iot/services?apikey=&resource=/weatherBaloon), I tried both config-blank (deviceRegistry = memory) and with mongo.

My provisioning is a POST to /iot/services (you can try my example above using the config-blank):

"services":[  
      {  
         "resource":"/weatherBaloon",
         "apikey":"",
         "type":"WeatherBaloon",
         "commands":[],
         "lazy":[  
            {  
               "name":"Longitude",
               "type":"double"
            },
            {  
               "name":"Latitude",
               "type":"double"
            },
            {  
               "name":"Temperature Sensor",
               "type":"degrees"
            }
         ],
         "active":[  
            {  
               "name":"Power Control",
               "type":"Boolean"
            }
         ]
      }
   ]
} 
fgalan commented 6 years ago

@pasquy73 for reference... which exact version of IOTA are you usring? I mean, the githash corresponding to the version you are using for testing.

pasquy73 commented 6 years ago

I'm not sure to understand your request; I used git clone https://github.com/Fiware/iot.IoTagent-LWM2M.git and it's master. I also saw that https://github.com/telefonicaid/lightweightm2m-iotagent.git is a mirror of https://github.com/Fiware/iot.IoTagent-LWM2M.git. Anyway in my '.git/refs/heads' folder I've a master file with: f97f62bb872a3e0e94b087eeb1cc3e26dfe75207

dcalvoalonso commented 6 years ago

@pasquy73 , in order to send the query to the CB are you using the following request?

curl -s -S --header 'Content-Type: application/json' \
  --header 'Accept: application/json' --header 'fiware-service: weather' --header 'fiware-servicepath: /baloons' -d '
{ 
    "entities": [
        {
            "type": "WeatherBaloon",
            "isPattern": "false",
            "id": "weather1:WeatherBaloon"
        }
    ],
    "attributes" : [
        "Latitude"
    ]    
}

' 'http://localhost:1026/v1/queryContext'
fgalan commented 6 years ago

Anyway in my '.git/refs/heads' folder I've a master file with: f97f62bb872a3e0e94b087eeb1cc3e26dfe75207

That's the githash I were referring. Thanks!

(Another way of getting it is running git log | head -n 1 in your working copy)

letavia commented 5 years ago

Any update on this issue? I tried with the latest docker image on fiware/lightweightm2m-iotagent repo, using "active" instead of "attributes" in the payload for device provisioning, but when I checked in the database, it was not recorded, there were only lazy and commands attributes.

fgalan commented 5 years ago

@letavia is your last comment in this issue related with what you mentions here: https://github.com/telefonicaid/lightweightm2m-iotagent/issues/112#issuecomment-486260958 ?

letavia commented 5 years ago

Yes, and I will continue in issue #112.