Filter results by

ARTIK as MQTT Message Broker

MQTT has emerged as a standard messaging protocol for IoT. It can be used over TCP/IP networks and is very lightweight. The standard follows a publish-subscribe ("pub/sub") model; here, an ARTIK 5/7/10 module plays a key role on the network as the "message broker".

In this section, we will:

  1. Set up an ARTIK device with Mosquitto to become a simple MQTT broker.
  2. Use the Node-RED development tool to easily send and receive MQTT messages.
  3. Subscribe ARTIK 053 edge node devices to messages published to the broker.


You'll need the following resources.

  • ARTIK 5, 7, or 10 development board with Linux OS
  • One or two ARTIK 053 modules with Tizen RT OS
  • Wi-Fi® access point

You'll be using the ARTIK IDE to compile the code for ARTIK 053 modules, so you'll need to have a least tried out an initial project before tackling this one.

Initial Setup

Install the Node.js JavaScript environment, the NPM package management tool, and the Node-RED visual wiring tool on your ARTIK board. This setup is only needed the first time, before starting your first session. The procedure assumes you have network connectivity. Refer to Ethernet and Wi-Fi for details.

  1. Log in through the terminal emulator to your ARTIK Linux device.

  2. Follow the procedure in the introductory Node-RED tutorial to install Node and Node-RED. You'll additionally be using mosquitto, which comes pre-installed on your system.

Starting a Session

You must use Wi-Fi for your network connections for these procedures to work.

  1. Log in to your ARTIK Linux device (if you are not already logged in).

  2. Make a note of the Wi-Fi network IP address (which we refer to as localhost later on). Enable Wi-Fi first with dhclient wlan0 as noted in Configuring Wi-Fi, then use this command to find the wlan0 address:

    ifconfig wlan0

  3. Start Mosquitto (message broker) and run it as a background process.

    mosquitto &

  4. Start Node-RED (node connection development tool) and run it as a background process.

    node-red &

  5. Start a browser on your computer. Point it to the localhost IP address of your ARTIK device that you noted previously, on port 1880.


    Note: Your computer must be connected to the same Wi-Fi network as the ARTIK Wi-Fi.

ARTIK is now set up as a broker and is also running Node-RED, so we are ready to set up publish-subscribe messaging.

Sending MQTT Messages

This section sets up a periodic transmission of the string 'RED' to an output node that sends them under the Topic of 'color' to the ARTIK message broker. ARTIK will "publish" this information to any interested "subscribers" (to be set up in the next section).

  1. Create a flow on the Node-RED canvas.

    • Select an Input node: Drag an "inject" input node from the palette in the left pane to the middle of the canvas (it initially shows "timestamp").

    • Select an Output node: Drag an "MQTT" output node to the right of the first node. This node will be sending messages to the broker via MQTT.

    • Connection: Connect the 2 nodes by dragging a "wire" from the right side of the inject node to the left side of the MQTT node.

  2. Configure each node by double-clicking on it.

    • Inject node: Set Payload to string; enter 'RED' as its value. Set Repeat to a 10s interval.

    • MQTT node: Configure the node to send a message by entering the localhost IP address of the broker, at port 1883. Enter a Topic of 'color'.

  3. Run the flow. Click Deploy at the upper right to run this new flow.

Node-RED is now sending 'color' messages to the broker every 10 seconds. We can next set up edge devices and configure them to be subscribers to these messages.

Using Debug Capabilities of Node-RED

Along with the Inject input node type, the Debug output node type helps greatly in troubleshooting a flow. For a demonstration, we will start from the canvas as it was left after the previous exercise Sending MQTT Messages.

  1. Add debug capabilities to the existing flow on the Node-RED canvas.

    • Select an Output node: Drag a "debug" output node from the palette in the left pane onto the canvas, to the right of your Inject node.
    • Connection: Connect the nodes by dragging a second wire from the right side of the Inject node to the left side of the debug node.
  2. Run the flow. Click Deploy at the upper right to run this new flow.

  3. Look at the debug output. Click on the debug tab just under the Deploy button.

Now you can see the history of the messages being sent from the Inject node.


In this tutorial, you have seen how messages can be sent and received through a broker in a publish-subscribe fashion. This simple architecture can scale up and out to a variety of scenarios through a number of different of network topologies.

Node-RED is a powerful development tool. We present some more advanced examples of its use in the next article.

Troubleshooting Tip. When you try to start a subsequent Node-RED session, do you get error messages but no canvas?
– Some of the saved nodes or settings may be corrupt. Copy elsewhere and then delete the files (but not the lib subdirectory) in the hidden /root/.node-red directory.
– Make sure there is no proxy in your network.

Last updated on: