MQTT

MQTT Broker:

mosquitto

Install:

apt install mosquitto mosquitto-clients

or

snap install mosquitto mosquitto-clients

Commands:

 mosquitto_pub -h 10.0.0.10 -t SENSOR3/+ -m '123' -d
 mosquitto -v -c /etc/mosquitto/mosquitto.conf

Trigger relay:

mosquitto_pub -t <devicename>/GPIO/2 -m 0                      #on
mosquitto_pub -t <devicename>/GPIO/2 -m 1                      #off

Gosund (switch power1):

mosquitto_pub -t <devicename>/cmnd/Power1 -m OFF
mosquitto_pub -t <devicename>/cmnd/Power1 -m ON

To send a message to a mqtt server:

https://diy.waziup.io/sensors/publish_using_MQTT/publish_using_MQTT.html

https://github.com/plapointe6/EspMQTTClient #authentication example!

Interfaces

Mosquitto listens on default on localhost (127.0.0.1). If you want to make mosquitto listen on all interfaces, you have to edit

/etc/mosquitto/mosquitto.conf

and add

#individual
listener 1883 0.0.0.0
allow_anonymous true

Afterwards you have to restart mosquitto to make it active:

systemctl restart mosquitto.service

Check:

netstat -an | grep 1883
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN
iot/mqtt.txt · Last modified: 2024/03/02 13:19 by tmade
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki