element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Safe and Sound
  • Challenges & Projects
  • Design Challenges
  • Safe and Sound
  • More
  • Cancel
Safe and Sound
Blog Safe and Sound Wearables- Hearing Guard System #14: MSP432 and CC3100 MQTT with Websockets Part II
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jomoenginer
  • Date Created: 5 Jun 2017 1:22 AM Date Created
  • Views 895 views
  • Likes 4 likes
  • Comments 2 comments
  • mqtt
  • simplelink wi-fi cc3100 boosterpack
  • websockets
  • msp432
  • cc3100
  • mosquitto
Related
Recommended

Safe and Sound Wearables- Hearing Guard System #14: MSP432 and CC3100 MQTT with Websockets Part II

jomoenginer
jomoenginer
5 Jun 2017

MSP432 and CC3100 MQTT with Websockets Part II (MSP432/CC3100 MQTT config)

 

Hardware:

SimpleLinkTm MSP432P401R LaunchPad

CC3100MODBOOST WiFi, SimpleLinkTm Module BoosterPack

Beaglebone Black Rev C.

 

Software:

CC3100 MQTT Client - Texas Instruments Wiki

MSP432Ware v.3.50.00.02 (CC3100BOOST_MQTT_TwitterLED_MSP432_401R example)

Eclipse Paho JavaScript Client

Mosquitto MQTT Broker

 

 

In my previous post, I outlined how to set up MQTT with Websockets on a Beaglebone Black using Mosquitto.  Here, I will show how to use that config and combine it with an MSP432 and CC3100 MQTT example to send and receive data from the CC3100 using MQTT.

 

Part1

Safe and Sound Wearables- Hearing Guard System #13: MSP432 and CC3100 MQTT with Websockets Part I

 

To get started with MQTT on the MSP432 with CC3100 in Code Composer Studio, I had a look at Jan Cumps' posting which covers security questions with MQTT on the MSP432 with the CC3100 Booster pack.

https://www.element14.com/community/community/design-challenges/texas-instruments-safe-sound-wearables-design-challenge/blog/2016/12/02/msp432-and-cc3100-can-we-make-the-mqtt-example-safe

 

Like in Jan's example, I used the MSPWare CC3100BOOST_MQTT_TwitterLED_MSP432_401R example. However, in my case, I do not wish to publish anything on the web and want to keep the communication local. To perform this I had to edit the example code as such.

 

The first thing is to import the CC3100BOOST_MQTT_TwitterLED_MSP432_401R example from MSP432Ware.  I'm using CCS 6.2 and importing from Resource Explorer does not work all the time so I had to import the project directly from the appropriate folder.

 

On my system, this ended up at:

C:\ti\tirex-content\msp\msp432ware__3.50.00.02\examples\boards\MSP-EXP432P401R\MSP-EXP432P401R_Software_Examples\Firmware\Source\CC3100BOOST_MQTT-TwitterLED_MSP432P401R

 

From CCS, click on Project-> Import CCS Projects and navigate to the location of the example.

 

image

 

Once this is located and the 'OK' Button is clicked, the project should show up in the 'Discovered Projects' window.

 

image

 

Click 'Finish' and the project should be imported into CCS.

 

image

 

NOTE: There is README.txt with some instruction with regards to how to set-up the code for your particular environment.

 

In the 'main.c' file, locate the section of code that allows you to set the network parameters.

/*
 * Values for below macros shall be modified per the access-point's (AP) properties
 * SimpleLink device will connect to following AP when the application is executed
 */
//#define SSID_NAME       "<Your_AP's_SSID>"       /* Access point name to connect to. */
#define SSID_NAME       "YourSSID"       /* Access point name to connect to. */
#define SEC_TYPE        SL_SEC_TYPE_WPA_WPA2     /* Security type of the Access piont */
//#define PASSKEY         "<Your_AP's_Password>"   /* Password in case of secure AP */
#define PASSKEY         "WPA_WPA2_PASSWORD"   /* Password in case of secure AP */
#define PASSKEY_LEN     pal_Strlen(PASSKEY)      /* Password length in case of secure AP */

 

