The MQTT protocol design for IOT devices, and it is very easy to implement, so connect this project to MQTT system is should be a must ;).
The MQTT module is an MQTT client that subscribe to devices statuses updates and publish set/get status requests.
MQTT system is several clients that connect to one broker.
To connect the module to an exists broker set the MQTT_BROKER_URI env var (for example mqtt://192.168.1.10:1883).
To run internal broker leave empty the MQTT_BROKER_URI env var.
The default internal broker port is 1883 to change it sets MQTT_INTERNAL_BROKER_PORT env var.
Since every device manufacture use slight different topic/payloads for controlling the device, the MQTT module holds a collection of drivers for each.
The MQTT driver needs to detect the topic, past a message into Casanet status structure, and convert set status into device's MQTT topic/payload.
This driver is a generic driver, that publish and subscribes to casanet/* topic.
The driver subscribes to the topic casanet/state/+, to get the minion new status.
while in the + place should be the minion id.
For example a valid topic casanet/state/yg56rf.
The body of the message should be a minion status (see swagger API for the structure). For example (Filling only the current minion device type):
{
"switch": {
"status": "on"
}
}The driver publishes to the topic casanet/set/[minionId], to set the minion a new status.
For example casanet/set/yg56rf.
The body of the message is a minion status to set (see swagger API for the structure). For example (It filling only the current minion device type):
{
"switch": {
"status": "on"
}
}And also MQTT module publishes to the topic casanet/get/[minionId] to get the current status (with an empty body).
Currently there is a driver for a tasmota simple switch devices only.
To use it:
- Create a new minion in the dashboard, select brand
mqttand in the modelswitch. - Set any device Id string, and copy it for later.
- In Tasmota web interface set the broker IP. (note that if not set any other broker to Casanet, the broker is the Casanet server IP).
- In Tasmota web interface change the topic name to
sonoff/[deviceID].
Currently there is a driver for Shelly button, switch, and bulb color only.
To use it:
- Open Shelly web interface, and enable MQTT (
Internet & Security -> Enable action exclusion via MQTT). - Set MQTT Server set the broker IP. (note that if not set any other broker to Casanet, the broker is the Casanet server IP).
- Enable custom MQTT prefix, and copy the value.
- Create a new minion in the dashboard, select brand
mqttand in the model selecttoggle/switch/color light. - Paste the device's custom MQTT prefix as the device ID.
It should be very simple.
- Create a new driver file, go to
backend/src/modules/mqtt/mqtt-driversdirectory and copy thecasanetMqttDriver.tsand change the file name (toxxxMqttDriver.ts) and the class namexxxMqttDriver. - Change the topic to subscribe and the messages to send as required.
- in the
../mqtt/mqttHandler.ts(line ~153) add an instance of thexxxMqttDriverclass to the drivers collection. - feel free for asking help or opening PR :)


