Pages

2017/08/28

Raspberry Pi - How to install MQTT broker and mosquitto auth plugin

This post is about how to install MQTT broker and mosquitto auth plugin.

The Environment:

- Raspberry Pi 1 Model B
- OS: Raspbian Jessie Lite
- Primary Storage: 16GB Class 10 SD Card


Installing Mosquitto Broker

Ref.: https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/

Updating the Repository

pi@raspberry:~ $ wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key

pi@raspberrypi:~ $ wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
--2017-08-27 12:15:06--  http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
Resolving repo.mosquitto.org (repo.mosquitto.org)... 85.119.83.194, 2001:ba8:1f1:f271::2
Connecting to repo.mosquitto.org (repo.mosquitto.org)|85.119.83.194|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3137 (3.1K) [application/octet-stream]
Saving to: ‘mosquitto-repo.gpg.key’

mosquitto-repo.gpg.key    100%[=====================================>]   3.06K  --.-KB/s   in 0s

2017-08-27 12:15:08 (22.5 MB/s) - ‘mosquitto-repo.gpg.key’ saved [3137/3137]

pi@raspberry:~ $ sudo apt-key add mosquitto-repo.gpg.key


Make the repository available to be installed with apt-get:

pi@raspberry:~ $ cd /etc/apt/sources.list.d/

pi@raspberrypi:/etc/apt/sources.list.d $ sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list

pi@raspberrypi:/etc/apt/sources.list.d $ sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
--2017-08-27 12:18:03--  http://repo.mosquitto.org/debian/mosquitto-jessie.list
Resolving repo.mosquitto.org (repo.mosquitto.org)... 85.119.83.194, 2001:ba8:1f1:f271::2
Connecting to repo.mosquitto.org (repo.mosquitto.org)|85.119.83.194|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 49 [application/octet-stream]
Saving to: ‘mosquitto-jessie.list’

mosquitto-jessie.list     100%[=====================================>]      49  --.-KB/s   in 0s

2017-08-27 12:18:05 (591 KB/s) - ‘mosquitto-jessie.list’ saved [49/49]

Go back to the root directory:

pi@raspberrypi:/etc/apt/sources.list.d $ cd

Finally, update apt-get information:

pi@raspberry:~ $ sudo apt-get update

pi@raspberrypi:~ $ sudo apt-get update
Hit http://mirrordirector.raspbian.org jessie InRelease
Hit http://archive.raspbian.org jessie InRelease
Get:1 http://repo.mosquitto.org jessie InRelease [3,884 B]
Hit http://mirrordirector.raspbian.org jessie/main armhf Packages
Hit http://archive.raspbian.org jessie/main armhf Packages
Hit http://mirrordirector.raspbian.org jessie/contrib armhf Packages
Hit http://archive.raspbian.org jessie/contrib armhf Packages
Get:2 http://repo.mosquitto.org jessie/main armhf Packages [2,211 B]
Hit http://mirrordirector.raspbian.org jessie/non-free armhf Packages
Hit http://archive.raspbian.org jessie/non-free armhf Packages
Hit http://mirrordirector.raspbian.org jessie/rpi armhf Packages
Hit http://archive.raspberrypi.org jessie InRelease
Hit http://archive.raspbian.org jessie/rpi armhf Packages
Ign http://repo.mosquitto.org jessie/main Translation-en_GB
Ign http://repo.mosquitto.org jessie/main Translation-en
Hit http://archive.raspberrypi.org jessie/main armhf Packages
Hit http://archive.raspberrypi.org jessie/ui armhf Packages
Ign http://archive.raspbian.org jessie/contrib Translation-en_GB
Ign http://archive.raspbian.org jessie/contrib Translation-en
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en_GB
Ign http://archive.raspbian.org jessie/main Translation-en_GB
Ign http://archive.raspbian.org jessie/main Translation-en
Ign http://archive.raspbian.org jessie/non-free Translation-en_GB
Ign http://archive.raspbian.org jessie/non-free Translation-en
Ign http://archive.raspbian.org jessie/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en
Ign http://archive.raspbian.org jessie/rpi Translation-en
Ign http://mirrordirector.raspbian.org jessie/main Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/main Translation-en
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en
Ign http://archive.raspberrypi.org jessie/main Translation-en_GB
Ign http://archive.raspberrypi.org jessie/main Translation-en
Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB
Ign http://archive.raspberrypi.org jessie/ui Translation-en
Fetched 6,095 B in 42s (143 B/s)
Reading package lists... Done

