The software is designed to have a loosely coupled architecture making it possible to add new home automation functionality without the need to worry about the MQTT communication to much. This results in a task for the main home automation logic and a seperate task to handle the MQTT communication to the broker. A global variable list is used to share memory objects between the two tasks enabling communication.
The main task is build using a SFC (Sequential Function Chart) with the following actions:
MAIN_INIT
: action ran once at startup to init FB's with static values/references.READ_PUSHBUTTONS
: action ran continously to read out digital inputs (FB's used in this action assume usage of pushbutton).WRITE_SWITCHES
: action ran continously afterREAD_PUSHBUTTONS
to switch outputs using the results fromREAD_PUSHBUTTONS
.
Each of the Function Blocks (FB's) used to read inputs and switch outputs has a reference to a MQTTPublishQueue
which is used to queue events to send to the MQTT broker.
The events are sent towards the broker in the MQTT Task which has a lower priority so it never interferes with the main task which does the critical work.
The main task is build using a SFC (Sequential Function Chart) with the following actions:
MQTT_INIT
: action ran once at startup to init FB's with static values/references.MQTT_PUBLISH
: action ran continously to read the events to publish from theMQTTPublishQueue
. Has a number ofMQTTPublishWorkers
who are able to send MQTT events simultanously.MQTT_SUBSCRIBE
: action ran continously afterMQTT_PUBLISH
to handle subscriptions.
Contains function blocks to enable communication between the main task and the MQTT task. For example:
MQTTPublishQueue
FB where the main task queue's messages to be published.- Callbackcollectors FB's so FB's can register for a callback event in case a message is received on a topic.