eclipse-hawkbit / hawkbit

Eclipse hawkBit™
https://projects.eclipse.org/projects/iot.hawkbit
Eclipse Public License 2.0
462 stars 188 forks source link

How to make device(Raspberry pi or bosch xdk) register to hawkbit #681

Closed rachel-dev closed 6 years ago

rachel-dev commented 6 years ago

Hello everyone,

I am new to use hawkbit. I am trying to make device register to Bosch rollout or local hawkbit. But I don't know how to do that.

Thank you before.

laverman commented 6 years ago

Hi @xdk-rachel , the easiest way to register your device with your local hawkbit is to use the Direct Device Integration (DDI) API, by simply performing a GET to http://localhost:8080/default/controller/v1/{controllerId}. This will create a base poll resource (ref: documentation).

schabdo commented 6 years ago

... or you use the Management UI to create it manually

rachel-dev commented 6 years ago

@laverman @schabdo Hi, Thank you very much. But I am still confused about it. For example, if I want to download to Raspberry Pi, so raspberry pi will send the command : curl 'https://rollouts-ms.apps.de1.bosch-iot-cloud.com/rest/v1/targets' -i -X POST -H 'Content-Type: application/json;charset=UTF-8' -d '[ { "securityToken" : "2345678DGGDGFTDzztgf", "address" : "https://192.168.0.1", "controllerId" : "123456", "name" : "raspberry pi", "description" : "test" } ]' and then raspberry pi will be registered to hawkbit. Is it right? or can you give me an example? Thank you very much.

schabdo commented 6 years ago

Yes indeed, your approach will work: After you sent the curl request to the management API (/rest/v1/targets) a controller with ID 123456 is able to use the DDI API authenticated by given security token 2345678DGGDGFTDzztgf.

Hint: For your local test you can enable anonymous access via property (see here) => this will allow controllers to register themselves dynamically. So the first call to management API is not necessary.

However for later production use I won't recommend to call either the management API directly from your device nor to enable anonymous access

rachel-dev commented 6 years ago

@schabdo Thank you very much screenshot from 2018-05-14 16-59-18 screenshot from 2018-05-14 16-59-32 If i want to use DMF like fist picture, how can I connect?

schabdo commented 6 years ago

Well, there is no open source LWM2M connector for HawkBit I am aware of. The connector shown in your picture is proprietary so I am afraid I can't help you with that. HawkBit only offers DMF as a AMQP based message API

rachel-dev commented 6 years ago

@schabdo Thank you again. Could you tell me how to send messages through DMF? I read the document that said there is some function like sp.direct.exchange. But how to use that? Do I need to installing anything?

laverman commented 6 years ago

The DMF is based on RabbitMQ. Therefore, you need a RabbitMQ running which is connected to your HawkBit instance. This can be easily achieved by using the provided docker-compose file.

When I understood you correctly, you want to know how a client uses the DMF? A good example for this, is the hawkbit-device-simulator, especially the DMF (amqp) part.

Blackrose commented 6 years ago

Hi, recently, I noticed the docker image has upgraded.Now I am use '$ curl 'https://ddi-api.host.com/TENANT_ID/controller/v1/CONTROLLER_ID' -i -H 'Accept: application/hal+json' ' command and get the "401 Unauthorized" error message. @schabdo said need use securityToken value.But the API doesn't have any description.Where can I found the latest document? https://docs.bosch-iot-rollouts.com/documentation/rest-api/rootcontroller-api-guide.html#_get_tenant_controller_v1_controllerid

laverman commented 6 years ago

Hi @Blackrose - the corresponding documentation can be found here [1]. As described, you need to enable direct authentication via security token in the HawkBit settings. Afterwards, you need to provide an Authorization header (e.g. -H "Authorization: TargetToken 123456").

Edit: The target token is the target's security token.

[1] https://www.eclipse.org/hawkbit/documentation/security/security.html

Blackrose commented 6 years ago

@laverman Thanks.I have already communicated with the server.

laverman commented 6 years ago

Did I understand you correctly, that your problem is thereby solved?

Blackrose commented 6 years ago

@laverman Right. It has been resolved.

kaushalkapadiya commented 6 years ago

i just started using hawkbit and i don't how to connect a new device to hawkbit using ddi or dmf. does anyone know how to do that

laverman commented 6 years ago

Hi @kaushalkapadiya, if you want to connect your device directly to hawkBit, I'd recommend using the Direct Device Integration (DDI) API (cf. RESTdocs).

To connect your device:

  1. In System Configuration, allow a device to authenticate with a gateway security token (as described here)
  2. Let your device perform a HTTP-GET to http://localhost:8080/default/controller/v1/{controllerId} with the following header Authorization: GatewayToken {yourGatewayTokenFromSystemConfiguration}
  3. After performing this request successfully, your device appears in the Management UI of your hawkBit instance.

In addition, I'd like to point you to our website https://www.eclipse.org/hawkbit/ where you'll find the API documentation among other helpful things 😊

kaushalkapadiya commented 5 years ago

i tried to make http request using curl like, curl -u admin:admin 'http://localhost:8080/default/controller/v1/ddiSimulated0' -i -X GET -H 'Accept: application/hal+json;Authorization: GatewayToken 3cbed112ef459f7bad2f5b50e71a437a'

but i am having error, HTTP/1.1 401 Unauthorized Date: Fri, 16 Nov 2018 16:44:44 GMT X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Content-Length: 0

poppydhir commented 5 years ago

Device giving 401 when connecting to hawkbit. Though UI runs fine. I am able to loging , upload image, create distribution, register the device, assign distribution to device(All successful). But when I connect device, its able to connect but can't download the artifact/image. LOGS below>>

close_session: Close sess: close http-sess;


Hawkbit Setup->
Running docker container with docker image - hawkbit-update-server:0.2.4-mysql [Port 443] Running Haproxy( with certs ) in front of hawkbit-server. Device connect using certs Docker Environment variables SPRING_DATASOURCE_USERNAME ** SECURITY_USER_PASSWORD **** SPRING_DATASOURCE_PASSWORD ** SPRING_RABBITMQ_USERNAME SPRING_RABBITMQ_PASSWORD SPRING_RABBITMQ_HOST rabbitmq SPRING_DATASOURCE_URL jdbc:mysql://MYSQLSERVER:3306/hawkbit SERVER_PORT 443 SECURITY_USER_NAME **

_

schabdo commented 5 years ago

@poppydhir your issue seems to be related to the use of certificate authentication. So not a general device connectivity issue as discussed here. May I ask you to file a new GitHub issue instead?