Installing Mosquitto Broker

pi@raspberry:~ $ sudo apt-get install mosquitto

pi@raspberrypi:~ $ sudo apt-get install mosquitto
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libwebsockets3
Suggested packages:
  apparmor
The following NEW packages will be installed:
  libwebsockets3 mosquitto
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 164 kB of archives.
After this operation, 433 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libwebsockets3 armhf 1.2.2-1 [40.2 kB]
Get:2 http://repo.mosquitto.org/debian/ jessie/main mosquitto armhf 1.4.14-0mosquitto1~jessie2 [123 kB]
Fetched 164 kB in 2s (75.3 kB/s)
Selecting previously unselected package libwebsockets3:armhf.
(Reading database ... 35473 files and directories currently installed.)
Preparing to unpack .../libwebsockets3_1.2.2-1_armhf.deb ...
Unpacking libwebsockets3:armhf (1.2.2-1) ...
Selecting previously unselected package mosquitto.
Preparing to unpack .../mosquitto_1.4.14-0mosquitto1~jessie2_armhf.deb ...
Unpacking mosquitto (1.4.14-0mosquitto1~jessie2) ...
Processing triggers for man-db (2.7.5-1~bpo8+1) ...
Processing triggers for systemd (215-17+deb8u7) ...
Setting up libwebsockets3:armhf (1.2.2-1) ...
Setting up mosquitto (1.4.14-0mosquitto1~jessie2) ...
Processing triggers for libc-bin (2.19-18+deb8u10) ...
Processing triggers for systemd (215-17+deb8u7) ...

Testing the Installation

pi@raspberry:~ $ mosquitto -v

This returns the Mosquitto version that is currently running in your Raspberry Pi. It should be 1.4 or above.

pi@raspberrypi:~ $ mosquitto -v
1503808188: mosquitto version 1.4.14 (build date Mon, 10 Jul 2017 23:48:43 +0100) starting
1503808188: Using default config.
1503808188: Opening ipv4 listen socket on port 1883.
1503808188: Error: Address already in use

Note: sometimes the command mosquitto -v prompts a warning message saying “Error: Address already in use”. That warning message means that your Mosquitto Broker is already running, so don’t worry about that.

Installing Mosquitto Auth Plugin

Getting the Mosquitto Broker Source Code

The source code can be downloaded from this link  - https://mosquitto.org/files/source/.


To match the version installed (v1.4.14) above, we will download "mosquitto-1.4.14.tar.gz".

pi@raspberrypi:/var/www/html $ cd ~
pi@raspberrypi:~ $ wget http://mosquitto.org/files/source/mosquitto-1.4.14.tar.gz

pi@raspberrypi:~ $ wget http://mosquitto.org/files/source/mosquitto-1.4.14.tar.gz--2017-08-27 15:33:18--  http://mosquitto.org/files/source/mosquitto-1.4.14.tar.gz
Resolving mosquitto.org (mosquitto.org)... 85.119.83.194, 2001:ba8:1f1:f271::2
Connecting to mosquitto.org (mosquitto.org)|85.119.83.194|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 365596 (357K) [application/octet-stream]
Saving to: ‘mosquitto-1.4.14.tar.gz’

mosquitto-1.4.14.tar 100%[=====================>] 357.03K   195KB/s   in 1.8s

2017-08-27 15:33:21 (195 KB/s) - ‘mosquitto-1.4.14.tar.gz’ saved [365596/365596]

pi@raspberrypi:~ $ ls

"mosquitto-1.4.14.tar.gz" is now downloaded and saved to the user's home directory.

pi@raspberrypi:~ $ ls
mosquitto-1.4.14.tar.gz  mosquitto-repo.gpg.key

Unzip 'mosquitto-1.4.14.tar.gz" with the command below.

pi@raspberrypi:~ $ tar xvzf mosquitto-1.4.14.tar.gz

pi@raspberrypi:~ $ ls
mosquitto-1.4.14  mosquitto-1.4.14.tar.gz  mosquitto-repo.gpg.key

The unzipped files are now stored in the directory - "mosquitto-1.4.14".

Getting the Mosquitto Auth Plugin

