telefonicaid / iotagent-node-lib

Module to enable IoT Agent developers to build custom agents for their devices that can easily connect to NGSI Context Brokers
https://iotagent-node-lib.rtfd.io/
GNU Affero General Public License v3.0
60 stars 88 forks source link

Provisioning an Individual Device with GeoJson Attribute #961

Open rezendel opened 3 years ago

rezendel commented 3 years ago

Hello,

I am trying to integrate a device with the maps widget on wirecloud.(mashups). I want to make sure that the data format is right

Is this the right syntax when provisioning a device?

      sudo curl -iX POST \
  'http://localhost:4041/iot/devices' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
 "devices": [
   {
     "device_id":   "gps0022",
     "entity_name": "urn:ngsi-ld:Gps:0022",
     "entity_type": "Gps18",
     "transport":   "MQTT",
     "timezone":    "America/Sao_Paulo",
     "attributes": [
       **{ "object_id": "l", "name":"coordinates","type":"Point"}**
     ]
   }
 ]
}'

I get this result:

 {
  "id":"urn:ngsi-ld:Gps:0023",
  "type":"Gps18",
  "TimeInstant":{
    "type":"DateTime",
    "value":"2020-12-10T16:33:13.366Z",
    "metadata":{}
        },
  **"coordinates":{
    "type":"Point",
    "value":[10.2424,45.5642],**
    "metadata":{"TimeInstant":{"type":"DateTime","value":"2020-12-10T16:33:13.366Z"}}}}

I have also tried the following:

     **{ "object_id": "l", "name":"location","type":"Geojson"}**

then the result is:

{"id":"urn:ngsi-ld:Gps:0023","type":"Gps18","TimeInstant":{"type":"DateTime","value":"2020-12-10T17:58:21.706Z","metadata":{}},

          **"location":{"type":"Geojson",
           "value":[66.2424,45.5642],**
                      "metadata":{"TimeInstant":{"type":"DateTime","value":"2020-12-10T17:58:21.706Z"}}}}
**note: geo.json didn't work**

the geolocation attribute structure is different from the example the fiware documentation.

 **"location": {
        "type": "geo:json",
        "value": {
             "type": "Point",
             "coordinates": [13.3986, 52.5547]
        }
    },**

Should the data be like this so I can integrate with the application map mashups? If so, how should I defined the attributes?

Note: I am not a JSON expert :D

thank you

jason-fox commented 3 years ago

This is perfectly possible in NGSI-LD - The provisioned Animal collars in the NGSI-LD subscriptions tutorial provide an example of a GPS unit set up as a Geoproperty. There is an outstanding PR #854 needs to be merge to simplify this on NGSI-v2 using geo:json or geo:point. GPS coordinates maybe possible to create using the JEXL parser as well. You can look at the PR to see how I envisage lat/lng pairs to be provisioned.

There is no problem with creating static attributes of a GeoJSON type of course.

rezendel commented 3 years ago

Thanks Jason.

If I understood correctly, I should not be getting this issue since the PR #854 fixes this.

I will check my application settings

jason-fox commented 3 years ago

@rezendel - PR #854 is currently open and not merged. You won't be getting this issue with NGSI-LD, but the back-port to NGSI-v2 is awaiting review.

fgalan commented 3 years ago

PR https://github.com/telefonicaid/iotagent-node-lib/pull/854 has been just merged.

@rezendel could you test again and tell us how it goes, please? Not sure how do you have installed the IOTA, but maybe you need to rebuild your docker container to get the new version of the iotagent-node-lib from master...