Skip to content

MQTT

What Is MQTT? MQTT was developed by Andy Stanford-Clark (IBM) and Arlen Nipper (Eurotech; now Cirrus Link) in 1999 for monitoring an oil pipeline through the desert. The goals were to have a bandwidth-efficient protocol that used little battery power, because the devices were connected via satellite which was extremely expensive. The protocol uses a publish/subscribe architecture in contrast to HTTP with its request/response paradigm. Publish/Subscribe is event-driven and enables messages to be pushed to clients. The central communication point is the MQTT broker, it is in charge of dispatching all messages between the senders and the rightful receivers. Each client that publishes a message to the broker, includes a topic into the message. The topic is the routing information for the broker. Each client that wants to receive messages subscribes to a certain topic and the broker delivers all messages with the matching topic to the client. Therefore the clients don't have to know each other, they only communicate over the topic. This architecture enables highly scalable solutions without dependencies between the data producers and the data consumers.
How does TapNLink use MQTT? TapNLink uses MQTT to power realtime communication between IoT endpoint systems and web applications, so that users can control their devices from anywhere. A remote operation is the ability to control, monitor and manage your system in the field from any location. It allows you to make remote changes and review system status in real time, reducing the need for on-site visits, ensuring that machines are operating optimally and reducing the risk of endpoint damage.
Which MQTT broker should I use? There are [several free brokers](https://github.com/mqtt/mqtt.github.io/wiki/servers). IoTize started using test.mosquitto.org, but is a victim of its own success and is now so slow (and regularly broken) that it can't maintain a monitoring session. We currently use www.hivemq.com/public-mqtt-broker.

Refer to Eclipse Mosquitto for an introduction to MQTT protocol and how to setup a lightweight MQTT Broker.

Operating process

Using a WIFI TapNLink (IOTZ-TAPNLINK-PRIMER-NBW & TnL-FIW103) it is possible with very little effort to create an application that communicates via MQTT with your system. IoTize Studio is simply configured with the connection type (Certificate / Id & Pwd / no password).

TapNLink NFC-WIFI acts as a gateway to the MQTT broker, which resides in the Cloud. On the other side is a second device, the control center, that also has an MQTT client and enables the monitoring of the system through this communication.

Note: The User name / Login can be the same for the Control App and TapNLink, but their Client Ids must be different.

Use Case

We are going to configure and simulate a remote monitoring session of 'Sensor Demo target application' using the public HiveMQ MQTT broker.

Prerequisites

  • TapNLink NFC-WIFI Primer Evaluation Kit: allows iot designers to test all the advantages of IoTizeTapNLink products for building a connected electronic system. You can purchase it from Digikey.
  • IoTize Studio: IoTize’s software for configuring TapNLink modules, downloadable from IoTize website.
  • App Generator: Tools to control custom mobile app generation. For a simple implementation, follow instructions in the App Generator Getting Started. (For a more customized app, follow the instructions from IoTize App Generator documentation.)

IoTize Studio software has a set of sample configurations. Open the following configuration: [Install Directory]\IoTize\IoTize Studio\Examples\Sensors_STM32_Demo\Sensor_demo.iotz

You could use Socket communication to connect IoTize Studio directly to your Tap.

The operating mode depends on whether TapNLink NFC-WiFi Primer is configured as an Access Point device or connected to Network.

Use 'Sensor demo smartphone app' to find out which mode your Tap is using. Select Studio from the configuration explorer and select Socket as the 'Connection To Tap | Protocol'. Enter the IP address of the Tap in the field Socket host name\IP.

  • Either your TapNLink NFC-WiFi Primer is in Access Point mode and creates its own local WIFI Network (this is the default configuration of TapNLink NFC-WIFI Primer).

  • Or, TapNLink NFC-WiFi Primer is already connected to your Local WIFI Network:

You could test the connection between your PC and the Tap using the Test Connection command.

  • If your TapNLink NFC-WIFI Primer is not already connected to your Local WIFI Network, refer to IoTize Studio Manual to connect it.

  • Select IoTized Application | Wireless Communication. Use the Serial Number of your TapNLink NFC-WIFI Primer as the ClientID.

  • Configure your Tap using the Configure command button, then use Test|Reboot TAP to restart the Tap with the new configuration that enables the connection between the Tap and the Broker.

See IoTize Studio Manual to learn more about MQTT protocol settings in IoTize Studio.

Step3. Build a mobile App using the 'App Generator'

IoTize Software Suite has an App Generator which quickly creates powerful and beautifully designed mobile apps that can be deployed through Cordova. See App Generator documentation to learn more about the App Generator environment and tools.

The App Generator can be used directly from IoTize Studio.

  • Change the Mobile App Settings from IoTize Studio to MQTT communication protocol.

  • Use the Generate App command to start building the app.

  • To test the remote monitoring session, start a local development server on 'localhost': open a new cmd prompt, go to the directory of the generated app and type ng serve command to start serving the app.

  • Using your browser, navigate to the localhost URL, select MQTT as communication protocol. Provide the Broker URL settings and the serial number of your TapNLink NFC-WIFI Primer and press CONNECT.

  • The served app integrates an MQTT Client that will connect to the Broker using MQTT over Websocket, so you can remotely monitor 'Sensor demo target application' through the internet.