Change the working directory to where the unzipped source code is saved.

pi@raspberrypi:~ $ cd mosquitto-1.4.14
pi@raspberrypi:~/mosquitto-1.4.14 $ ls

pi@raspberrypi:~ $ cd mosquitto-1.4.14
pi@raspberrypi:~/mosquitto-1.4.14 $ ls
about.html       CONTRIBUTING.md  Makefile         readme-windows.txt
aclfile.example  edl-v10          man              security
ChangeLog.txt    epl-v10          misc             service
client           examples         mosquitto.conf   src
CMakeLists.txt   installer        notice.html      test
compiling.txt    lib              pskfile.example
config.h         LICENSE.txt      pwfile.example
config.mk        logo             readme.md

Issue the command below to clone the source of the mosquitto auth plugin.

pi@raspberrypi:~/mosquitto-1.4.14 $ git clone https://github.com/jpmens/mosquitto-auth-plug.git

pi@raspberrypi:~/mosquitto-1.4.14 $ git clone https://github.com/jpmens/mosquitto-auth-plug.git
-bash: git: command not found

Install the missing git command.

pi@raspberrypi:~/mosquitto-1.4.14 $ cd
pi@raspberrypi:~ $ sudo apt-get install git

After git is installed, use the below commands to clone the plugin again.

pi@raspberrypi:~ $ cd mosquitto-1.4.14
pi@raspberrypi:~/mosquitto-1.4.14 $ git clone https://github.com/jpmens/mosquitto-auth-plug.git

pi@raspberrypi:~/mosquitto-1.4.14 $ git clone https://github.com/jpmens/mosquitto-auth-plug.git
Cloning into 'mosquitto-auth-plug'...
remote: Counting objects: 1260, done.
remote: Total 1260 (delta 0), reused 0 (delta 0), pack-reused 1260
Receiving objects: 100% (1260/1260), 443.17 KiB | 250.00 KiB/s, done.
Resolving deltas: 100% (774/774), done.
Checking connectivity... done.

Check the cloned source.

pi@raspberrypi:~/mosquitto-1.4.14 $ ls

pi@raspberrypi:~/mosquitto-1.4.14 $ ls
about.html       CONTRIBUTING.md  Makefile             readme.md
aclfile.example  edl-v10          man                  readme-windows.txt
ChangeLog.txt    epl-v10          misc                 security
client           examples         mosquitto-auth-plug  service
CMakeLists.txt   installer        mosquitto.conf       src
compiling.txt    lib              notice.html          test
config.h         LICENSE.txt      pskfile.example
config.mk        logo             pwfile.example

pi@raspberrypi:~/mosquitto-1.4.14 $ cd mosquitto-auth-plug
pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ ls

pi@raspberrypi:~/mosquitto-1.4.14 $ cd mosquitto-auth-plug
pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ ls
auth-plug.c  be-http.c   be-mysql.h     cache.c       LICENSE.txt
backends.c   be-http.h   be-postgres.c  cache.h       log.c
backends.h   be-jwt.c    be-postgres.h  config.mk.in  log.h
base64.c     be-jwt.h    be-psk.c       contrib       Makefile
base64.h     be-ldap.c   be-psk.h       envs.c        np.c
be-cdb.c     be-ldap.h   be-redis.c     envs.h        pbkdf2-check.c
be-cdb.h     be-mongo.c  be-redis.h     examples      README.md
be-files.c   be-mongo.h  be-sqlite.c    hash.c        userdata.h
be-files.h   be-mysql.c  be-sqlite.h    hash.h        uthash.h

Make a copy of "config.mk.in".

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ cp config.mk.in config.mk

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ cp config.mk.in config.mkpi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ ls
auth-plug.c  be-http.h      be-postgres.h  config.mk.in  Makefile
backends.c   be-jwt.c       be-psk.c       contrib       np.c
backends.h   be-jwt.h       be-psk.h       envs.c        pbkdf2-check.c
base64.c     be-ldap.c      be-redis.c     envs.h        README.md
base64.h     be-ldap.h      be-redis.h     examples      userdata.h
be-cdb.c     be-mongo.c     be-sqlite.c    hash.c        uthash.h
be-cdb.h     be-mongo.h     be-sqlite.h    hash.h
be-files.c   be-mysql.c     cache.c        LICENSE.txt
be-files.h   be-mysql.h     cache.h        log.c
be-http.c    be-postgres.c  config.mk      log.h

