blinkenxmas.mqtt
The blinkenxmas.mqtt module defines the MessageThread class,
the thread used by bxweb and bxcli to communicate with
the MQTT broker.
Classes
- class blinkenxmas.mqtt.MessageThread(config, queue)[source]
The blinkenxmas MQTT thread class wraps an instance of
paho.mqtt.client.Clientin aThreadfor background execution. Instances of this class may be used as a context manager that will start the thread upon entry, and stop it (re-raising any exception that occurred during execution) on exit. This is the recommended method of running this thread.- Parameters:
config (argparse.Namespace) – The application configuration
queue (queue.Queue) – The queue to submit animations to for transmission to the broker
Support functions
- blinkenxmas.mqtt.render(animation, fps, chunk_size=4096)[source]
Given an animation (which is a list of lists of strings of HTML color specifications), and an fps speed, returns a byte-string representation of the animation.
The byte-string returned consists of:
An unsigned byte containing the fps value
An unsigned short (2 bytes in network order) containing the number of frames following
For each frame:
An unsigned byte containing the number of LED changes following
For each LED change:
An unsigned byte with the zero-based index of the LED
An unsigned short (2 bytes in network order) containing the color of the LED in RGB565 format
For example, an animation that switches the first and second LEDs between red and blue at 1fps would be rendered as:
b"\x01\x02\x02\x00\xF8\x00\x01\x00\x00\x02\x00\x00\x00\x01\x00\x1F"