pyrtan / examples / modem-check / modem-check.toml
1,432 bytes · last changed 2026-10-26 in The catalog grows up: namespaces, publishing by pull request through the gate, gap reports gossiped back to authors; release 0.8.0
| 1 | # Whether a modem on a serial line answers AT. A serial node opens a device |
| 2 | # at a baud rate, writes, and reads until a terminator or the timeout; |
| 3 | # `devices` is the allow-list. An observe retries once on no answer. |
| 4 | |
| 5 | name = "modem-check" |
| 6 | version = 2 |
| 7 | namespace = "pyrtan" |
| 8 | description = "Whether a modem on a serial line answers AT." |
| 9 | tags = ["hardware", "serial"] |
| 10 | license = "MIT" |
| 11 | devices = ["/dev/ttyUSB*", "/dev/ttyACM*"] |
| 12 | start = "at" |
| 13 | |
| 14 | [[triggers]] |
| 15 | pattern = "is the modem up" |
| 16 | [[triggers]] |
| 17 | pattern = "is the modem on {device:word} up" |
| 18 | |
| 19 | [inputs.device] |
| 20 | type = "str" |
| 21 | default = "/dev/ttyUSB0" |
| 22 | |
| 23 | [nodes.at] |
| 24 | kind = "observe" |
| 25 | serial = { device = "{{ inputs.device }}", baud = 9600, write = "AT\r\n", read_until = "\n" } |
| 26 | into = "s" # state.s = { device, baud, sent, body, bytes, complete, json, lines } |
| 27 | timeout = 3 |
| 28 | retries = 1 |
| 29 | extract = [{ into = "answer", regex = "(OK|ERROR)" }] |
| 30 | next = "answered" |
| 31 | |
| 32 | [nodes.answered] |
| 33 | kind = "decide" |
| 34 | on = "answer" |
| 35 | branches = [ |
| 36 | { when = { eq = "OK" }, then = "yes" }, |
| 37 | { when = { eq = "ERROR" }, then = "error" }, |
| 38 | { else = "odd" }, |
| 39 | ] |
| 40 | |
| 41 | [nodes.yes] |
| 42 | kind = "done" |
| 43 | say = "The modem on {{ inputs.device }} is there." |
| 44 | output = { device = "{{ inputs.device }}" } |
| 45 | |
| 46 | [nodes.error] |
| 47 | kind = "fail" |
| 48 | reason = "modem-error" |
| 49 | say = "The modem on {{ inputs.device }} answered ERROR." |
| 50 | |
| 51 | [nodes.odd] |
| 52 | kind = "fail" |
| 53 | reason = "odd-answer" |
| 54 | say = "{{ inputs.device }} answered {{ state.s.body | strip }} to AT." |