Module homie-p1.copas

Copas based async P1 reader.

This module uses an OS command to read from (using io.popen). So a socat command can be used to read from a serial port and to pass it to stdout which will be captured by io.popen.

Because io.popen based IO is blocking, the copas.async module is used to create an OS thread (using LuaLanes) to do this task. So the core Copas loop remains fully async.

TL;DR; provide an OS command to read the P1 data from, and this module will fully async turn them into parsed datagrams to handle.

Info:

  • Copyright: Copyright (c) 2022-2022 Thijs Schreijer
  • License: MIT, see LICENSE.md.
  • Author: Thijs Schreijer

Functions

P1.new (opts) Constructs and returns a new reader instance.
P1:stop () Instructs reader to exit.

Fields

log Logger is set on the module table, to be able to override it.


Functions

P1.new (opts)
Constructs and returns a new reader instance. Upon constructing the reader, it will immediately open the stream and start parsing in background task.

Parameters:

  • opts A table with configuration options.
    • log logger A LuaLogging compatible logger object to use for logging in this instance. If omitted, the logger configured on the module table (field log) will be used. (optional)
    • stream_open_command string The command to use with io.popen to open the stream to read P1 data from. Typically this is a socat type command.
    • handler function A datagram handler function. The function will get a single parsed datagram each time it is called.
P1:stop ()
Instructs reader to exit.

Fields

log
Logger is set on the module table, to be able to override it. Default is the LuaLogging default logger (if loaded), or a no-op function. Per client overrides can be given in P1.new.
generated by LDoc 1.4.6 Last updated 2023-01-05 15:41:28