element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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 - Hazardous Factors MQTT Subscriber & Publisher - blog 12
  • 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: dougw
  • Date Created: 9 Apr 2017 2:25 PM Date Created
  • Views 1499 views
  • Likes 2 likes
  • Comments 1 comment
  • mqtt_publisher
  • safe and sound
  • mqtt
  • safe and sound design challenge
  • hazardous_environmental_factors
  • invisible_hazards
  • safe & sound
  • wearable technology
  • mqtt_broker
  • Wearables
  • safe&sound
  • mqtt_subscriber
  • doug_wong
  • mqtt_lens
Related
Recommended

Safe and Sound - Hazardous Factors MQTT Subscriber & Publisher - blog 12

dougw
dougw
9 Apr 2017

I managed to purchase a second WiFi booster pack although the TI discount voucher I won here was not accepted This booster pack has allowed me to assemble a second system consisting of a  MSP-EXP432P401RMSP-EXP432P401R a CC3100ModBoost and a  430BOOST-SHARP96430BOOST-SHARP96 I have programmed the second system as an MQTT client subscribing to the IHEF data being published by my sensor platform which has the same cards plus my custom sensor booster pack Both systems use Wi-Fi to access my MQTT broker

image

The following video shows both systems booting up with MQTTLENS running in the background all interacting with my Mosquitto broker.

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

Here is the subscriber program such as it is at this moment:

/*

Invisible Hazardous Environmental Factors

by Doug Wong 2017-04-08

Remote Display via MQTT

   - connects to an MQTT server

  - subscribes to the topic "IHEF"

  - displays Alcohol, CO, Air Quality, CO2, UV

*/

 

 

#include <SPI.h>

#include <WiFi.h>

#include <PubSubClient.h>

#include <LCD_SharpBoosterPack_SPI.h>

 

 

// your network name also called SSID

char ssid[] = "AccessPoint";

// your network password

char password[] = "NetworkPassword";

// MQTTServer to use

char server[] = "brokerURL";

 

 

LCD_SharpBoosterPack_SPI myScreen;

 

 

//callback section retrieves subscribed data and displays it

void callback(char* topic, byte* payload, unsigned int length) {

    char *cstring = (char *) payload;

   if (cstring[0] == 49)    // ALC

   {

      myScreen.text(5, 17, cstring);

      myScreen.text(65, 17, " ppm  ");

   }

   if (cstring[0] == 50)    // CO

   {

      myScreen.text(5, 32, cstring);

      myScreen.text(65, 32, " ppm  ");

   }

   if (cstring[0] == 51)    // AQ

   {

      myScreen.text(5, 47, cstring);

      myScreen.text(65, 47, " ppm  ");

   }

   if (cstring[0] == 52)    // CO2

   {

      myScreen.text(5, 62, cstring);

      myScreen.text(65, 62, " ppm  ");

   }

   if (cstring[0] == 53)    // UV

   {

      myScreen.text(5, 77, cstring);

      myScreen.text(65, 77, " idx  ");

   }

   myScreen.flush();

}

 

 

WiFiClient wifiClient;

PubSubClient client(server, 1883, callback, wifiClient);

 

 

void setup()

{                         //initiallization section connects to MQTT broker

  Serial.begin(115200);

  // attempt to connect to Wifi network:

    myScreen.begin();

    myScreen.clearBuffer();

    myScreen.setFont(0); 

    myScreen.text(5, 1, "Connecting...");

    myScreen.flush();

  // Start Ethernet with the build in MAC Address

  // attempt to connect to Wifi network:

  // Connect to WPA/WPA2 network

  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED) {

    // print dots while we wait to connect

    delay(300);

  }

    myScreen.text(5, 9, "WiFi Connected ");

    myScreen.text(5, 18, "Waiting for ip");

    myScreen.flush();

  while (WiFi.localIP() == INADDR_NONE) {

    delay(300);

  }

    myScreen.text(5, 27, "IP obtained");

    myScreen.text(5, 36, WiFi.localIP());

    myScreen.flush();

    delay(300);

}

 

 

void loop()

{

  // Reconnect if the connection was lost

  if (!client.connected()) {

 

 

    if(!client.connect("IHEF")) {

 

 

    } else {

      if(client.subscribe("IHEF")) {

      myScreen.text(5, 45, "Subcribed");

      myScreen.text(5, 54, "IHEF");

      myScreen.flush();

      delay(1200);

      myScreen.clear();

      myScreen.text(20, 3, "MQTT IHEF");

      myScreen.flush();

      }

    }

  }

 

  // Check if any message were received

  // on the topic we subsrcived to

  client.poll();

  delay(1000);

}

 

My next blog will likely be about the invisible hazards of microwaves, but I am also close to starting on packaging all my instrumentation in a wearable format. The main things still missing from my project are some minor components for my custom sensor circuit card, and there is still some software work to produce calibrated sensor readings.

 

All links to blogs related to this project can be found in the first blog here:

Safe and Sound - Invisible Hazardous Environmental Factors Monitoring System - blog 1

  • Sign in to reply

Top Comments

  • DAB
    DAB over 8 years ago +1
    Nice and simple example on how to set up the MQTT exchange. DAB
Parents
  • DAB
    DAB over 8 years ago

    Nice and simple example on how to set up the MQTT exchange.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • DAB
    DAB over 8 years ago

    Nice and simple example on how to set up the MQTT exchange.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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