Skip to content

WIP Asyncio Program Flow

Ellis Percival edited this page Jan 24, 2021 · 7 revisions

Set output

_handle_mqtt_message():

  • MQTT message received to <topic_prefix>/output/<output_name>/set
  • Output name parsed from topic
  • GPIO module object, output config and payload added to the module's output queue

digital_output_loop():

  • Queue entry picked up
  • Payload checked to ensure it matches configured on or off payloads
  • set_digital_output() called to set the output

set_digital_output():

  • Output set to desired logic level
  • DigitalOutputChangedEvent event fired with details of the change

EventBus.fire():

  • Task added to task loop for publish_callback()

publish_callback():

  • MQTT message published to <topic_prefix>/output/<output_name> to confirm output change

Set output for x ms

_handle_mqtt_message():

  • MQTT message received to <topic_prefix>/output/<output_name>/set_on_ms (or /set_off_ms)
  • Output name parsed from topic
  • Async closure function created to handle the toggling of the output with the delay in the middle (set_ms())
  • set_ms() task added to the task loop

set_ms():

  • Interval time parsed from payload (milliseconds)
  • set_digital_output() called to set the output

set_digital_output():

  • Digital output set to the desired value (on or off)
  • DigitalOutputChangedEvent event fired with details of the change

EventBus.fire():

  • Task added to task loop for publish_callback()

publish_callback():

  • MQTT message published to <topic_prefix>/output/<output_name> to confirm output change

set_ms():

  • Task paused for specified interval

  • set_digital_output() called to set the output

set_digital_output():

  • Digital output set to the desired value (off or on)
  • DigitalOutputChangedEvent event fired with details of the change

EventBus.fire():

  • Task added to task loop for publish_callback()

publish_callback():

  • MQTT message published to <topic_prefix>/output/<output_name> to confirm output change

Digital input value changed and published (polling)

digital_input_poller():

  • Input change recognised
  • DigitalInputChangedEvent event fired with details of the change

EventBus.fire():

  • Task added to task loop for publish_callback()

publish_callback():

  • MQTT message published to <topic_prefix>/input/<input_name> with payload set according to the input's new value

Initialise sensor input

_init_sensor_inputs():

  • Async closure function created to publish results of sensor reads (publish_sensor_callback())
  • SensorReadEvent event subscribed to with publish_sensor_callback()
  • Sensor input config validated and normalised
  • Sensor module's setup_sensor() method called
  • Async closure function created to loop forever and poll the sensor at the configured interval (poll_sensor())
  • Task added to task loop for poll_sensor()

Sensor value read and published

poll_sensor():

  • Sensor module used to get value of sensor
  • Sensor value rounded to desired number of digits
  • SensorReadEvent event fired with details of read value

EventBus.fire():

  • Task added to task loop for publish_sensor_callback()

publish_sensor_callback():

  • MQTT message published to <topic_prefix>/sensor/<sensor_name> with read sensor value