BadWolf42 / jMQTT

Jeedom plugin to interface as a client with an MQTT broker.
19 stars 13 forks source link

LWT should be configurable #64

Closed BadWolf42 closed 3 years ago

BadWolf42 commented 3 years ago

Last Will and Testament topic and values should be configurable. Some online Broker only allows RW to some topics, resulting in a crash of the jMQTT Client Broker instance.

Domochip commented 3 years ago

I think we need first to adapt python daemon to not crash for this kind of error. Then maybe get this error back to Jeedom. (cmd = errorReport)

And finally add a broker configuration to use LWT or not

AlexpFr commented 3 years ago

The daemon doesn't crash, the client just receives unexpected disconnection from broker!.

JMQTT log :

[2021-05-13 09:39:56][INFO] : Stopping Daemon
[2021-05-13 09:39:57][INFO] : Starting Daemon
[2021-05-13 09:39:58][INFO] : Lancement du démon python jMQTT pour le plugin jMQTT
[2021-05-13 09:39:58][INFO] : Lancement du démon websocket jMQTT pour le plugin jMQTT
[2021-05-13 09:39:58][INFO] : Start jMQTT websocket daemon
[2021-05-13 09:39:58][INFO] : Plugin     : jMQTT
[2021-05-13 09:39:58][INFO] : Socket port: 1026
[2021-05-13 09:39:58][INFO] : PID file   : /tmp/jeedom/jMQTT/jmqttd.php.pid
[2021-05-13 09:39:58][DEBUG] : Writing PID 18530 to /tmp/jeedom/jMQTT/jmqttd.php.pid
[2021-05-13 09:39:58][DEBUG] : Listening on: [127.0.0.1:1026]
[2021-05-13 09:42:23][DEBUG] : Id 446 : Python daemon connected successfully to WebSocket Daemon
[2021-05-13 09:42:23][DEBUG] : Id 446 : onMessage received : "{"cmd":"connection","state":false}"
[2021-05-13 09:42:24][DEBUG] : Id 446 : onMessage received : "{"cmd":"connection","state":true}"
[2021-05-13 09:42:24][DEBUG] : Id 446 : onMessage received : "{"cmd":"connection","state":false}"
[2021-05-13 09:42:29][DEBUG] : Id 446 : onMessage received : "{"cmd":"connection","state":false}"
[2021-05-13 09:42:39][DEBUG] : Id 446 : onMessage received : "{"cmd":"connection","state":false}"
[2021-05-13 09:42:55][DEBUG] : Id 446 : onMessage received : "{"cmd":"connection","state":false}"
[2021-05-13 09:43:10][DEBUG] : Id 446 : onMessage received : "{"cmd":"connection","state":false}"

JMQTT_daemon log :

[2021-05-13 09:39:59][INFO    ] : Start jMQTT python daemon
[2021-05-13 09:39:59][INFO    ] : Plugin     : jMQTT
[2021-05-13 09:39:59][INFO    ] : Log level  : debug
[2021-05-13 09:39:59][INFO    ] : Socket port: 1025
[2021-05-13 09:39:59][INFO    ] : PID file   : /tmp/jeedom/jMQTT/jmqttd.py.pid
[2021-05-13 09:39:59][DEBUG   ] : Apikey    : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[2021-05-13 09:39:59][DEBUG   ] : Writing PID 18528 to /tmp/jeedom/jMQTT/jmqttd.py.pid
[2021-05-13 09:39:59][DEBUG   ] : Socket interface started
[2021-05-13 09:39:59][DEBUG   ] : LoopNetServer Thread started
[2021-05-13 09:39:59][DEBUG   ] : Listening on: [127.0.0.1:1025]
[2021-05-13 09:42:23][DEBUG   ] : Client connected to [127.0.0.1:46780]
[2021-05-13 09:42:23][DEBUG   ] : Message read from socket: b'{"port":8883,"clientid":"android-123456","statustopic":"android-123456\/status","username":"","password":"","paholog":"","tls":true,"tlscafile":"\/var\/www\/html\/plugins\/jMQTT\/data\/certs\/AmazonRootCA1.crt","tlssecure":"0","tlsclicertfile":"\/var\/www\/html\/plugins\/jMQTT\/data\/certs\/certificate.pem","tlsclikeyfile":"\/var\/www\/html\/plugins\/jMQTT\/data\/certs\/key.key","cmd":"newMqttClient","id":"446","hostname":"a1optpg91s0ydf-ats.iot.eu-west-1.amazonaws.com","callback":"ws:\/\/127.0.0.1:1026\/plugins\/jMQTT\/resources\/jmqttd\/jmqttd.php","apikey":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}'
[2021-05-13 09:42:23][DEBUG   ] : Client disconnected from [127.0.0.1:46780]
[2021-05-13 09:42:23][DEBUG   ] : jeedom_socket received message : {"port":8883,"clientid":"android-123456","statustopic":"android-123456\/status","username":"","password":"","paholog":"","tls":true,"tlscafile":"\/var\/www\/html\/plugins\/jMQTT\/data\/certs\/AmazonRootCA1.crt","tlssecure":"0","tlsclicertfile":"\/var\/www\/html\/plugins\/jMQTT\/data\/certs\/certificate.pem","tlsclikeyfile":"\/var\/www\/html\/plugins\/jMQTT\/data\/certs\/key.key","cmd":"newMqttClient","id":"446","hostname":"a1optpg91s0ydf-ats.iot.eu-west-1.amazonaws.com","callback":"ws:\/\/127.0.0.1:1026\/plugins\/jMQTT\/resources\/jmqttd\/jmqttd.php","apikey":"xxxxxxxxxxxxxxxxxxxxxxxxxxx"}
[2021-05-13 09:42:23][INFO    ] : Id 446 : Starting Client creation
[2021-05-13 09:42:23][INFO    ] : Id 446 : Connected to Jeedom using ws://127.0.0.1:1026/plugins/jMQTT/resources/jmqttd/jmqttd.php
[2021-05-13 09:42:24][INFO    ] : Id 446 : Connected to broker a1optpg91s0ydf-ats.iot.eu-west-1.amazonaws.com:8883
[2021-05-13 09:42:24][INFO    ] : Id 446 : Sending message to Jeedom : {"cmd":"connection","state":true}
[2021-05-13 09:42:24][ERROR   ] : Id 446 : Unexpected disconnection from broker!
[2021-05-13 09:42:24][INFO    ] : Id 446 : Sending message to Jeedom : {"cmd":"connection","state":false}
[2021-05-13 09:42:29][ERROR   ] : Id 446 : Unexpected disconnection from broker!
[2021-05-13 09:42:29][INFO    ] : Id 446 : Sending message to Jeedom : {"cmd":"connection","state":false}
[2021-05-13 09:42:39][ERROR   ] : Id 446 : Unexpected disconnection from broker!
[2021-05-13 09:42:39][INFO    ] : Id 446 : Sending message to Jeedom : {"cmd":"connection","state":false}
[2021-05-13 09:42:55][ERROR   ] : Id 446 : Unexpected disconnection from broker!
[2021-05-13 09:42:55][INFO    ] : Id 446 : Sending message to Jeedom : {"cmd":"connection","state":false}
[2021-05-13 09:43:10][ERROR   ] : Id 446 : Unexpected disconnection from broker!
[2021-05-13 09:43:10][INFO    ] : Id 446 : Sending message to Jeedom : {"cmd":"connection","state":false}
Domochip commented 3 years ago

OK, good, option to disable status publish is available by commit : https://github.com/Domochip/jMQTT/commit/86f583311577aa50eec9d53c8dd5c90123817998

AlexpFr commented 3 years ago

I just tested on the AWS cloud, it works well, I was able to subscribe to the topic of my equipment. (in MQTTs of course).

Thank you so much !

Domochip commented 3 years ago

you're welcome ;-)