diff --git a/README.md b/README.md index 6962a5a..70e6f8c 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ The MQTT broker mosquitto is integrated into the package. It requires its own do During installation, a [MQTT](https://en.wikipedia.org/wiki/MQTT) broker, [Mosquitto](https://mosquitto.org/), is installed at the same time as Domoticz. The installed version is the one from the official project repo and not from Debian ones. This broker requires a dedicated domain or subdomain to work (ex : mqtt.your.domain.tld) : creating this domain prior installation is a prerequisite -#### Use +#### Adding in domoticz To use mosquitto, you need to customize the communication between domoticz and the broker by following the [domoticz documentation](https://www.domoticz.com/wiki/MQTT#Installing_Mosquitto), part *Add hardware "MQTT Client Gateway"*. User and password are automatically generated during installation, you may retrieve them with @@ -54,15 +54,32 @@ User and password are automatically generated during installation, you may retri sudo yunohost app setting domoticz mqtt_user sudo yunohost app setting domoticz mqtt_pwd ```` -You can then publish on a device on domoticz with following syntax: + +#### Publish/Subscribe + +By default, mosquitto will listen on 2 ports: +- 1883 on localhost using mqtt protocol +- 8883 using websocket protocol. Nginx redirect external port 443 to this internal port. + +Hence, To publish/subscribe on a topic from the outside, you have to use a software supporting websocket protocol (ex : paho python library). + +#### Mosquitto_pub et mosquitto_sub + +These 2 tools do not support websocket protocol, only direct mqtt: base settings will not allow communication from an outside device. +If you're using them directly from your server, this kind of syntax should work: ```` -mosquitto_pub -u *user* -P *password* -h mqtt.your.domain.tld -p 443 -t 'domoticz/in' -m '{ "idx" : 1, "nvalue" : 0, "svalue" : "25.0" }' +mosquitto_pub -u *user* -P *password* -h mqtt.your.domain.tld -p 1883 -t 'domoticz/in' -m '{ "idx" : 1, "nvalue" : 0, "svalue" : "25.0" }' ```` -In the same way, you may subscribe to a topic with +In the same way: ```` -mosquitto_sub -u *user* -P *password* -h mqtt.your.domain.tld -p 443 -t 'domoticz/out' +mosquitto_sub -u *user* -P *password* -h mqtt.your.domain.tld -p 1883 -t 'domoticz/out' ```` +If you wish to open direct mqtt protocol from an outside device, you'll need to: +- open port 1883 on Yunohost firewall (**Attention, security risk**) +- Allows IP addresses in mosquitto configuration for this listener +- Set the tls setting in mosquitto configuration by giving access to crt.pem and key.pem from your mqtt domain by setting respective certfile et keyfile variables. **This is mandatory to ensure a secure connection.** + #### Upgrade from version without mosquitto If you have package ynh3 or below, mosquitto is not installed by default. If you have chosen to not set a domain during initial installation also. diff --git a/README_fr.md b/README_fr.md index c1df5c2..71b550b 100644 --- a/README_fr.md +++ b/README_fr.md @@ -45,23 +45,40 @@ Le broker MQTT mosquitto est intégré au package et nécessite un sous-domaine A l'installation, un broker [MQTT](https://fr.wikipedia.org/wiki/MQTT), [Mosquitto](https://mosquitto.org/), est installé en même temps que Domoticz. La version installée est celle du dépot officiel du projet, et non des dépots Debian. Ce broker nécessite un domaine ou un sous-domaine particulier pour fonctionner (ex : mqtt.your.domain.tld) : il est nécessaire de créer ce domaine auparavant. -####Utilisation +#### Ajout dans domoticz Pour pouvoir l'utiliser, vous devez paramétrer la communication avec entre domoticz et le broker en suivant la [documentation de domoticz](https://www.domoticz.com/wiki/MQTT#Installing_Mosquitto) dans la partie *Add hardware "MQTT Client Gateway"* -Les users et mot de passe du broker sont automatiquement générés lors de l'installation. Vous pouvez les récupérer en tapant +Les users et mot de passe du broker sont automatiquement générés lors de l'installation. Vous pouvez les récupérer avec ```` sudo yunohost app setting domoticz mqtt_user sudo yunohost app setting domoticz mqtt_pwd ```` -Vous pouvez ensuite publier sur ce serveur en utilisant la syntaxe: +#### Publier/souscrire + +Par défaut, mosquitto va écouter sur 2 ports: +- Le 1883 sur localhost en protocole mqtt +- Le 8883 en protocole websocket. Nginx redirige le port 443 externe vers ce port en interne.e +Pour publier/souscrire sur un topic depuis l'exterieur, vous devez donc utiliser un programme supportant le protocole websocket (ex : la bibliothèque python paho).: + +#### Mosquitto_pub et mosquitto_sub + +Ces deux programmes ne supportent pas le protocole websocket mais uniquement le mqtt : le paramétrage de base ne vous autorise donc pas à les utiliser pour communiquer depuis un client externe. +Si vous les utilisez directement depuis votre serveur, ce genre de syntaxe devrait marcher: ```` -mosquitto_pub -u *user* -P *password* -h mqtt.your.domain.tld -p 443 -t 'domoticz/in' -m '{ "idx" : 1, "nvalue" : 0, "svalue" : "25.0" }' +mosquitto_pub -u *user* -P *password* -h mqtt.your.domain.tld -p 1883 -t 'domoticz/in' -m '{ "idx" : 1, "nvalue" : 0, "svalue" : "25.0" }' ```` -De la même manière, vous pouvez suivre ce qu'il se passe avec +De la même manière:c ```` -mosquitto_sub -u *user* -P *password* -h mqtt.your.domain.tld -p 443 -t 'domoticz/out' +mosquitto_sub -u *user* -P *password* -h mqtt.your.domain.tld -p 1883 -t 'domoticz/out' ```` +Si vous souhaitez ouvrir le protocole mqtt depuis l'extérieur afin de pouvoir les utiliser depuis un autre serveur, il vous faudra: +- ouvrir le port 1883 sur le firewall Yunohost (**Attention, risque de sécurité**) +- autoriser les adresses IP souhaitées dans la configuration de mosquitto pour ce listener +- paramétrer le tls dans la configuration de mosquitto en donnant accès au crt.pem et key.pem de votre domaine mqtt en les paramétrant respectivement avec les variables certfile et keyfile. **Ceci est obligatoire pour sécuriser la connexion.** + + + ####Mise à jour depuis les versions n'ayant pas mosquitto Si vous êtes sur le package ynh3 ou inférieur, mosquitto n'est pas installé par défaut.