Step by Step Guide on MQTT.fx and Medium One

In this tutorial, we will explain the steps to send MQTT messages to Medium One’s sandbox using a client application.

Required:

  • Medium One Sandbox account
  • http://mqttfx.org/
  • MQTT username: (see instructions)
  • MQTT password: (see instructions)
  • MQTT broker: mqtt.mediumone.com
  • MQTT port : 61620

Estimated time: 10-20 mins

Prerequisite: Please go through our 10 Min Quick Start Guide before attempting this (http://docs.mediumone.com/)

 

How to get MQTT username:

The username is <project_id>/<mqtt_user_id>

1

2

In this example, the mqtt_username is: AfzvMXSqmrM/4KEHYifLft0 .

 

How to get the MQTT password:

mqtt_password = <api_key>/<user_password>

Here’s the api key.

3

You should know the user password. If not, you can reset it here.

4

 

How to setup MQTT.fx

  Click the settings gear box to configure (below).

5

6

7

Enter the MQTT Username and password from above here:

8

9

10

Click OK when done, then click connect.You should see green box on the right (below)

12

Next, specify the Topic and Payload, and click Publish. To publish to your tenant, the format is 0/<project MQTT ID>/<user MQTT ID>/<device>. The device can be anything. Make sure to put {“event_data”:{“hello”:”world”}} as the text to send.

13

How to See Events in Medium One Dashboard

On the Medium One dashboard, select the real-time log widget and the user to see the event come in.

14

If you want to enable the events for Workflows, go to config/datastream -> raw, 

15

then click and enable the tag.

16

How to subscribe to an event on Mqtt.fx

Go back to Mqtt.fx. To subscribe to data from your account, the format is 1/<project_mqtt_id>/<user_mqtt_id>/<device>/event. Note that the last parameter is the word “event” and does not change.  Remember what you put in for <device>, you will need it in the next step. We put “test_device” for this example. Click on “Subscribe.”

Build a workflow to respond to to Mqtt.fx

Log into your Medium One account. Click on “Workflow Studio,” then “Create a New Workflow.” Name it “MQTT Response”. Under Tags and Triggers in the righthand sidebar, click on raw->hello. Drag and drop this tag onto the screen.

Under “Modules,” find Foundation->Base Python. Drag this onto the screen as well. Connect out1 from the green box into in1 in the blue box. Your workflow should look like this.

Double click on the blue box and replace the code in there with the following python code:

Click “Save and Activate.” Make sure to replace ‘test_device’ with whatever device name you subscribed to in the previous step.

See the communication flow in Mqtt.fx

Go to the publish tab Mqtt.fx and click “Publish.” Wait a few moments. Click on the subscribe tab. You should see that a new event came in. Click on it.

In the black box, you should see the text specified in the workflow.

Congratulations! You have written a workflow that can publish events back to an MQTT client.

joyceml22@gmail.com'

Author: Joyce Li