eclipse-agail / agile-core

Source code repository for agile core components
Eclipse Public License 2.0
7 stars 16 forks source link

Issues with Registering Devices #27

Closed craigmulligan closed 8 years ago

craigmulligan commented 8 years ago

If I query all devices via /api/protocols/devices

it returns an object like this:

{
    "id": "B0:B4:48:BD:10:85",
    "protocol": "iot.agile.protocol.BLE",
    "name": "CC2650 SensorTag",
    "status": "AVAILABLE"
  }

However it appears to register a device a stream object needs to present. Eg. this doesn't work:

{
"deviceId": "",
"address": "B0:B4:48:BE:7D:83",
"name": "CC2650 SensorTag",
"description": "",
"protocol": "iot.agile.protocol.BLE",
"path": ""
}

In my opinion, you should be able to post back an unregistered device object recieved from /api/protocols/devices but the current registration endpoint requires other attributes like address and a blank deviceId instead of id.

Thoughts?

cskiraly commented 8 years ago

I agree. We have it in the queue. This is how I see it on the long term:

Anyway, you, as the API user, should NOT support the streams and the empty ID.

craigmulligan commented 8 years ago

You still need to pass an id attribute and an streams array.

cskiraly commented 8 years ago

I was not overriding the old "POST /devices" , but created a new under "POST /devices/register". We can deprecate the old one, as I think it is not useful and no one is using it anymore, and change "POST /devices" it to the new syntax.

craigmulligan commented 8 years ago

Oh I see, could you clarify what exactly needs to be posted? When I post the following to /devices/register as per the swagger example.

{
  "name": "C2650 SensorTag",
  "protocol": "iot.agile.protocol.BLE",
  "id": "B0:B4:48:BD:10:85",
  "status": "CONNECTED"
}

It returns an 400 err:

Unrecognized field "name" (class iot.agile.http.resource.DeviceManager$RegisterArgs), not marked as ignorable (2 known properties: "overview", "type"])
 at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@17aaa47; line: 6, column: 2] (through reference chain: iot.agile.http.resource.RegisterArgs["name"])
cskiraly commented 8 years ago

My bad, I still struggle with getting the right syntax out of swagger. What you need is: { "overview": { "name": "C2650 SensorTag", "protocol": "iot.agile.protocol.BLE", "id": "B0:B4:48:BD:10:85", "status": "CONNECTED" } "type": "TI SensorTag" }

The value of type you are supposed to get from /api/devices/typof to which you first pass the overview. This returns an array of possible types. If there is only one, you can use that, if there are more, someone should decide which implementation to use.

cskiraly commented 8 years ago

I think I'm missing a "," above

{ "overview": { "name": "C2650 SensorTag", "protocol": "iot.agile.protocol.BLE", "id": "B0:B4:48:BD:10:85", "status": "CONNECTED" }, "type": "TI SensorTag" }

craigmulligan commented 8 years ago

Ah thanks, Could you elaborate on the /api/devices/typof call, there aren't any docs.

craigmulligan commented 8 years ago

What is the type used for?

cskiraly commented 8 years ago

argh. typo. /api/devices/typeof This is the device type. When you register a device, you should be able to tell what it is, since it cannot always be autodetected. The workflow is:

craigmulligan commented 8 years ago

I tried typeof too but still failing - see issue #35

cskiraly commented 8 years ago

The swagger documented version is working now. See: http://petstore.swagger.io/?url=http://agile-iot.github.io/agile-api-spec/docs/swagger/api.swagger.yml#!/DeviceManager/TypeOf http://petstore.swagger.io/?url=http://agile-iot.github.io/agile-api-spec/docs/swagger/api.swagger.yml#!/DeviceManager/Register

Note that: