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 #13: MSP432 and CC3100 MQTT with Websockets Part I
  • 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: 4 Jun 2017 9:44 AM Date Created
  • Views 613 views
  • Likes 5 likes
  • Comments 1 comment
  • debian
  • mqtt
  • javascript
  • websockets
  • msp432
  • cc3100
  • BeagleBone Black
Related
Recommended

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

jomoenginer
jomoenginer
4 Jun 2017

MSP432 and CC3100 MQTT with Websockets Part I (Beaglebone 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

 

PartII

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

 

As part of my Hearing Guard System, I intend to implement MQTT between the Base Station and Room Monitor in order to monitor any events that were triggered as well as gather user data.  The data would be collected between the Personal Noise Sensor and the Room Monitor and then this data could be collected by the Base Station to be viewed via a web page or processed by some sort of data collect app.

 

There are plenty of good resources on the web as well as on Element14 that outline how to set up an MQTT environment using an Embedded Linux device such as Raspberry Pi or Beagelbone Black and I will list the sites that I used to assist me with this.  The issue that I ran into was that I could not find a single site that provided all of the info that I needed to setup the config that I want to use;  Mosquitto MQTT Broker on an Beaglebone Black with Websockets as well as a Javascript MQTT Client that I could access from any device in the same network.

 

MQTT Config on Beaglebone Black with Websockets: Debian version (7.11 in this instance)

 

To get started, I found installing the following packages on the Beagelbone helped resolve any dependencies that were needed along the way.

 

sudo apt-get update
 sudo apt-get install parted
 sudo apt-get install xfce4-goodies
 sudo apt-get install gnome-icon-theme
 sudo apt-get install iceweasel
 sudo apt-get install build-essential gcc make cmake cmake-gui cmake-curses-gui
 sudo apt-get install libssl-dev
 sudo apt-get install git
 sudo apt-get install build-essential libcgicc5 libcgicc5-dev libcgicc-doc
 sudo apt-get install apache2
 sudo apt-get install -y nodejs
 sudo apt-get install build-essential python quilt devscripts python-setuptools
 sudo apt-get install cmake
 sudo apt-get install libc-ares-dev
 sudo apt-get install uuid-dev
 sudo apt-get install daemon


sudo ldconfig

 

 

On the Beaglebone, it would be a good idea to disable the following:

 

 

733  sudo systemctl stop bonescript.socket
  734  sudo systemctl stop bonescript.service
  735  sudo systemctl disable bonescript.socket
  736  sudo systemctl disable bonescript.service

 

 

For Websocket support with Mosquitto, I installed the following lib:

 

mkdir MQTT
cd MQTT
git clone https://github.com/warmcat/libwebsockets.git

cd libwebsockets/
ls
mkdir build
cd build/
cmake ..
make && sudo make install
ldconfig
sudo ldconfig

 

Once these are installed, installing Mosquitto and websockets should go smoothly.

 

Installing the Mosquitto Broker and Client could be performed using the standard Debian 'apt-get' tool.

 

sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients

 

This should work for a client (Although Eclipse suggests using Paho as a MQTT client), but the issue with this is that Websockets are disabled by default in Mosquitto and there is no config file or option to enable this.  The only way to enable this is to download the source code, enable Websockets in the 'build.mk', and then rebuild and install mosquitto.

 

To download the Mosquitto source and add websocket support, use the following:

Mosquitto Debian repository

 

 

cd MQTT

 wget http://mosquitto.org/files/source/mosquitto-1.4.12.tar.gz
 tar zxvf mosquitto-1.4.12.tar.gz 
 cd mosquitto-1.4.12

 vim config.mk

 

 

Find the entry that shows WITH_WEBSOCKETS. This will be set to 'no' out of box, but to enable websockets, change this to 'yes'.

Ex:

 

67 # Build with websockets support on the broker.
 68 WITH_WEBSOCKETS:=yes

 

Save the file and rebuild mosquitto and install it:

 

make && sudo make install
sudo ldconfig

 

 

To set up the Mosquitto Broker for this config with Websockets, a few items need to be changed in the mosquitto.conf file.  This file will not be in place by default, so it would have to be created as follows.

 

mkdir /var/lib/mosquitto/
chown mosquitto:mosquitto /var/lib/mosquitto/ -R

cp /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf
vim /etc/mosquitto/mosquitto.conf

 

In the 'mosquitto.conf' file, add the following:

 

listener 1883 localhost
listener 8883 <your Broker IP address>
#Enable websockets
listener 8083
protocol websockets

persistence true
persistence_location /var/lib/mosquitto/
persistence_file mosquitto.db
log_dest syslog
log_dest stdout
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
# I have not enabled username and password on CC3100 so no passwords are configured.
allow_anonymous true

 

After editing the file, run the following to resync the config:

 

/sbin/ldconfig

 

 

The 'iptables' on the Broker system must be set to ensure it will allow incoming traffic on the broker and websocket ports.

 

sudo iptables -A INPUT -p tcp -m tcp --dport 8883 -j ACCEPT
 sudo iptables -A INPUT -p tcp -m tcp --dport 8083 -j ACCEPT

 

To test that the Mosquitto Broker is working, start the broker instance. This is running on the Beaglebone in this instance:

 

$ sudo mosquitto -c /etc/mosquitto/mosquitto.conf
[sudo] password for joiot: 
1496562603: mosquitto version 1.4.12 (build date 2017-05-29 17:29:22+0000) starting
1496562603: Config loaded from /etc/mosquitto/mosquitto.conf.
1496562603: Opening ipv4 listen socket on port 1883.
1496562603: Opening ipv4 listen socket on port 8883.
1496562603: Opening websockets listen socket on port 8083.
1496562663: New connection from 192.168.2.202 on port 8883.

 

NOTE: There is a line showing that broker is opening websockets to listen on port 8083 as was configure in mosquitto.con. This is a good sign.

 

 

Subscribe to a 'test/topic' topic on a system in the network. On the Beaglebone in this instance using the Mosquitto MQTT client.

 

sudo mosquitto_sub -v -h 192.168.2.202 -p 8883 -t 'test/topic'

 

When a MQTT Client subscribes to a topic, the Broker should indicate the connection.

This was seen in this instance:

1496562663: New connection from 192.168.2.202 on port 8883.
1496562663: New client connected from 192.168.2.202 as mosqsub/20663-beaglebon (c1, k60).

 

Publish a test message to the 'test/topic' from another system to ensure the broker is accessilbe by other systems. Raspberry Pi in this instance using the Mosquitto MQTT client.

 

pi@jiot2:~ $ sudo mosquitto_pub -h 192.168.2.202 -p 8883  -t 'test/topic' -m 'Test 1 2 3'

 

Again, the broker should indicate that a new connection was made by a client. However, when a client publishes to a topic, the connection will be dropped once the message is sent. There is no need to keep the connection open.

Ex:

1496562768: New connection from 192.168.2.130 on port 8883.
1496562768: New client connected from 192.168.2.130 as mosqpub/10136-jiot2 (c1, k60).
1496562768: Client mosqpub/10136-jiot2 disconnected.

 

On the system that subscribed to the 'test/topic', the message from the publishing client should be seen if all is configured properly.

Ex:

joiot@beaglebone:~$ sudo mosquitto_sub -v -h 192.168.2.202 -p 8883 -t 'test/topic'

test/topic Test 1 2 3

 

 

If the message published successfully, then the Broker and the Clients are set properly to handle MQTT messaging.

 

The next step is to configure and test the websocket connect using a javascript example.

For this example I pulled down the 'simple-mqtt-websocket-example' by Jan-Piet Mens

https://github.com/jpmens/simple-mqtt-websocket-example

 

git clone https://github.com/jpmens/simple-mqtt-websocket-example.git
 ls
 cd simple-mqtt-websocket-example/
 sudo mkdir /var/www/ws_sample
 sudo cp *.js /var/www/ws_sample/
 sudo cp *.html /var/www/ws_sample/

 

Edit the config.js file to added the appropriate MQTT settings.

Ex:

 

host = '192.168.2.202'; // hostname or IP address


//port = 9001;
port = 8083;
topic = 'test';         // topic to subscribe to
useTLS = false;

 

Save the file and open the 'index.html' file in a web browser.  If all is set and websockets are configured properly, the web page should be similiar to the following screen shot:

NOTE: The published messages from the MQTT client to the 'test/topic' MQTT topic should be seen in the Mosquitto Websocket example window.

 

image

 

If the messages published to the 'test/topic' is seen in the Websocket window, then it is good indication that MQTT with Websockets is up and running properly.

 

 

Since this post went on longer than I had expect, I will split this into 2 posts (Part I and Part II).

 

In the next post I will cover configuring the MSP432 and CC3100 to Subscribe and Publish using the MQTT Broker via websockets.

 

 

 

Sites I found useful for MQTT config:

http://www.xappsoftware.com/wordpress/2015/05/18/six-steps-to-install-mosquitto-1-4-2-with-websockets-on-debian-wheezy/comment-page-1/

https://github.com/warmcat/libwebsockets.git

https://mosquitto.org/download/

https://github.com/eclipse/mosquitto

https://www.digitalocean.com/community/questions/how-to-setup-a-mosquitto-mqtt-server-and-receive-data-from-owntracks

http://www.microdev.it/wp/en/2017/03/12/mqtt-with-beaglebone-and-esp8266-mosquitto-installation-on-beaglebone/

  • Sign in to reply
  • DAB
    DAB over 8 years ago

    Nice update.

     

    You definitely make it look easier than it probably is.

     

    DAB

    • 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