A Python tool for executing specific tasks by monitoring serial port logs.
- Real-time monitoring and automatic saving of serial logs
- Rule matching based on regular expressions
- Support for multiple action types
- Custom Python function invocation
pip install -r requirements.txtpython ifttt_serial.py rule.yamlSee the examples/ folder for full configuration options:
examples/1-basic/rule.yaml- Basic configuration exampleexamples/2-advance/rule.yaml- Advanced configuration example
serial:
port: /dev/ttyUSB0
baudrate: 115200Important Note: The tool automatically creates two log files:
- Device log file (
device_xxx.log) - Records raw data received from the serial port - IFTTT log file (
device_xxx.ifttt.log) - Records logs generated by action execution
For example, configuring device_20250710_120000 will generate:
device_20250710_120000.log- Device raw logdevice_20250710_120000.ifttt.log- IFTTT action log
startup:
action:
type: send
cmd: "reboot"rules:
- match: "BOOT_OK"
action:
type: save-log
text: "Device boot completed"
- match: "ERROR:(\\d+)"
action:
type: python
module: handlers
function: handle_error
args: ["{1}"]timeout:
no_data_sec: 30
on_timeout:
type: shell
cmd: "bash reboot_dut.sh"
max_retries: 3
on_failure:
type: exit
code: 1type: send
cmd: "reboot\r\n"Parameters:
cmd- Command string to send to the serial port
Use Cases:
- Send startup, reboot, or other commands to the device
- Send control commands in automated test flows
Note: This action sends data directly to the currently connected serial port.
type: serial
port: /dev/ttyUSB1
baudrate: 115200
cmd: "reboot\r\n"Parameters:
port- Target serial device pathbaudrate- Baud rate, default is 115200cmd- Command to send
Use Cases:
- Send commands to multiple different serial devices
- Control external devices (e.g., modems, sensors, etc.)
Note: This action creates a temporary serial connection, which is closed automatically after sending.
type: sleep
sec: 2Parameters:
sec- Delay in seconds, supports decimals (e.g., 0.5 means 500 ms)
Use Cases:
- Wait for device response between actions
- Insert delay steps in test flows
type: save-log
text: "Custom log message"Parameters:
text- Content to write to the IFTTT log
Use Cases:
- Record custom events or debug information to the IFTTT log
- Save context information when rules are triggered
Note: This writes to the dedicated IFTTT log file, not the device log file.
type: sequence
actions:
- type: save-log
text: "Sequence Actions start"
- type: sleep
sec: 1
- type: send
cmd: "reboot\r\n"Parameters:
actions- List of actions to execute in order; each action is configured the same as a standalone action
Use Cases:
- Execute multiple actions sequentially (e.g., initialization, wait, start, etc.)
- Combine complex automation flows
Note: Each sub-action in a sequence is executed strictly in order; the next action will not start until the previous one completes.
type: shell
cmd: "echo 'Hello World'"Parameters:
cmd- Shell command string to execute
Use Cases:
- Call external scripts
- Integrate system-level operations into automation flows
Note:
- The shell action waits for the command to finish before continuing; failures are logged to the IFTTT log.
- Shell commands are executed in the directory where the config file is located, avoiding the need for long paths.
type: python
module: custom_handlers
function: handle_error
args: ["{1}", "error"]Parameters:
module- Python module name to import (with or without.pysuffix)function- Function name to callargs- List of arguments to pass to the function, supports placeholders (e.g.,{1}for regex groups)
Use Cases:
- Handle complex logic or custom business requirements
- Send error information to users via email or messaging APIs
Note:
- Custom modules must be in the same directory as the rule file or in the Python path
- Supports passing regex groups and context variables as arguments
type: exit
code: 1Parameters:
code- Exit code (integer), usually0for normal exit, non-zero for errors
Use Cases:
- Automatically exit the program after reaching max retries or detecting fatal errors
Note:
- The exit action immediately terminates the main program; subsequent actions will not be executed
- Can be used with
timeoutand other mechanisms for automated error handling
{timestamp}- Current timestamp{1},{2}, ... - Regex match groups
-
Serial Connection Failure
- Check if the serial device path is correct
- Confirm device permissions and serial parameters
-
Configuration File Errors
- Validate YAML format
- Check for required fields
- Ensure correct YAML indentation (YAML is indentation-sensitive)
-
Python Module Import Failure
- Make sure custom Python modules and rule files are in the same folder
- Check module and function names
ifttt_serial.py- Main programrequirements.txt- Dependency listexamples/- Example configurations and handlerstests/- Test-related files
MIT License