Skip to content

Lecrapouille/MQTT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTT: Class wrapping MQTT mosquitto

A C++11 tiny wrapper class for a MQTT client based on the mosquitto implementation. You will need small code to make your application running with a MQTT client.

Hello World example

  • In a first Linux console, a subscriber will echo messages from our application. Type:
mosquitto_sub -h localhost -t "Example/Output"
  • In a second Linux console, compile and launch our application. Type:
cd example
g++ --std=c++11 -Wall -Wextra -I../include ../src/MQTT.cpp Example.cpp -o example `pkg-config --cflags --libs libmosquitto`
./example

You will see (may be different from your case):

Connected to MQTT broker with error code 0
Message 1 subscribed. Granted QOS: 0
  • In a third Linux console, a publisher will send messages to our application. Type:
mosquitto_pub -h localhost -t "Example/Input" -m "Hello"

You will see:

  • In the first console:
Hello
  • In the second console:
Received message 0: "Hello" from topic: "Example/Input" size: 5 qos: 0
Message 2 published

In this example, once a message has been received the application is closing.

Your C++ asynchronous MQTT client is functional :)

About

Class wrapping client MQTT (mosquitto lib)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages