After quite I while I found time to finish the end to end scenario that I have started with:

Part 1 Getting the Sensors up and running

Part 2 :Mosqitto configuration

This time we want to connect the MQTT Broker and the SAP CP IoT Service.

Initially we configure the platform to be able to use the IoT Service. I assume you are using hanatrial.ondemand.com

After logging in we navigate to “Services” and make sure the Interet of Things Service is activated (or we do so)

 

So we navigate to Services IoT Service

Configuration

  1. Message Types
  2. Device Types
  3. Devices

 

  1. We start with the message type and create a new type called mqtt (with the +  on the bottom of the page)

We create a new value “temperature” of type float and delete the rest.

For every message type an ID is created which will become important:

2. Then we go ahead to create a Device type temperatureSensor which uses the MessageType mqtt:

The name is free text and here we chose bi-directional communication to be able to write and read from the sensor.

3. Then we finally create a Device (Sensor a) of the type temperatureSensor:

Also this device comes with an ID:

Finishing the configuration on SAP CP

First we check if the Message Management service was deployed and do so if needed:

Also we may need to add a role to your User: IoT-MMS-User

Then we proceed wit the configuration

We need at least three parameters. The url (or IP) to your server, user of the MQTT broker and the password

Test if it works

We should have completed the steps on the platform and should new be ready to connect our local MQTT broker (mosquitto) to our cloudplatform.

Before you start you should make sure that your local installation is accessible from the internet – if this is the case we can proceed.

To test the connection we use the MQTT over TCP client:

The broker is taken from the configuration in MMS and the requested device ID is the one we previously created in step 3 creating the first device:

We connect to the broker and can now send a message to the sensor (or rather the topic for the sensor)

A bit tricky is to compose the correct message:

Our message type (mqtt) only expects a temperature in numeric format. The message type however is not “mqtt” as one would expect but is the ID that was associated with it.

The message could look like this (please use your ID’s):

{"mode":"async", "messageType":"f309795097bacbefacc8","messages":[{"temperature":"22"}]}

 

When you press send you should see a positive response from the server.(see above)

When you go back to the device configuration (see begin of the post) you should also be able to visualize the value and to see it in a table:

You should also be able to see the values on other clients that subscribe to the same topic.

On your Raspi Server you should be able to use the mosquitto pub and sub commands as described in PART 2.

The same command as above looks like this and sends the value temperature 22 to the topic associated with the sensor:

mosquitto_pub -t 'iot/data/iotmmsd057364trial/v1/66616fcc-23e4-44f1-9a9f-d5f63d2deec8' -m '{"mode":"async", "messageType":"f309795097bacbefacc8","messages":[{"temperature":"22"}]}' -u user -P password
To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Mark Teichmann

    I am trying also to connect to a Mosquito Broker but on Port 8883 using TLS/SSL. But I can’t get a connection, get Connection Status 2. Did you also try to connect over SSL or is this not possible?

    (0) 

Leave a Reply