diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..7818b8f67b19330c9881652412bf8d40132a75ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +backup/ +*.log diff --git a/serial_to_mqtt_bridge/check_tmux_session.sh b/serial_to_mqtt_bridge/check_tmux_session.sh new file mode 100755 index 0000000000000000000000000000000000000000..7fa596863e5228f9be602b927ffe05b13606edc8 --- /dev/null +++ b/serial_to_mqtt_bridge/check_tmux_session.sh @@ -0,0 +1,37 @@ +#!/bin/bash +#add to crontab -e +# * * * * * /home/pi/Sustronics/suspilot3_3/serial_to_mqtt_bridge/check_tmux_session.sh Sus_ACM0 >> /home/pi/Sustronics/suspilot3_3/serial_to_mqtt_bridge/check_tmux_session.log 2>&1 + +# Function to print messages with timestamp +log_message() { + echo "$(date '+%Y-%m-%d %H:%M:%S') $1" +} + +# Check if a session name is provided +if [ -z "$1" ]; then + log_message "Usage: $0 <session_name>" + exit 1 +fi + +# Name of the tmux session from the first argument +SESSION_NAME="$1" + +# Check if the session exists +if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + log_message "The tmux session '$SESSION_NAME' is running." +else + log_message "The tmux session '$SESSION_NAME' is not running." + + # Check if /dev/ttyACM0 exists + if [ -e /dev/ttyACM0 ]; then + log_message "The device '/dev/ttyACM0' exists." + + # Set environment variables and run the script + DEVNAME='/dev/ttyACM0' ID_SERIAL_SHORT='ACM0' \ + /home/pi/Sustronics/suspilot3_3/serial_to_mqtt_bridge/udev_trigger.sh + log_message "Script executed with DEVNAME='/dev/ttyACM0' and ID_SERIAL_SHORT='ACM0'." + else + log_message "The device '/dev/ttyACM0' does not exist." + fi +fi +