charlie388 / cpp-mqtt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using paho c++ MQTT Client in a CMake project

  • Paho libaries (c, c++) are linked statically
  • OpenSSL and Standard C libaries are linked dynamically

Start Coding in the Browser

Open in GitHub Codespaces

Within the codespace instance a mosquitto MQTT broker is started automatically for testing. See folder test for configuration and folder .devcontainer for start-up commands.

(You will need a github account to do so)

Use Codespace to compile and develop

After the codespace instance has started it ask you to choose your tool chain. Click von the marked entry

Then you may recognize that in one of the console windows the log output of a mosquitto broker can be observed. The configuration of this instance is taken from the file ./test/mosquitto.conf

To be ready for compilation you have to choose the configuration from the bottom menu. Choose either Degub or Release.

Then click on "Run" which will first ask for the build target choose 'cpp-mqtt'

The build process will first fetch the git submodules for the Paho C/C++ client libaries, build the application and finaly create a self-signed certififcate for the use of TLS.

You can then see the sample application running and watch the different print outs

Build local

If you prefer to see and use the sample code on your own environment on a local PC clone the source code from here and proceed like this.

git clone https://github.com/charlie388/cpp-mqtt.git
cd cpp-mqtt
# create makefiles (test on ubuntu 16.04)
cmake -S ./ -Bbuild -G Ninja
# build
cmake  --build ./build --target all --

This will create an executable application named cpp-mqtt in the build folder.

Blog post

Read here the corresponding blog post: https://cedalo.com/blog/implement-paho-mqtt-c-cmake-project/

Notes

  • CMake is set up only for compiling and running on Linux OS. To cross-build and/or run on Windows modifications are necessary for the linked libraries.

About

License:GNU General Public License v3.0


Languages

Language:C++ 68.5%Language:Shell 13.1%Language:CMake 12.9%Language:Dockerfile 5.5%