-
Notifications
You must be signed in to change notification settings - Fork 0
MQTT Type
jbaumann edited this page Jan 6, 2022
·
3 revisions
The MQTT type is used by setting the type
accordingly:
[my mqtt check]
type = mqtt
mqtt = <type of mqtt check>
server = the mqtt server
topic = list, of, topics
repair = repair command
The mqtt type offers the following options:
Option | Explanation |
---|---|
mqtt | the type of check that is used. Currently only timeout is implemented (mandatory) |
topic | the topics that the configuration listens to, separated by a comma ',' (mandatory) |
server | the name or IP address of the MQTT server (mandatory) |
port | the port on the server on which the MQTT service runs (optional, default is 1883) |
user | if a user is needed for the connection to the MQTT service you can set it here. Prerequisite for using a password. A user in the credentials overwrites this setting (optional) |
password | if a password is needed for the connection to the MQTT service you can set it here. Important: If a password is needed then a user has to be set as well. A password in the credentials overwrites this setting (optional) |
credentials | A file name referencing a file that contains a user and optionally a password in two different lines (a semicolon ';' marks a comment until the end of the line). Entries in the credentials file overwrite the options 'user' and 'password' (optional) |
repair | This command is executed when the check was unsuccessful for longer than the set timeout |
timeout | The timeout defines the maximum allowed time between successful checks. If this is exceeded, then a repair action or a fallback action is executed |
Typically with MQTT you will use both a sleep time and a timeout far longer than for other configurations, since most IOT devices send messages only at longer intervals.
Using a credentials file is a good idea that allows you to keep your sensitive authentication data from the config file. Please remember to change the access rights of the file(s) so that only the user pi can read them. This can be done using the following command (assuming the file is named 'credentials.txt'):
> chmod go-rwx credentials.txt
mqtt]
type = mqtt
mqtt = timeout
server = my_mqtt_server
; port = 1883
topic = first_floor/living_room/sensor/tele/STATE, first_floor/living_room/sensor/tele/LWT
repair = sudo systemctl restart networking
fallback = ls -l
;credentials = credentials.txt
;user = user
;password = passwd
sleep time = 60
timeout = 120
; The following two lines contain the user and password
; information.
the_user_name
the_secret_password
The following options overwrite default values from the [general] section, if need be:
Option | Explanation |
---|---|
fallback | This is the fallback action that is executed if repairing was unsuccessful |
sleep time | The daemon sleeps between checks of the current configuration for this time in seconds. |