NOTE: As Jan pointed out, like with setting the Wireless connection on a RasPi or Beaglebone, or Linux system in general, the SSID and Password to your Wi-Fi config will be exposed. At least in this case it is in the compiled code.

 

Set the SSID_NAME and PASSKEY appropriately.

 

 

Next, locate the section of code that shows the defines for the MQTT broker  and set the MQTT_BROKER_SERVER to the appropriate IP as well as define the SUBSCRIBE_TOPIC and PUBLISH_TOPIC defines.

 

/*
 * MQTT server and topic properties that shall be modified per application
 */
//#define MQTT_BROKER_SERVER  "iot.eclipse.org"
//#define SUBSCRIBE_TOPIC "/msp/cc3100/demo"

#define MQTT_BROKER_SERVER  "YOUR_BROKER_IP"

#define SUBSCRIBE_TOPIC "/test/topic"
#define PUBLISH_TOPIC "/msp/cc3100/demo/fromLP"
//#define PUBLISH_TOPIC "/test/topic"

 

 

The example code will generate a uniqueID for the CC3100 based on the MAC address

 

    // Generate 32bit unique ID from TLV Random Number and MAC Address
    generateUniqueID();

 

 

I added a variable for the mqqt_port since it was hardcoded in the function call

 

     int rc = 0;
    unsigned char buf[100];
    unsigned char readbuf[100];
    int mqtt_port = 8883;  //  Added for MQTT port

 

 

I changed some of the CLI_Write statements just to debug the topic assignments

 

    if (rc != 0) {
        CLI_Write(" Failed to subscribe to /msp/cc3100/demo topic \n\r");
        LOOP_FOREVER();
    }
    //CLI_Write(" Subscribed to /msp/cc3100/demo topic \n\r");
    CLI_Write(" Subscribed to ");
    CLI_Write(SUBSCRIBE_TOPIC);
    CLI_Write(" topic \n\r");


    rc = MQTTSubscribe(&hMQTTClient, uniqueID, QOS0, messageArrived);


    if (rc != 0) {
        CLI_Write(" Failed to subscribe to uniqueID topic \n\r");
        LOOP_FOREVER();
    }
    //CLI_Write(" Subscribed to uniqueID topic \n\r");
    CLI_Write(" Subscribed to ");
    CLI_Write(uniqueID);
    CLI_Write(" topic \n\r");

 

 

Also, I changed some of the reporting for the Publish section to ensure it was sending to the correct topic.

 

        if (publishID) {
            int rc = 0;
            MQTTMessage msg;
            msg.dup = 0;
            msg.id = 0;
            msg.payload = uniqueID;
            msg.payloadlen = 8;
            msg.qos = QOS0;
            msg.retained = 0;
            rc = MQTTPublish(&hMQTTClient, PUBLISH_TOPIC, &msg);


            if (rc != 0) {
                CLI_Write(" Failed to publish unique ID to MQTT broker \n\r");
                LOOP_FOREVER();
            }
            CLI_Write(" Published unique ID successfully \n\r");
            CLI_Write(PUBLISH_TOPIC);
            CLI_Write("\n\r");


            publishID = 0;
        }

 

 

In the example, to generate the uniqueID, it combines a random number and the MAC address.

 

static void generateUniqueID() {
    CRC32_setSeed(TLV->RANDOM_NUM_1, CRC32_MODE);
    CRC32_set32BitData(TLV->RANDOM_NUM_2);
    CRC32_set32BitData(TLV->RANDOM_NUM_3);
    CRC32_set32BitData(TLV->RANDOM_NUM_4);
    int i;
    for (i = 0; i < 6; i++)
    CRC32_set8BitData(macAddressVal[i], CRC32_MODE);


    uint32_t crcResult = CRC32_getResult(CRC32_MODE);
    sprintf(uniqueID, "%06X", crcResult);
}

 

 

