Closed Sieboldianus closed 2 years ago
this lists the error codes returned by mosquitto_publish()
:
https://mosquitto.org/api/files/mosquitto-h.html#mosquitto_publish
and this lists the numeric values:
https://github.com/eclipse/mosquitto/blob/master/include/mosquitto.h#L87
4 == MOSQ_ERR_NO_CONN
vzlogger should probably decode those codes for the user, using https://mosquitto.org/api/files/mosquitto-h.html#mosquitto_strerror
Great, thanks! So the MOSQ_ERR Codes and the List of names are ordered in the docs. This helps!
However, with my last settings, it obvisoully works from the vzlogger site:
No error messages, but I also do not see the data coming in at the MQTT Broker.
No output here:
mosquitto_sub -h mqtt.local.mytld.com -t "vzlogger/#" -p 8883 -u "telegraf" -P "..."
Below are my configs for the above vzlogger logs. Perhaps someone can see any obvious mistake.
/etc/vzlogger.conf
/etc/mosquitto/conf.d/default.conf
/etc/telegraf/telegraf.conf
telegraf -config /etc/telegraf/telegraf.conf
And the logs with no certs, no socket, directly connecting to port 1883 on the MQTT broker host (listener set to listener 1883 0.0.0.0
):
tail -f /var/log/vzlogger.log | grep mqtt
I think I isolated the error.
Using:
allow_anonymous true
in /etc/mosquitto/conf.d/default.conf
, the vzlogger MQTT messages arrive:
tail -f /var/log/mosquitto/mosquitto.log
1616568634: Received PUBLISH from vzlogger_4467 (d0, q0, r0, m0, 'vzlogger/data/chn2/raw', ... (14 bytes))
1616568635: Received PUBLISH from vzlogger_4467 (d0, q0, r0, m0, 'vzlogger/data/chn0/raw', ... (12 bytes))
1616568635: Received PUBLISH from vzlogger_4467 (d0, q0, r0, m0, 'vzlogger/data/chn1/raw', ... (14 bytes))
1616568635: Received PUBLISH from vzlogger_4467 (d0, q0, r0, m0, 'vzlogger/data/chn2/raw', ... (14 bytes))
1616568636: Received PUBLISH from vzlogger_4467 (d0, q0, r0, m0, 'vzlogger/data/chn0/raw', ... (12 bytes))
tail -f /var/log/vzlogger.log | grep mqtt
[Mar 24 07:50:39][mqtt] publish vzlogger/data/chn1/raw=1003517.800000
[Mar 24 07:50:39][mqtt] publish vzlogger/data/chn2/raw=1865034.000000
[Mar 24 07:50:40][mqtt] publish vzlogger/data/chn0/raw=-1941.000000
[Mar 24 07:50:40][mqtt] publish vzlogger/data/chn1/raw=1003517.800000
[Mar 24 07:50:40][mqtt] publish vzlogger/data/chn2/raw=1865034.600000
[Mar 24 07:50:41][mqtt] publish vzlogger/data/chn0/raw=-1942.000000
[Mar 24 07:50:41][mqtt] publish vzlogger/data/chn1/raw=1003517.800000
[Mar 24 07:50:41][mqtt] publish vzlogger/data/chn2/raw=1865035.200000
Apparently, it has something to do with the user auth. I checked passwords several times and they are ok. I tested connecting locally with those credentials to the MQTT host, and it worked. Clueless as to now, but it does work for now..
Did anyone get vzlogger with MQTT user-pw auth to work? Perhaps there is an issue with this feature.
With the anonymous login it now works. I also had to set the following telegraf configs:
[[inputs.mqtt_consumer]]
servers = ["tcp://localhost:1883"]
topics = [
"vzlogger/#",
]
qos = 0
connection_timeout = "30s"
client_id = "influx_telegraf"
data_format = "value"
data_type = "float"
Note the data_type = "float"
, which was initially missing and the final issue that prevented values to flow to influxdb2.
to debug your authentication issues... we should enable detailed logging of the http requests (via curl debug option) in vzlogger.
alternatively, point vzlogger at a tcp listener (nc -vlp 1884
or such)
to intercept the data vzlogger is sending,
and compare it with a working request from another utility.
I will try and report.. many thanks!
Well, it was a user error.
In most guides for setting up MQTT broker, the following command is used to add user/pw:
sudo mosquitto_passwd -c /etc/mosquitto/passwd smartmeter
Of course, I did this twice:
smartmeter
usertelegraf
userWhat they don't tell you is that -c
flag silently overwrites the passwd file, deleting the first user.
I found out through following the nc
rabbit hole - thanks!
Everything looked fine, wich is why I finally checked the /etc/mosquitto/passwd
, to find it contained only one user.
Start netcat:
nc -vlp 1884
.. and change vzlogger.conf to use 1884
on the RPi, I get from nc:
connect to [192.168.60.10] from (UNKNOWN) [192.168.60.16] 52912
<MQTT▒vzlogger_14807
smartmeterlk8wwefewf7uZF7NoZLk0%vzlogger/data/chn0/id1-0:16.7.0*2550=vzlogger/data/chn0/uuiddcdbec30-87f6-11eb-bf60-e5d3715178680$vzlogger/data/chn0/raw-6330.0000000$vzlogger/data/chn1/id1-0:1.8.0*2550=vzlogger/data/chn1/uuidbd6c93b0-87f4-11eb-9599-a1e7fb6c47040&vzlogger/data/chn1/raw1011852.8000000$vzlogger/data/chn2/id1-0:2.8.0*2550=vzlogger/data/chn2/uuid2ebb8470-87f7-11eb-8877-3198b438162f0&vzlogger/data/chn2/raw1999996.6000000$v
smartmeter
here is the MQTT userlk8wwefewf7uZF7NoZLk
is MQTT user's password0%
isAnd in vzlogger logs:
[Mar 25 13:46:04][mqtt] mosquitto_loop returned 4. trying reconnect
[Mar 25 13:46:05][mqtt] mosquitto_reconnect returned 14
[Mar 25 13:46:05][mqtt] mosquitto_loop returned 4. trying reconnect
[Mar 25 13:46:06][mqtt] mosquitto_reconnect returned 14
[Mar 25 13:46:06][mqtt] mosquitto_loop returned 4. trying reconnect
[Mar 25 13:46:07][mqtt] mosquitto_reconnect returned 14
[Mar 25 13:46:07][mqtt] mosquitto_loop returned 4. trying reconnect
Test the same nc connection with mosquitto_pub:
mosquitto_pub -h 192.168.60.10 -t test -m "hello world" -p 1884 -u "smartmeter" -P "lk8wwefewf7uZF7NoZLk"
connect to [192.168.60.10] from 192.168.60.10 [192.168.60.10] 52172
?MQTT▒<mosqpub|17462-iot
smartmeterlk8wwefewf7uZF7NoZLk
Many thanks! And many apologies for this unecessary issue report.
I still leave it open if you want to reference it when error codes are decoded. Feel free to close it though.
What they don't tell you is that -c flag silently overwrites the passwd file, deleting the first user.
so the root cause is that mosquitto_passwd
copies the syntax of htpasswd
,
which has the bad design decision that -c
means "create password file", not "create user"...
(and adding a user to a nonexistent file does not implicitly create the file but fails, and asking to create over an existing file will overwrite it without warning.)
not sure what 0% is
most likely the data is binary (i never used mqtt), you should add | xxd
to have it dumped in hex.
i will try to create an MR for adding 'mosquitto_strerror()', and you can then help by testing it.
Is there any guidance towards error codes of vzlogger mqtt implementation? I only found named errors on the docs, but vzlogger gives me numbers:
I tried several config versions for
/etc/mosquitto/conf.d/default.conf
:1. No certs, no sockets
``` allow_anonymous false password_file /etc/mosquitto/passwd listener 1883 protocol websockets ```2. With socket support
``` allow_anonymous false password_file /etc/mosquitto/passwd listener 1883 ```3. With certs (no socket)
``` listener 8883 certfile /etc/nginx/ssl/wildcard.local.mytld.com.fullchain keyfile /etc/nginx/ssl/wildcard.local.mytld.com.key ```4. With certs and socket support
``` listener 8083 protocol websockets cafile /etc/nginx/ssl/wildcard.local.mytld.com.ca certfile /etc/nginx/ssl/wildcard.local.mytld.com.crt keyfile /etc/nginx/ssl/wildcard.local.mytld.com.key ```All of this with adjusted settings in MQTT of
/etc/vzlogger.conf
.To no avail. The messages from vzlogger do not reach the MQTT Broker.
Depending on my settings above (with/without socket), I get slightly different error numbers:
This is with socket:
``` [Mar 23 22:28:45][mqtt] mosquitto_publish announce vzlogger/data/chn0/id returned 4 [Mar 23 22:28:45][mqtt] mosquitto_publish announce vzlogger/data/chn0/uuid returned 4 [Mar 23 22:28:45][mqtt] mosquitto_publish announce vzlogger/data/chn1/id returned 4 [Mar 23 22:28:45][mqtt] mosquitto_publish announce vzlogger/data/chn1/uuid returned 4 [Mar 23 22:28:45][mqtt] mosquitto_publish announce vzlogger/data/chn2/id returned 4 [Mar 23 22:28:45][mqtt] mosquitto_publish announce vzlogger/data/chn2/uuid returned 4 [Mar 23 22:28:45][mqtt] mosquitto_reconnect succeeded [Mar 23 22:28:45][mqtt] disconnect_callback called, res=6 [Mar 23 22:28:45][mqtt] mosquitto_loop returned 6. trying reconnect [Mar 23 22:28:46][mqtt] mosquitto_publish announce vzlogger/data/chn0/id returned 4 [Mar 23 22:28:46][mqtt] mosquitto_publish announce vzlogger/data/chn0/uuid returned 4 [Mar 23 22:28:46][mqtt] publish vzlogger/data/chn0/raw=438.000000 [Mar 23 22:28:46][mqtt] mosquitto_publish returned 4 [Mar 23 22:28:46][mqtt] mosquitto_publish announce vzlogger/data/chn1/id returned 4 [Mar 23 22:28:46][mqtt] mosquitto_publish announce vzlogger/data/chn1/uuid returned 4 [Mar 23 22:28:46][mqtt] publish vzlogger/data/chn1/raw=998545.800000 [Mar 23 22:28:46][mqtt] mosquitto_publish returned 4 [Mar 23 22:28:46][mqtt] mosquitto_publish announce vzlogger/data/chn2/id returned 4 [Mar 23 22:28:46][mqtt] mosquitto_publish announce vzlogger/data/chn2/uuid returned 4 [Mar 23 22:28:46][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 ```This is with certs:
``` [Mar 23 22:18:28][mqtt] mosquitto_publish returned 4 [Mar 23 22:18:28][mqtt] mosquitto_reconnect succeeded [Mar 23 22:18:28][mqtt] disconnect_callback called, res=6 [Mar 23 22:18:28][mqtt] mosquitto_loop returned 6. trying reconnect [Mar 23 22:18:29][mqtt] publish vzlogger/data/chn0/raw=569.000000 [Mar 23 22:18:29][mqtt] mosquitto_publish returned 4 [Mar 23 22:18:29][mqtt] publish vzlogger/data/chn1/raw=998453.200000 [Mar 23 22:18:29][mqtt] mosquitto_publish returned 4 [Mar 23 22:18:29][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 [Mar 23 22:18:29][mqtt] mosquitto_publish returned 4 [Mar 23 22:18:29][mqtt] mosquitto_reconnect succeeded [Mar 23 22:18:29][mqtt] disconnect_callback called, res=6 ```This was with certs and web socket support
``` [Mar 23 22:04:23][mqtt] publish vzlogger/data/chn1/raw=998327.200000 [Mar 23 22:04:23][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 [Mar 23 22:04:24][mqtt] publish vzlogger/data/chn0/raw=558.000000 [Mar 23 22:04:24][mqtt] publish vzlogger/data/chn1/raw=998327.400000 [Mar 23 22:04:24][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 [Mar 23 22:04:25][mqtt] publish vzlogger/data/chn0/raw=558.000000 [Mar 23 22:04:25][mqtt] publish vzlogger/data/chn1/raw=998327.400000 [Mar 23 22:04:25][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 [Mar 23 22:04:26][mqtt] publish vzlogger/data/chn0/raw=557.000000 [Mar 23 22:04:26][mqtt] publish vzlogger/data/chn1/raw=998327.600000 [Mar 23 22:04:26][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 [Mar 23 22:04:27][mqtt] publish vzlogger/data/chn0/raw=557.000000 [Mar 23 22:04:27][mqtt] publish vzlogger/data/chn1/raw=998327.800000 [Mar 23 22:04:27][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 [Mar 23 22:04:28][mqtt] publish vzlogger/data/chn0/raw=557.000000 [Mar 23 22:04:28][mqtt] publish vzlogger/data/chn1/raw=998328.000000 [Mar 23 22:04:28][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 [Mar 23 22:04:29][mqtt] publish vzlogger/data/chn0/raw=558.000000 [Mar 23 22:04:29][mqtt] publish vzlogger/data/chn1/raw=998328.000000 [Mar 23 22:04:29][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 [Mar 23 22:04:30][mqtt] publish vzlogger/data/chn0/raw=558.000000 [Mar 23 22:04:30][mqtt] publish vzlogger/data/chn1/raw=998328.200000 [Mar 23 22:04:30][mqtt] publish vzlogger/data/chn2/raw=1864560.800000 ``` No error messages, but I also did not see the data coming in at the MQTT Broker. No output here: ``` mosquitto_sub -h mqtt.local.mytld.com -t "vzlogger/#" -p 8883 -u "telegraf" -P "..." ```