Hi, please help with MQTT; I installed new ZM from source - 'v1.37.64', but I still can't mqtt to work; in short - compile:
cmake -DZM_DB_PASS=...
make
make install
in Options -> MQTT I set the hostname, username, password and topic
in Monitor -> MQTT I enabled MQTT
Options -> Log -> Debug
restarted ZM more times, but no sign that ZM tries to connect MQTT - Mosquito writes no entries that client connected, netstat shows no connection was established, no MQTT related log in ZM log files
What I need to do to get MQTT publishing to work?
is 'Event Notification Server' nessesary?
The idea in behind is to turn on the lights on a sidewalk if someone comes/leaves house
br Bogo
MQTT in ZM
Re: MQTT in ZM
the problem is, that MOSQUITTOPP_FOUND is FALSE - but that's strange, because CMAKE reports that mosquittolib was found
-- Optional libraries found: zlib cURL OpenSSL PCRE Mosquitto Mosquittopp libVNC
-- Optional libraries not found: libVLC gsoap
if I try to hard-set #define MOSQUITTOPP_FOUND TRUE, I get compilation errors...
[ 24%] Building CXX object src/CMakeFiles/zm.dir/zm_mqtt.cpp.o
In file included from /usr/local/zm/zoneminder/src/zm_mqtt.cpp:8:
/usr/local/zm/zoneminder/src/zm_monitor.h:623:19: error: ‘MQTT’ was not declared in this scope
623 | std::unique_ptr<MQTT> mqtt;
| ^~~~
/usr/local/zm/zoneminder/src/zm_monitor.h:623:23: error: template argument 1 is invalid
623 | std::unique_ptr<MQTT> mqtt;
| ^
/usr/local/zm/zoneminder/src/zm_monitor.h:623:23: error: template argument 2 is invalid
/usr/local/zm/zoneminder/src/zm_mqtt.cpp:14:1: error: ‘MQTT’ does not name a type
14 | MQTT::MQTT(Monitor *monitor) :
| ^~~~
...
-- Optional libraries found: zlib cURL OpenSSL PCRE Mosquitto Mosquittopp libVNC
-- Optional libraries not found: libVLC gsoap
if I try to hard-set #define MOSQUITTOPP_FOUND TRUE, I get compilation errors...
[ 24%] Building CXX object src/CMakeFiles/zm.dir/zm_mqtt.cpp.o
In file included from /usr/local/zm/zoneminder/src/zm_mqtt.cpp:8:
/usr/local/zm/zoneminder/src/zm_monitor.h:623:19: error: ‘MQTT’ was not declared in this scope
623 | std::unique_ptr<MQTT> mqtt;
| ^~~~
/usr/local/zm/zoneminder/src/zm_monitor.h:623:23: error: template argument 1 is invalid
623 | std::unique_ptr<MQTT> mqtt;
| ^
/usr/local/zm/zoneminder/src/zm_monitor.h:623:23: error: template argument 2 is invalid
/usr/local/zm/zoneminder/src/zm_mqtt.cpp:14:1: error: ‘MQTT’ does not name a type
14 | MQTT::MQTT(Monitor *monitor) :
| ^~~~
...
Re: MQTT in ZM
so a digged a bit deeper and it seems mqtt basically works now...
what I did:
1) because of the compilation-error - changed include order in src/zm_mqtt.cpp from
#include "zm_mqtt.h"
#include "zm_monitor.h"
to
#include "zm_monitor.h"
#include "zm_mqtt.h"
2) hardcoded "#define MOSQUITTOPP_FOUND TRUE" to the beginning of these files:
src/zm_monitor.cpp
src/zm_monitor.h
src/zm_mqtt.cpp
src/zm_mqtt.h
3) every monitor starts it's own mqtt client-connection, the problem there is that the mqtt client_id is hardcoded in src/zm_mqtt.cpp as "ZoneMinder"; if mosquitto detects two connection with the same client_id, it closes the older one (with message in logs), so every monitor should connect with an uniqueue client_id
in src/zm_mqtt.cpp i changed
mosquittopp("ZoneMinder"),
to
mosquittopp(),
which generates automatically a client_id in form auto-<guid>, but it would be better to have something like this, fortunately I can not write it in cpp correctly:
mosquittopp("ZoneMinder" + monitor->Id()),
maybe someone more skillful than me could do a patch...?
br Bohuslav
what I did:
1) because of the compilation-error - changed include order in src/zm_mqtt.cpp from
#include "zm_mqtt.h"
#include "zm_monitor.h"
to
#include "zm_monitor.h"
#include "zm_mqtt.h"
2) hardcoded "#define MOSQUITTOPP_FOUND TRUE" to the beginning of these files:
src/zm_monitor.cpp
src/zm_monitor.h
src/zm_mqtt.cpp
src/zm_mqtt.h
3) every monitor starts it's own mqtt client-connection, the problem there is that the mqtt client_id is hardcoded in src/zm_mqtt.cpp as "ZoneMinder"; if mosquitto detects two connection with the same client_id, it closes the older one (with message in logs), so every monitor should connect with an uniqueue client_id
in src/zm_mqtt.cpp i changed
mosquittopp("ZoneMinder"),
to
mosquittopp(),
which generates automatically a client_id in form auto-<guid>, but it would be better to have something like this, fortunately I can not write it in cpp correctly:
mosquittopp("ZoneMinder" + monitor->Id()),
maybe someone more skillful than me could do a patch...?
br Bohuslav
Re: MQTT in ZM
SO I roughed this in a long time ago... and to my recollection.. it worked. I don't see how now though.
I have applied your fixes and some more so it should work now.
I have applied your fixes and some more so it should work now.
Re: MQTT in ZM
That is good news. I've tried to make it work in the past, it must be the reason it didn't at the time.
Now I have 2 questions :
1) Why did i see :
2) What it the use for the subscriptions field in the MQTT of each camera ?
Thanks a lot !
Now I have 2 questions :
1) Why did i see :
in the logs for each MQTT enabled camera ? it seems to come from line 719 in zm_monitor.cpp :MQTT enabled ? 1, subs
which logs an error in any case.Error("MQTT enabled ? %d, subs %s", mqtt_enabled, mqtt_subscriptions_string.c_str());
2) What it the use for the subscriptions field in the MQTT of each camera ?
Thanks a lot !
Re: MQTT in ZM
I don't have MQTT enabled as I don't need it but I get the following error in the log for all my monitors
MQTT enabled ? 0, subs
Re: MQTT in ZM
Please update. THat error log should have been a debug level.
Re: MQTT in ZM
The use of the subscription field is to subscribe to MQTT events. Maybe you want to record when somethng else sends an MQTT or you want to include some data in the event recording.
This is all just the beginnings of what can be done. I roughed it in hoping someone else would do something useful with it.
This is all just the beginnings of what can be done. I roughed it in hoping someone else would do something useful with it.