When a message arrives, a message callback function takes the message and parses the data from it to enable the appropriate RGB LEDs on the MSP432.

 

//****************************************************************************
//
//!    \brief MQTT message received callback - Called when a subscribed topic
//!                                            receives a message.
//! \param[in]                  data is the data passed to the callback
//!
//! \return                        None
//
//****************************************************************************
static void messageArrived(MessageData* data) {
    char buf[BUFF_SIZE];
    CLI_Write("Message arrrived \n\r");
    char *tok;
    long color;


    // Check for buffer overflow
    if (data->topicName->lenstring.len >= BUFF_SIZE) {
//      UART_PRINT("Topic name too long!\n\r");
        return;
    }
    if (data->message->payloadlen >= BUFF_SIZE) {
//      UART_PRINT("Payload too long!\n\r");
        return;
    }

    strncpy(buf, data->topicName->lenstring.data,
        min(BUFF_SIZE, data->topicName->lenstring.len));
    buf[data->topicName->lenstring.len] = 0;

    strncpy(buf, data->message->payload,
        min(BUFF_SIZE, data->message->payloadlen));
    buf[data->message->payloadlen] = 0;


    tok = strtok(buf, " ");
    color = strtol(tok, NULL, 10);
    TA0CCR1 = PWM_PERIOD * (color/255.0);                 // CCR1 PWM duty cycle
    tok = strtok(NULL, " ");
    color = strtol(tok, NULL, 10);
    TA0CCR2 = PWM_PERIOD * (color/255.0);                // CCR2 PWM duty cycle
    tok = strtok(NULL, " ");
    color = strtol(tok, NULL, 10);
    TA0CCR3 = PWM_PERIOD * (color/255.0);                  // CCR3 PWM duty cycle

    return;
}

 

 

The example code uses an IRQ Handler to process the button presses and send either a message with the uniqueID or the MAC Address.

 

/*
 * Port 1 interrupt handler. This handler is called whenever the switch attached
 * to P1.1 is pressed.
 */
void PORT1_IRQHandler(void)
{
    uint32_t status = GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
    GPIO_clearInterruptFlag(GPIO_PORT_P1, status);


    if (status & GPIO_PIN1)
    {
        if (S1buttonDebounce == 0)
        {
            S1buttonDebounce = 1;


            GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);


            // Publish the unique ID
            publishID = 1;
            CLI_Write("** PublishID \n\r ");
            CLI_Write(publishID);
            CLI_Write("\n\r");


            MAP_Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_UP_MODE);
        }
    }
    if (status & GPIO_PIN4)
    {
        if (S2buttonDebounce == 0)
        {
            S2buttonDebounce = 1;


            CLI_Write(" MAC Address: \n\r ");
            CLI_Write(macStr);
            CLI_Write("\n\r");


            MAP_Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_UP_MODE);
        }
    }
}

 

 

Compile and Run the code.

 

To view the UART output, find the COM port associated with the  'XDS110 Class Application/User UART.

This is COM3 on my system.

 

image

 

Open a serial port connection to the XDS110 COM port.

Settings:

Speed (baud):  9600

Data bits:          8

Stop bits:          1

Parity:               None

