pyrtan / sourcev0.13.0 · main

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
5name = "modem-check"
6version = 2
7namespace = "pyrtan"
8description = "Whether a modem on a serial line answers AT."
9tags = ["hardware", "serial"]
10license = "MIT"
11devices = ["/dev/ttyUSB*", "/dev/ttyACM*"]
12start = "at"
13
14[[triggers]]
15pattern = "is the modem up"
16[[triggers]]
17pattern = "is the modem on {device:word} up"
18
19[inputs.device]
20type = "str"
21default = "/dev/ttyUSB0"
22
23[nodes.at]
24kind = "observe"
25serial = { device = "{{ inputs.device }}", baud = 9600, write = "AT\r\n", read_until = "\n" }
26into = "s" # state.s = { device, baud, sent, body, bytes, complete, json, lines }
27timeout = 3
28retries = 1
29extract = [{ into = "answer", regex = "(OK|ERROR)" }]
30next = "answered"
31
32[nodes.answered]
33kind = "decide"
34on = "answer"
35branches = [
36 { when = { eq = "OK" }, then = "yes" },
37 { when = { eq = "ERROR" }, then = "error" },
38 { else = "odd" },
39]
40
41[nodes.yes]
42kind = "done"
43say = "The modem on {{ inputs.device }} is there."
44output = { device = "{{ inputs.device }}" }
45
46[nodes.error]
47kind = "fail"
48reason = "modem-error"
49say = "The modem on {{ inputs.device }} answered ERROR."
50
51[nodes.odd]
52kind = "fail"
53reason = "odd-answer"
54say = "{{ inputs.device }} answered {{ state.s.body | strip }} to AT."