Running Eclipse HONO and Ditto on Google Cloud (2)

MichaelChi
Google Cloud - Community
3 min readAug 20, 2022

This is the second part of the blog series. In this blog I will configure Eclipse HONO and Eclipse Ditto so the two integrated together. Then I will create a device to verify end-to-end connectivity.

Download the setCloud2EdgeEnv.sh file to Cloud Shell, make sure you are still connected to the GKE cluster we created in previous blog post.

chmod +777 setCloud2EdgeEnv.sh
RELEASE=c2e
NS=cloud2edge
./setCloud2EdgeEnv.sh $RELEASE $NS

This will gives you required environment variables, copy the script outputs and paste it to the Cloud Shell console and hit Enter to execute them.

export AMQP_NETWORK_IP=”xx.xx.xx.xx"
export AMQP_NETWORK_PORT_amqp=”15672"
export AMQP_NETWORK_PORT_amqps=”15671"
export REGISTRY_IP=”35.194.207.149"
export REGISTRY_PORT_http=”28080"
export REGISTRY_PORT_https=”28443"
export AMQP_ADAPTER_IP=”xx.xx.xx.xx"
export AMQP_ADAPTER_PORT_amqp=”5672"
export AMQP_ADAPTER_PORT_amqps=”5671"
export HTTP_ADAPTER_IP=”xx.xx.xx.xx"
export HTTP_ADAPTER_PORT_http=”8080"
export HTTP_ADAPTER_PORT_https=”8443"
export MQTT_ADAPTER_IP=”34.81.137.23"
export MQTT_ADAPTER_PORT_mqtt=”1883"
export MQTT_ADAPTER_PORT_secure-mqtt=”8883"
export DITTO_API_IP=”xx.xx.xx.xx"
export DITTO_API_PORT_http=”8080"
# Run this command to populate environment variables
# with the NodePorts of Hono’s and Ditto’s API endpoints:
# eval “$(./setCloud2EdgeEnv.sh RELEASE_NAME [NAMESPACE])”
# with NAMESPACE being the Kubernetes name space that you installed Hono to
# if no name space is given, the default name space is used

Note that the variable name of MQTT_ADAPTER_PORT_secure-mqtt is invalid since it contains a hyphen, replace it with underscore so the script can be correctly executed.

Set up a device in Eclipse HONO

Eclipse HONO provides REST API endpoint for us to interact with it. To create a device that connects to Eclipse HONO, first we create a tenant that will host our devices.

export TENANT_NAME=”org.eclipse.ditto"
export DEVICE_ID=”demo-device-001"
curl -i -X POST http://${REGISTRY_IP}:${REGISTRY_PORT_http}/v1/tenants/${TENANT_NAME}

This creates a new tenant called org.eclipse.ditto. You should see similar outputs.

Create a device under the new tenant

curl -u ditto:ditto -i -X POST http://${REGISTRY_IP}:${REGISTRY_PORT_http}/v1/devices/${TENANT_NAME}/${TENANT_NAME}:${DEVICE_ID}

You should have a HTTP 201 response code indicates the device is successfully created.

Note that when creating a new device, in the API endpoint you specify ${TENANT_NAME}:${DEVICE_ID} instead of just ${DEVICE_ID} to identify the device.

Now that we have device created, we need to assign credentials to the device so it can actually connect to Eclipse HONO.

curl -i -X PUT -H "Content-Type: application/json" --data '[{
"type": "hashed-password",
"auth-id": "demo-device-001-auth",
"secrets": [{"pwd-plain": "my-password"}]}]' http://${REGISTRY_IP}:${REGISTRY_PORT_http}/v1/credentials/${TENANT_NAME}/${TENANT_NAME}:${DEVICE_ID}

Note that here we use a new id called auth-id with a value of ${DEVICE_ID}-auth and we assign a plain text password to the device.

At this point we have successfully create a new device called demo-device-001 under the org.eclipse.ditto tenant.

Now let’s verify if we can connect the device to Eclipse HONO and start to send telemetry.

curl -X POST -i -u ${DEVICE_ID}-auth@${TENANT_NAME}:my-password -H ‘Content-Type: application/json’ -d ‘{“temp”: 23.07}’ http://${HTTP_ADAPTER_IP}:${HTTP_ADAPTER_PORT_http}/telemetry

You should see a HTTP 503 error saying no consumer available. This is because although we have the device ready, in Eclipse HONO there is no consumer listening to incoming telemetry.

At this point we have successfully create a Eclipse HONO tenant, create a device under that tenant, and have the device successfully send telemetry to Eclipse HONO. In the next blog post, we will start to configure Eclipse Ditto so it receives telemetry coming from Eclipse HONO.

Part(3)

--

--