Edit the content of "config.mk".

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ sudo nano config.mk

Modify the below 2 lines by adding the red parts.

MOSQUITTO_SRC = /home/pi/mosquitto-1.4.14
OPENSSLDIR = /usr/local/openssl

Note, Be sure there is no space at the end of the 2 red parts.

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ cat config.mk
# Select your backends from this list
BACKEND_CDB ?= no
BACKEND_MYSQL ?= yes
BACKEND_SQLITE ?= no
BACKEND_REDIS ?= no
BACKEND_POSTGRES ?= no
BACKEND_LDAP ?= no
BACKEND_HTTP ?= no
BACKEND_JWT ?= no
BACKEND_MONGO ?= no
BACKEND_FILES ?= no

# Specify the path to the Mosquitto sources here
# MOSQUITTO_SRC = /usr/local/Cellar/mosquitto/1.4.12
MOSQUITTO_SRC = /home/pi/mosquitto-1.4.14

# Specify the path the OpenSSL here
#OPENSSLDIR = /usr
OPENSSLDIR = /usr/local/openssl

# Specify optional/additional linker/compiler flags here
# On macOS, add
#       CFG_LDFLAGS = -undefined dynamic_lookup
# as described in https://github.com/eclipse/mosquitto/issues/244
#
# CFG_LDFLAGS = -undefined dynamic_lookup  -L/usr/local/Cellar/openssl/1.0.2l/lib
# CFG_CFLAGS = -I/usr/local/Cellar/openssl/1.0.2l/include -I/usr/local/Cellar/mosquitto/1.4.12/include
CFG_LDFLAGS =
CFG_CFLAGS =

Use ctrl-x to save the changes, then issue the "make" command to compile.

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ make

The command fails with the following output message.

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ make
Selected backends:          MySQL
Using mosquitto source dir: /home/pi/mosquitto-1.4.14
OpenSSL install dir:        /usr/local/openssl

If you changed the backend selection, you might need to 'make clean' first

CFLAGS:   -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  -I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing    -g -DNDEBUG -I/src -DDEBUG=1 -I/usr/local/openssl/include
LDFLAGS:   -L/home/pi/mosquitto-1.4.14/lib/
LDADD:    -L/usr/lib/arm-linux-gnueabihf -lmysqlclient -lpthread -lz -lm -ldl -L/usr/local/openssl/lib -lcrypto -lmosquitto

cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o auth-plug.o auth-plug.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o base64.o base64.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o pbkdf2-check.o pbkdf2-check.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o log.o log.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o envs.o envs.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o hash.o hash.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o be-psk.o be-psk.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o backends.o backends.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o cache.o cache.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o be-mysql.o be-mysql.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -L/home/pi/mosquitto-1.4.14/lib/ -fPIC -shared -o auth-plug.so auth-plug.o base64.o pbkdf2-check.o log.o envs.o hash.o be-psk.o backends.o cache.o be-mysql.o   `mysql_config --libs` -L/usr/local/openssl/lib -lcrypto -lmosquitto
/usr/bin/ld: cannot find -lmosquitto
collect2: error: ld returned 1 exit status
Makefile:142: recipe for target 'auth-plug.so' failed
make: *** [auth-plug.so] Error 1

How to solve the problem "/usr/bin/ld: cannot find -lmosquitto"

Reference: http://i-pogo.blogspot.tw/2010/01/usrbinld-cannot-find-lxxx.html

pi@raspberrypi:/usr/lib $ apt-cache search libmosquitto-dev



pi@raspberrypi:/usr/lib $ sudo apt-get install libmosquitto-dev