Flow control:     XON/XOFF (I'm not sure if this matters)

 

On a Mac system, the serial port can be opened as:

This is what it looks like on my system but may not be the same in all cases

screen /dev/cu.usbmodem123jon11 9600

 

On Windows, I use PuTTY.

 

When the example code is run, the output to the serial port should resemble the following:

NOTE: If nothing is seen on the screen, press the Reset button on the MSP432 to reset the config.

 

MQTT Twitter Controlled RGB LED - Version 1.0.0
*******************************************************************************
 Device is configured in default state
 Device started as STATION
 Connection established w/ AP and IP is acquired
 Connected to MQTT broker
 Started MQTT client successfully
 Subscribed to /test/topic topic
 Subscribed to 765521EB topic

 

NOTE: The board first starts in the default config but then switches to a STATION.  If all goes well, the connection will be acquired and should show the connection to the MQTT broker as well as Subscription to the topics.  The 'uniqueID topic is listed as well as:

    Subscribed to 765521EB topic

 

When sending a message to a topic the CC3100 is subscribed to, a 'Message arrived' message will be seen:

 

Message arrived
Message arrived
Message arrived

 

 

When SW1 is Pressed on the MSP432, the code will Publish to topic uniqueID ;'765521EB' in this case

This is the added code I put to see what is happening when Publishing and Subscribing from the CC3100

 

** PublishID

 Published unique ID successfully
/msp/cc3100/demo/fromLP

 

 

If SW2 is pressed, the MAC Address will be reported.

 

MAC Address:
 f4:b8:5e:3c:f1:7e

 

 

To test this, the MQTT config from my previous post can be used.

Using the Beaglebone, ensure the Mosquitto MQTT broker is running

 

joiot@beaglebone:~$ sudo mosquitto -c /etc/mosquitto/mosquitto.conf
1496620491: mosquitto version 1.4.12 (build date 2017-05-29 17:29:22+0000) starting
1496620491: Config loaded from /etc/mosquitto/mosquitto.conf.
1496620491: Opening ipv4 listen socket on port 1883.
1496620491: Opening ipv4 listen socket on port 8883.
1496620491: Opening websockets listen socket on port 8083.

 

Reset the MSP432.

NOTE: If all is configured properly, the MQTT Broker should indicate that a new connection has been established with the uniqueID from the CC3100:

 

1496620596: New connection from 192.168.2.101 on port 8883.
1496620596: New client connected from 192.168.2.101 as 765521EB (c1, k60).

 

In separate windows, subscribe to the uniqueID topic, '765521EB' in this instance, as well as the '/msp/cc3100/demo/fromLP' topic.

 

joiot@beaglebone:~/MQTT$ sudo mosquitto_sub -v -h 192.168.2.202 -p 8883 -t '/msp/cc3100/demo/fromLP'

joiot@beaglebone:~$ sudo mosquitto_sub -v -h 192.168.2.202 -p 8883 -t '765521EB'765521EB

 

 

When SW1 on the MSP432 is pressed, the uniqueID from the CC3100 should appear with the '/msp/cc3100/demo/fromLP' topic:

Ex:

/msp/cc3100/demo/fromLP 765521EB

 

 

The RasPi config can be used as third system to Publish a message to the CC3100 topic and enable a RGB LED on the MSP432.

Ex: Green LED Enabled and Disabled

pi@jiot2:~ $ sudo mosquitto_pub -h 192.168.2.202 -p 8883  -t '765521EB' -m '0 255 0'
pi@jiot2:~ $ sudo mosquitto_pub -h 192.168.2.202 -p 8883  -t '765521EB' -m '0 0 0'

 

 

This also should be seen from the device that is subscribed to the '765521EB' topic:

Ex:

joiot@beaglebone:~$ sudo mosquitto_sub -v -h 192.168.2.202 -p 8883 -t '765521EB

765521EB 0 255 0
765521EB 0 0 0

 

The Green LED on the MSP432 should light in this case.

Ex:

image

 

 

I grabbed another Javascript MQTT with Websockets example and made some changes to send a message to the CC3100 to light the RGB LEDs on the MSP432.

This was downloaded from:

https://github.com/hexagon5un/mqtt-javascript-demo

 

The code is pretty basic and easy to implement and uses the Paho MQTT Client.

The 'index.html' looks like this:

<!DOCTYPE html>
<html>


        <head>
                <meta charset="UTF-8">
                <title>MQTT MSP432 CC3100</title>
        </head>


        <body>


                <h2 align=center>MQTT Example of Websockets with MSP432 and CC3100!</h2>


                <h3 id="id_status">Waiting for ID status update...</h3>
                <h3 id="test_status">Waiting for Test  status update...</h3>


                <button style="background-color:tomato;width:250;height:200" id="status_button0" type="button" onclick="led0_toggle();"><b>Click Me to Toggle RED LED!</b></button>
                <button style="background-color:chartreuse" id="status_button1" type="button" onclick="led1_toggle();"><b>Click Me to Toggle GREEN LED!</b></button>
                <button style="background-color:#1E90FF" id="status_button2" type="button" onclick="led2_toggle();"><b>Click Me to Toggle BLUE LED!</b></button>


                <!-- Source Paho MQTT Client-->
                <script src="lib/mqttws31.js"></script>
                <!-- Our Code Goes Here -->
                <script src="button_test.js"></script>
                <!-- Start it up! -->
                <script>connect();</script>


        </body>
</html>

 

 

The 'button_test.js' looks like this.

NOTE: I left the original author's name in place so I am not sure if this is correct since I did modify the original code but thought they should get cred for it none the less.

 

/*
   Eclipse Paho MQTT-JS Utility
   by Elliot Williams for Hackaday article,
*/


// Global variables
var client       = null;
var led0_is_on    = null;
var led1_is_on    = null;
var led2_is_on    = null;
// These are configs
var hostname       = "192.168.2.202";
//var port           = "9001";
var port           = "8083";
var clientId       = "mqtt_js_" + parseInt(Math.random() * 100000, 10);
var id_topic   = "/msp/cc3100/demo/fromLP";
//var test_topic     = "test/topic";
var test_topic     = "765521EB";


// This is called after the webpage is completely loaded
// It is the main entry point into the JS code
function connect(){
        // Set up the client
        client = new Paho.MQTT.Client(hostname, Number(port), clientId);
        console.info('Connecting to Server: Hostname: ', hostname,
                        '. Port: ', port, '. Client ID: ', clientId);


        // set callback handlers
        client.onConnectionLost = onConnectionLost;
        client.onMessageArrived = onMessageArrived;


        // see client class docs for all the options
        var options = {
                onSuccess: onConnect, // after connected, subscribes
                onFailure: onFail,     // useful for logging / debugging
                //userName: "",
                //password: ""
        };
        // connect the client
        client.connect(options);
        console.info('Connecting...');
}


function onConnect(context) {
        console.log("Client Connected");
    // And subscribe to our topics      -- both with the same callback function
        options = {qos:0, onSuccess:function(context){ console.log("subscribed"); } }
        client.subscribe(id_topic, options);
        client.subscribe(test_topic, options);
}

 

The screen shot of this looks like the following:

image

 

When the CC3100 subscribes to the MQTT broker, the ID status will change to the uniqueID of the CC3100.

image

 

This works the same as Publishing from command line, so if the Toggle RED LED button is pressed, this will be reported to the '765521EB' topic to toggle the LED on the MSP432.

 

joiot@beaglebone:~$ sudo mosquitto_sub -v -h 192.168.2.202 -p 8883 -t '765521EB'765521EB

765521EB 255 0 0
765521EB 0 0 0

 

Also, the MQTT Broker will indicate that the Websocket  has been established:

1496622622: New client connected from 192.168.2.102 as mqtt_js_13043 (c1, k60).

 

 

So, that is pretty much it.  This has shown how to configure an Mosquitto MQTT Broker on a Beaglebone Black using Debian, how to Publish and Subscribe to topics using a Mosquitto client, how to set up MQTT Websockets and use Javascript using a Paho Client to connect to the topics and send messages as well as to configure a CC3100 running on a MSP432 to Publish and Subscribe to MQTT topics using an Embedded MQTT client.

 

My next step is to get all this working in TI-RTOS and merge it with my existing Hearing Guard System. Time is ticking away though.

 

Here be a vid that shows all of this working.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply

Top Comments

  • DAB
    DAB over 8 years ago +1
    Great detailed post. DAB
  • DAB
    DAB over 8 years ago

    Great detailed post.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago
    Time is ticking away though.

     

    June 26th. That's still doable image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube