Makers Blog Archive
138 views 0 comments

Mosquitto is an open source project to implement an MQTT client to your system. The MQTT (Message Queue Telemetry Transport) protocol is made for machine-to-machine (M2M) connectivity, basing on an extremely lightweight messaging using a publish/subscribe model. This makes it suitable for Internet of Things messaging such as with low power sensors or embedded computers.

The Mosquitto project also provides a C library for implementing MQTT clients, and the very popular mosquitto_pub and mosquitto_sub command line MQTT clients.

Let’s see how to crosscompile it for PLCnext Controls.

Find the documentation at Mosquitto on Github and at the Mosquitto Project website.

Build dependencies

Mosquitto can be built with many dependencies.
In this tutorial we will include the following:

  • libuuid (uuid-dev) – enable with make WITH_UUID=yes
  • libwebsockets (libwebsockets-dev) – enable with make WITH_WEBSOCKETS=yes
  • openssl (libssl-dev on Debian based systems) – disable with make WITH_TLS=yes

Note: If you want additional functions you might have to add the crosscompiled dependencies to the SDK sysroot at $sysroot/usr/local/* (and later to the controller if you are using dynamic linking).

Libwebsockets can be included into Mosquitto for websocket support of the broker. libuuid and openssl are already included in FW 1.1.0 of the AXC F 2152 controller. See the Crosscompile Guide to the Libwebsockets API for reference how to compile.

Modify config.mk

In this config file, the installation details are stored and the default values are set. The defaults can also be overriden while executing make.

INSTALL?=install
prefix=/home/ow/CrossCompiling/Install # here the binaries *.so, executeables, and headers will be stored
mandir=${prefix}/share/man
localedir=${prefix}/share/locale
STRIP?=strip
DESTDIR=/home/ow/CrossCompiling/Install # here the `/etc/mosquitto` folder will be stored

Compile with

  1. source /opt/pxc/current/environment-setup-cortexa9t2hf-neon-pxc-linux-gnueabi
  2. cd mosquitto/man and for file in *.xml; do mv "$file" "$(basename "$file" .xml)"; done – this is necessary to convert files.
  3. Clear this variable or it will be used twice: CROSS_COMPILE=
  4. make -j8 WITH_WEBSOCKETS=yes WITH_TLS=yes WITH_UUID=yes WITH_DOCS=no
  5. sudo mkdir /etc/mosquitto && sudo chown yourUser /etc/mosquitto
  6. make install
  7. check if everything went right:arm-pxc-linux-gnueabi-objdump -p ~/CrossCompiling/Install/sbin/mosquitto | grep NEEDED NEEDED libdl.so.2 NEEDED libm.so.6 NEEDED librt.so.1 NEEDED libssl.so.1.0.0 NEEDED libcrypto.so.1.0.0 NEEDED libuuid.so.1 NEEDED libwebsockets.so.13 NEEDED libc.so.6file ~/CrossCompiling/Install/lib/libmosquitto* /home/ow/CrossCompiling/Install/lib/libmosquittopp.so: symbolic link to libmosquittopp.so.1 /home/ow/CrossCompiling/Install/lib/libmosquittopp.so.1: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=17fa452aedbc367f7cea715b2e91d49e395f88e9, not stripped /home/ow/CrossCompiling/Install/lib/libmosquittopp.so.1.5.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=ca543a884169037c35501fbcdc8cd2870fbbc526, not stripped /home/ow/CrossCompiling/Install/lib/libmosquitto.so: symbolic link to libmosquitto.so.1 /home/ow/CrossCompiling/Install/lib/libmosquitto.so.1: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=c4f29c1e6beae9d6615775674bdef1c419a46d8f, not stripped /home/ow/CrossCompiling/Install/lib/libmosquitto.so.1.5.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=6fe235c6d0b3ec9dcef5693c97c0628ef3702bbc, not stripped

Deploy

Copy the contents of Install to your controller:

  • lib = here you will find the shared library if you want to use mosquitto
  • bin = for the mosquitto_passwdmosquitto_sub and mosquitto_pub executeables
  • sbin = for the broker
  • include = if you need headerfiles on target

Also copy the /etc/mosquitto folder: the default config file is stored here, it is needed if you want to run the broker.

Not included

  • c-ares (libc-ares-dev on Debian based systems) – disable with make WITH_SRV=no
  • xsltproc (xsltproc and docbook-xsl on Debian based systems) – only needed when building from Git sources – disable with make WITH_DOCS=no

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.

Discussion

Please login/register to comment
Login/Register
Newsletter
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users