pi@raspberrypi:/usr/lib $ sudo apt-get install libmosquitto-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libmosquitto1
The following NEW packages will be installed:
  libmosquitto-dev libmosquitto1
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 89.5 kB of archives.
After this operation, 275 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://repo.mosquitto.org/debian/ jessie/main libmosquitto1 armhf 1.4.14-0mosquitto1~jessie2 [47.7 kB]
Get:2 http://repo.mosquitto.org/debian/ jessie/main libmosquitto-dev armhf 1.4.14-0mosquitto1~jessie2 [41.8 kB]
Fetched 89.5 kB in 2s (34.3 kB/s)
Selecting previously unselected package libmosquitto1:armhf.
(Reading database ... 36410 files and directories currently installed.)
Preparing to unpack .../libmosquitto1_1.4.14-0mosquitto1~jessie2_armhf.deb ...
Unpacking libmosquitto1:armhf (1.4.14-0mosquitto1~jessie2) ...
Selecting previously unselected package libmosquitto-dev:armhf.
Preparing to unpack .../libmosquitto-dev_1.4.14-0mosquitto1~jessie2_armhf.deb ...
Unpacking libmosquitto-dev:armhf (1.4.14-0mosquitto1~jessie2) ...
Processing triggers for man-db (2.7.5-1~bpo8+1) ...
Setting up libmosquitto1:armhf (1.4.14-0mosquitto1~jessie2) ...
Setting up libmosquitto-dev:armhf (1.4.14-0mosquitto1~jessie2) ...
Processing triggers for libc-bin (2.19-18+deb8u10) ...

Issue the command below.

sudo apt-get install libc-ares-dev libcurl4-openssl-dev libmysqlclient-dev

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ gcc -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror -DBE_MYSQL `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include np.c base64.o -o np -L/usr/local/openssl/lib -lcrypto -ldl

Issue the "make" command again.

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ make

How to solve the problem of "Makefile:165: recipe for target 'np' failed"?

Reason for this problem:

This problem happens when "make" is issued before "gcc -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror -DBE_MYSQL `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include np.c base64.o -o np -L/usr/local/openssl/lib -lcrypto -ldl"

Solution:

Issue the command "gcc -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror -DBE_MYSQL `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include np.c base64.o -o np -L/usr/local/openssl/lib -lcrypto -ldl" again before issue the "make" command.

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ make
Selected backends:          MySQL
Using mosquitto source dir: /home/pi/mosquitto-1.4.14
OpenSSL install dir:        /usr/local/openssl

If you changed the backend selection, you might need to 'make clean' first

CFLAGS:   -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  -I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing    -g -DNDEBUG -I/src -DDEBUG=1 -I/usr/local/openssl/include
LDFLAGS:   -L/home/pi/mosquitto-1.4.14/lib/
LDADD:    -L/usr/lib/arm-linux-gnueabihf -lmysqlclient -lpthread -lz -lm -ldl -L/usr/local/openssl/lib -lcrypto -lmosquitto

cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o auth-plug.o auth-plug.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o base64.o base64.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o pbkdf2-check.o pbkdf2-check.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o log.o log.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o envs.o envs.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o hash.o hash.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o be-psk.o be-psk.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o backends.o backends.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o cache.o cache.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -c -o be-mysql.o be-mysql.c
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -L/home/pi/mosquitto-1.4.14/lib/ -fPIC -shared -o auth-plug.so auth-plug.o base64.o pbkdf2-check.o log.o envs.o hash.o be-psk.o backends.o cache.o be-mysql.o   `mysql_config --libs` -L/usr/local/openssl/lib -lcrypto -lmosquitto
cc  -I/home/pi/mosquitto-1.4.14/src/ -I/home/pi/mosquitto-1.4.14/lib/ -fPIC -Wall -Werror  -DBE_MYSQL  `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include   -L/home/pi/mosquitto-1.4.14/lib/ np.c base64.o -o np -L/usr/local/openssl/lib -lcrypto
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x10): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x20): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2c): undefined reference to `dlclose'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x318): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3bc): undefined reference to `dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x454): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4f8): undefined reference to `dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x554): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x5b0): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x5dc): undefined reference to `dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x664): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x6b4): undefined reference to `dlerror'
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x70c): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
Makefile:165: recipe for target 'np' failed
make: *** [np] Error 1

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ make clean

pi@raspberrypi:~/mosquitto-1.4.14/mosquitto-auth-plug $ make

After the make is successfully completed, an executable "np" is created (see below pic.). The executable "np" file is needed to create the password for mosquitto to access Maria DB.


Note,

According to the info. shown below, the mosquitto-auth-plug is tested to work with OpenSSL 1.0.0c.

Source:

Authentication plugin for Mosquitto with multiple back-ends (MySQL, Redis, CDB, SQLite3)
https://github.com/jpmens/mosquitto-auth-plug



No comments:

Post a Comment