Skip to content

trigger_tools

Pragmatismo edited this page Mar 11, 2023 · 2 revisions

Trigger Tools

Write Log

Script for writing to a log file, by default to the trigger_log.txt log.

log=/home/pi/Pigrow/logs/trigger_log.txt

script="text with spaces"
    
message="text with spaces"

Note: to include spaces ensure the text is in "speech marks"

./write_log.py script="testing" message="a test of the log tool"

will write the line

testing@2023-03-11 20:49:01.167654@a test of the log tool

Output for trigger logic

check switch

Returns the state of a switch connected to the gpio. Identify the switch either with it's name as stored in the pigrow_config.txt or it's gpio number and wiring direction.

name=switch unique name

or

gpio=NUM
type=GND or HIGH

To use this in code the output can be switched to only reply 'on' or 'off'

output=short   - return only on/off

example script using check switch

fan_with_switch.sh

#!/bin/bash

# Run read_switch.py and capture the output
switch_status=$(/home/pi/Pigrow/scripts/triggers/read_switch.py name=fantoggle)

# Check if switch_status equals "on"
if [ "$switch_status" == "on" ]; then
  # If switch is on, run fan_on.py
  /home/pi/Pigrow/scripts/cron/fan_on.py
else`
  # If switch is off, log the message "over-ride switch enabled, not turning on fan"
  /home/pi/Pigrow/scripts/triggers/write_log.sh script=fan message="over-ride switch enabled, not turning on fan"
fi

to make the script executable you must enable it with chmod

chmod +x /path/to/fan_with_switch.sh

note: full paths should be used if the script is to be run through ssh or cron, e.g. /home/pi/Pigrow/...

Clone this wiki locally