Staging:CC3120 MQTT Client

Overview
This application will demonstrate the usage of the MQTT library as a client by subsribing and publishing on topics.

For demo application using the Simplelink device as MQTT Server, please refer to CC3120 MQTT Server application.

Application Details
MQTT (Message Queue Telemetry Transport) protocol is an extremely light weight machine to machine connectivity protocol. It is based on publish/subscribe messaging model and is designed to be used on the top of TCP/IP protocol. Key point of this protocol includes small code footprint and low network bandwidth requirement. Other features include faster response time, low power requirement, ease of scalability. All these advantages makes it an ideal candidate for communication protocol in embedded devices intended to implement IOT(internet of things) applications. More information regarding MQTT protocol can be obtained from the latest MQTT Protocol specification.

A Simple MQTT infrastructure contains a broker(like a central hub) connected to multiple clients, each of which has the capability of publishing on any topic(token). Broker has the responsibility of sending the message published on any topic to all the subscribers of that topic. This is a very simplistic description of a MQTT network, which has a lot more features and configuration parameters.

This application makes use of the APIs from MQTT client library to communicate with an IBM web client using the IBM broker. Two LEDs on the host platform can be controlled from a web client by publishing msg on appropriate topics. Similarly, message can be published on pre-configured topics(in the code) by pressing the buttons on the host platform. MQTT Client          - Publish   topic /Simplelink/ToggleLEDCmdL#    -┐ [e.g. IBM MQTT Web Client]  < Subscribe topic /Simplelink/ButtonPressTopic# -┐   | |  |                                                                                        |   v                                                                                      MQTT Broker [e.g. IBM MQTT Broker] ^  |                                                                                        |   |         MQTT Client           - Publish   topic /Simplelink/ButtonPressTopic# -┘   | [e.g. Simplelink Wi-Fi Device] < Subscribe topic /Simplelink/ToggleLEDCmdL#   -┘

Source Files Details

 * main.c - Initializes the device in default configuration and creates two tasks - 'mainTask' and 'MqttClientTask'

MQTT Library Details
MQTT library abstracts out the underlying intricacies of MQTT network and provides you with intuitive and easy to use APIs to implement the MQTT protocol on the Simplelink Wi-Fi device.

The MQTT Library API documentation can be found under the /docs directory:
 * mqtt_client.chm - API document for the MQTT Client library.
 * mqtt_server.chm - API document for the MQTT Server library.
 * sl_mqtt_client.chm - API document for the simple link wrapper around MQTT Client library.
 * sl_mqtt_server.chm - API document for the simple link wrapper around MQTT Server library.

Prerequisite

 * 1x CC3120BOOST
 * 1x MSP432-EXP432P401R
 * 1x Micro-USB cable
 * 1x 2.4GHz AP with internet access
 * Access to the IBM MQTT Web Client

Configurations
Most the parameters that user would need to modify are specified as MACROs, located at the top of the main.c file.

These definitions, along with MQTT callbacks, will eventually get populated in following structures containing connection configuration and library configuration respectively.

Client ID is unique for every client. It is recommended to change the client ID for CC3100 device to avoid connection issues as shown in the configurations section.

The MQTT library has the capability of connecting to multiple brokers simultaneously. If one wishes to do that, configuration for the new connection can be added as new element(on next index) in connect_config, and change the MAX_BROKER_CONN macro to your desired number.

Example Use Cases and Outputs

 * 1) Connect the boards, compile, and run the application. Please refer to CC31xx SimpleLink Studio for setup details.
 * 2) Open IBM MQTT Web Client from a browser on a PC. You will reach the web client from IBM. [[File:sl_sdk_mqtt_client_01.png]]
 * 3) Connect to "messagesight.demos.ibm.com", and Subscribe to the /Simplelink/ButtonPressTopic1 and /Simplelink/ButtonPressTopic2 topics. [[File:sl_sdk_mqtt_client_02.png]]
 * 4) On your PC, open a terminal to access command line interface to the connected MCU platform.
 * 5) Now back to your MQTT client project. Build and run this MQTT Client application. If connection to the MQTT broker is successful, you should see the following message: [[File:sl_sdk_mqtt_client_03.png]]
 * 6) As shown on the console window, the device is subscribed to the /Simplelink/ToggleLEDCmdL1 and /Simplelink/ToggleLEDCmdL2 topics. Communication is ready.
 * 7) To send a message from the IBM web client to the Simplelink device, publish either /Simplelink/ToggleLEDCmdL1 or /Simplelink/ToggleLEDCmdL2 topic, and you should see the message printed in the console and corresponding LED toggled. [[File:sl_sdk_mqtt_client_04.png]][[File:sl_sdk_mqtt_client_05.png]]
 * 8) To send a message from the Simplelink device to the IBM web client, press either S1 or S2 button. [[File:sl_sdk_mqtt_client_06.png]][[File:sl_sdk_mqtt_client_07.png]]
 * 9) You may repeat the last 2 steps to send messages back a forth between the two clients.

Additional Information
To print about the packet level details of MQTT packets in the console, define DEBUG_NET_DEV as the predefined symbol while building the mqtt library.

Limitations/Known Issues

 * Client can connect to at most 4 brokers at a time