In this step-by-step guide we show how to connect a data source to the IoT platform from IBM via MQTT using OPC Router as MQTT client.
The IBM Watson-Internet of Things platform is IBM’s IoT solution in the Watson system. Devices can be created in the IoT platform. The devices are sent and assigned current data via MQTT. With its various plug-ins for connecting subsystems, the OPC Router is the ideal data provider for devices of the Watson IoT platform. Watson serves as MQTT Broker, which is connected with the MQTT Client Plug-in of the OPC Router.
MQTT connection of the IBM Watson IoT platform
The connection takes place in following steps, which we explain in detail below.
- Setup of the IoT platform in IBM Watson
- Configuration of the device
- Configuration of the MQTT Client
Setup of the IoT platform
- Log in to the IBM Watson interface and navigate to the “Dashboard”. Then click “Create” to create a resource:
- Search in the library for “label:lite iot” to find the “Internet of Things Platform”. Then select and create:
- Name (1) and create (2) the newly created IoT platform:
- Start the IoT platform afterwards:
Creating a Device
1. After starting the platform, the device overview opens automatically. Select “Create a device” here:
2. The new device must be named in the next step. First name the type (1), then the device itself (2) and then continue (3).
3. In the next step, meta data for the device can be maintained. It is optional. Continue with “Next”:
4. In the following security settings, the default settings can be accepted and continued with “Next”:
5. In the last step, the data are summarized and the device can be created with “Finish”:
6. The created device is displayed with its access data for MQTT. These are important for the following MQTT client configuration. Here you can find the organization ID (1), the assigned type name (2), the device ID (3) and the authentication token (4):
Configuration of the MQTT Client
In the MQTT Client the device information must be transferred to the MQTT connection configuration. In the OPC Router (other clients are comparable) the data is used as follows:
Broker connection: The organization ID (here 7nahdt) becomes together with “.messaging.internetofthings.ibmcloud.com” the broker connection address.
Client ID: The Client ID consists of Organization ID (1), Device Type (2) and Device ID (3). the format is “d:<Device-Type>:<Device-ID>”.
Username: The fixed string “use-token-auth” (4) is used as username to indicate that a token is being used.
Password: The password is the authentication token (5) specified in the device information.
Example: Temperature transmission to the IoT platform with the OPC Router
In this example, temperature acquisition data is loaded from an SQL database and formatted as JSON and sent to the configured IBM Watson IoT device. The MQTT client integrated in the Watson IoT console displays the received data.