Skip to content

Access the CMTK API with Node-RED

Overview

This guide will show you how to access the CMTK API via HTTP by using Node-RED within Docker.

Prerequisites

GET data from the CMTK API

Drag and drop a http request node from the network section of the toolbox on the left into your flow. You will need a node to trigger the request and a node to send the output to. In this case, we are triggering it with an inject node and using a debug node as output. Connect the inject node to the http request and the debug node to the http request.

Get Overview

Next, open the configuration of the http request node by double-clicking on it. Enter the following URL: 172.16.0.2:8080/iolink/v1/devices/master1port1/parameters/8192/value. This will query the condition parameter of a "Balluff Condition Monitoring Sensor" (BCM) connected at port 1.

Note

The API is only accessible from within a docker container via 172.16.0.2:8080 without any authentication. All request will be handled as an admin. See API Documentation for more information about the available endpoints.

Output

Deploy your changes and click the little blue square next to the inject node. Click the bug icon in the toolbar on the right to show the output. You should see a JSON payload printed to the console every time you trigger the inject node.

Create Container

POST data to the CMTK API

Drag and drop a http request node from the network section of toolbox on the left into your flow. You will need a node to trigger the request and one to send the output to. In this case, we are triggering it with an inject node and use a debug node as output. Connect the inject node to the http request and the debug node to the http request.

Overview

First, we need to configure our inject node. Double click on the node and edit the message payload. Click on the dropdown to the left of the msg.payload textbox and select JSON. Insert the value {"value":[2]} into the textfield and click on done.

Inject Config

Next, open the configuration of the http request node by double-clicking on it. Enter the following URL: 172.16.0.2:8080/iolink/v1/devices/master1port1/parameters/8192/value. Change the method to POST and click on done. This will set the condition parameter of a "Balluff Condition Monitoring" sensor (BCM) connected at port 1.

Note

The API is only accessible from within a docker container via 172.16.0.2:8080 without any authentication. All request will be handled as an admin. See API Documentation for more information about the available endpoints.

HTTP Request

Deploy your changes and click the little blue square next to the inject node. Click the bug icon in the toolbar on the right to show the output. You should see an empty string payload printed to the console every time you trigger the inject node.

Output

Example

The exmaple we have created may be imported by clicking on the menu in the top right and import with the following JSON:

[
    {
        "id": "9deebbaac2a3ef51",
        "type": "tab",
        "label": "HTTP",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "013860fb915e372d",
        "type": "debug",
        "z": "9deebbaac2a3ef51",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 200,
        "wires": []
    },
    {
        "id": "abc102dcf36c2b37",
        "type": "http request",
        "z": "9deebbaac2a3ef51",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "172.16.0.2:8080/iolink/v1/devices/master1port1/parameters/8192/value",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 410,
        "y": 200,
        "wires": [
            [
                "013860fb915e372d"
            ]
        ]
    },
    {
        "id": "49f579f06c031ca0",
        "type": "inject",
        "z": "9deebbaac2a3ef51",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 200,
        "wires": [
            [
                "abc102dcf36c2b37"
            ]
        ]
    },
    {
        "id": "91b9d0cdecb3f508",
        "type": "inject",
        "z": "9deebbaac2a3ef51",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"value\":[2]}",
        "payloadType": "json",
        "x": 170,
        "y": 280,
        "wires": [
            [
                "dad1d24a21eb8181"
            ]
        ]
    },
    {
        "id": "dad1d24a21eb8181",
        "type": "http request",
        "z": "9deebbaac2a3ef51",
        "name": "",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "172.16.0.2:8080/iolink/v1/devices/master1port1/parameters/8192/value",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "senderr": false,
        "x": 400,
        "y": 280,
        "wires": [
            [
                "0f6d2e6202864fea"
            ]
        ]
    },
    {
        "id": "0f6d2e6202864fea",
        "type": "debug",
        "z": "9deebbaac2a3ef51",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 280,
        "wires": []
    }
]