Skip to content

jrsavage29/Full-Component-Robot-Arm-MQTT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

After Downloading This Program

  1. Replace all the files in the project folder except the .cproject file
  2. Make sure the network configuration in network_if.h is correct
#define SSID_NAME	""
#define SECURITY_TYPE	SL_WLAN_SEC_TYPE_WPA_WPA2
#define SECURITY_KEY	""

Example Summary

This example introduce the MQTT Client library API and usage.

Peripherals Exercised

  • The board LEDs are used for status indication. To distinguish similar indications, the user needs to be aware of the executed procedure.
    The following table lists all options.
LED indication Led Color for CC3220 Led Color for CC3235 Interpretation
Solidly on Green Green Indicate Simplelink is properly up - Every Reset / Initialize
Blinking Red Blue Device is trying to connect to AP - Every Reset / Initialize
Solidly off All All Device connected and working - Only after connection
Toggling (Solidly on/off) Red Blue Publish message received in SUBSCRIPTION_TOPIC1
Toggling (Solidly on/off) Yellow Red Publish message received in SUBSCRIPTION_TOPIC2
Toggling (Solidly on/off) Green Green Publish message received in SUBSCRIPTION_TOPIC3

Example Usage

  • Access Point (AP) Configuration
    • AP information is set in 'network_if.h' file.

The application have one MQTT entity
MQTT Client Role - Can connect to remote broker

  • Remote Broker Configuration

    • Broker parameters can be configured in Mqtt_ClientCtx parameter which can be found in 'mqtt_client_app.c'
    • The broker parameters are:
      • Connection types and security options
        • IPv4 connection
        • IPv6 connection
        • URL connection
        • Secure connection
        • skip domain name verfication in secure connection
        • skip certificate catalog verfication in secture connection
      • Server Address: URL or IP
      • Port number of MQTT server
      • Method to tcp secured socket
      • Cipher to tcp secured socket
      • Number of files for secure transfer
      • The secure Files
  • Secured socket
    In order to activate the secured example, SECURE_CLIENT must be defined in 'mqtt_client_app.c' file ( certificates should be programmed ).

  • Client Authentication
    In order to activate the Client authentication by the server, CLNT_USR_PWD must be defined ( ClientUsername and ClientPassword must be defined ).

  • Topics Configuration

    • The topics can be set by changing the definitions in 'mqtt_client_app.c' file
    • The subscription topics can be set in the SUBSCRIPTION_TOPICX definitions
    • The Client is subscribe to the following default topics
      "/Broker/To/cc32xx"
      "/cc3200/ToggleLEDCmdL1"
      "/cc3200/ToggleLEDCmdL2"
      "/cc3200/ToggleLEDCmdL3"
    • The publish topic and data can be set in the PUBLISH_TOPICX and PUBLISH_TOPICX_DATA definitions
    • The Client publish the following default topic "/cc32xx/ButtonPressEvtSw2" - the topic will be published by pressing SW2 on the board
  • Build the project and flash it by using the Uniflash tool for cc32xx, or equivalently, run debug session on the IDE of your choice.

  • Open a serial port session (e.g. 'HyperTerminal','puTTY', 'Tera Term' etc.) to the appropriate COM port - listed as 'User UART'.
    The COM port can be determined via Device Manager in Windows or via ls /dev/tty* in Linux.

    The connection should have the following connection settings:

      Baud-rate:    115200
      Data bits:         8
      Stop bits:         1
      Parity:         None
      Flow Control:   None
    
  • Run the example by pressing the reset button or by running debug session through your IDE.
    Green LED turns ON to indicate the Application initialization is complete

  • Once the application has completed it's initialization and the network processor is up,
    the application banner would be displayed, showing version details:

      ============================================
         MQTT client Example Ver: 1.1.1
      ============================================
    
       CHIP: 0x30000019
       MAC:  2.0.0.0
       PHY:  2.2.0.5
       NWP:  3.3.99.2
       ROM:  0
       HOST: 2.0.1.17
       MAC address: 04:a3:16:45:89:8e
    
      ============================================
    
  • At this point Board_LED0 will blink until the device will connect to the hard coded AP.

    • In case connection to the hard coded SSID AP fails, user will be requested to fill the SSID of an open AP it wishes to connect to.
    • If no AP is available or connection failed, the example reset and tries to connect again.
    • Once the connection success all LEDs turn off.
  • Special handling

    • In case the client will disconnect (for any reason) from the remote broker, the MQTT will be restarted.
      The user can change that behavior by deleting gResetApplication = true from MQTT_CLIENT_DISCONNECT_CB_EVENT case in 'Client_server_cbs.c' file.

Application Design Details

MQTT Client application used to demonstrate the client side of the MQTT protocol. It does that by offering a semi-automatic application.

The application starts with invoking the 'Mqtt_IF_Connect()' command which tries to connect to a specific AP which his SSID is hard coded in Network_if.h file, in case the connection to the AP fails, the user will be requested to fill the SSID of an open AP to connect to.

After connection success, the application invokes the 'MqttClient_start' command which set all the parameter that are required to create TCP/TLS/SSL connection to the broker, invokes the 'MQTTClient_connect(gMqttClient)' command which create the connection to the broker and then invokes the 'MQTTClient_subscribe(gMqttClient , subscriptionInfo, SUBSCRIPTION_TOPIC_COUNT)' command which subscribe the client topics which are hard coded in 'Mqtt_client_app.c'

Now the client can receive publish messages from the borker. In this example the topics in the left will toggle the LEDs in the right

						"/cc3200/ToggleLEDCmdL1" <-------------> toggle LED0  
						"/cc3200/ToggleLEDCmdL2" <-------------> toggle LED1  
						"/cc3200/ToggleLEDCmdL3" <-------------> toggle LED2   

The user can invoke more commands by pressing the push buttons on the CC32xx launchpad device:

  • When pressing push botton 0 - SW2, The device will publish the message that include the topic and data which is hard coded in 'Mqtt_client_app.c' by invoking 'MQTTClient_publish' command.

  • When pressing push botton 1 - SW3, The device will unsbscribe the topic by invoking 'MQTTClient_unsubscribe' command, disconnect from the broker by invoking 'MQTTClient_delete' command and software reset the device.

References

MQTT Org - MQTT Home page
MQTT v3.1.1 specification
MQTT v3.1 specification

For further information please refer to the user programmers guide: CC3X20 Programmer's Guide

About

Full Component Code for MQTT use with the Robot Arm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages