------------------
Outbound API
============
An outbound API (notifications) is provided in a separate process. The
present implementation uses MQTT and provides timestamped,
source-identified, semantically versioned JSON payloads for:
- DE1
- Connectivity
- State updates
- Shot samples with accumulated volume
- Water levels
- Scale
- Connectivity
- Weight and flow updates
- Flow sequencer
- "Gate" clear and set
- Sequence start
- Flow begin
- Expect drops
- Exit preinfuse
- Flow end
- Flow-state exit
- Last drops
- Sequence complete
- Stop-at-time/volume/weight
- Enable, disable (with target)
- Trigger (with target and value at trigger)
An example subscriber is provided in ``examples/monitor_delay.py``. On a
Raspberry Pi 3B, running Debian *Buster* and ``mosquitto`` 2.0 running
on ``::``, median delays are under 10 ms from *arrival\_time* of the
triggering event to delivery of the MQTT packet to the subscriber.
Packets are being sent with *retain* True, so that, for example, the
subscriber has the last-known DE1 state without having to wait for a
state change. Checking the payload's ``arrival_time`` is suggested to
determine if the data is fresh enough. The *will* feature of MQTT has
not yet been implemented.
A good introduction to MQTT and MQTT 5 can be found at HiveMQ:
- https://www.hivemq.com/mqtt-essentials/
- https://www.hivemq.com/blog/mqtt5-essentials-part1-introduction-to-mqtt-5/
One good thing about MQTT is that you can have as many subscribers as
you want without slowing down the controller. For example, you can have
a live view on your phone, live view on your desktop, log to file, log
to database, all at once.
Scan For And Use First DE1 And Skale Found
==========================================
Though "WET" and needing to be "DRY", the first-found DE1 and Skale will
be used. The Scale class has already been designed to be able to have
each subclass indicate if it recognizes the advertisement. Once DRY, the
scanner should be able to return the proper scale from any of the
alternatives.
Refactoring of this is pending the formal release of
``BleakScanner.find_device_by_filter(filterfunc)`` from `bleak PR
565 <https://github.com/hbldh/bleak/pull/565>`__