Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login
    Introducing Netgate Nexus: Multi-Instance Management at Your Fingertips.

    CUSTOM LED NETGATE 2100 UPDATE "older pfsense version"

    Scheduled Pinned Locked Moved Hardware
    3 Posts 1 Posters 536 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JonathanLeeJ Offline
      JonathanLee
      last edited by JonathanLee

      #!/bin/sh
      
      # ==============================================================================
      # LED Monitor for pfSense - RAM Lock + Pico Offline Alert (single alert)
      # ==============================================================================
      
      PI_IP="192.168.1.17"
      LOCKFILE="/var/run/deviceonlineday.lock"
      STATEFILE="/var/run/pico_offline.state"
      GPIO_DEV="/dev/gpioc2"
      
      if [ "$1" != "--locked" ]; then
          exec lockf -t 0 "$LOCKFILE" "$0" --locked
      fi
      shift
      
      # --- Ping Pico ---
      if ! ping -c 1 -W 2 "$PI_IP" >/dev/null 2>&1; then
          PICO_ONLINE=0
      else
          PICO_ONLINE=1
      fi
      
      # --- Pico offline logic ---
      if [ "$PICO_ONLINE" -eq 0 ]; then
          if [ ! -e "$STATEFILE" ]; then
              gpioctl -f "$GPIO_DEV" 0 duty 200 >/dev/null 2>&1
      
              php -r '
                require_once("/etc/inc/util.inc");
                require_once("/etc/inc/notices.inc");
                $msg = "Alert: Raspberry Pi Pico at '"$PI_IP"' is offline as of " . date("Y-m-d H:i:s");
                log_error($msg);
                notify_all_remote($msg);
              '
      
              touch "$STATEFILE"
          fi
          exit 0
      else
          [ -e "$STATEFILE" ] && rm -f "$STATEFILE"
      fi
      
      # --- PF state check ---
      check_current_states=$( pfctl -vss | grep -m 4 \
          -e '10.0.0.4:3074' \
          -e ', rule 115' \
          -e '192.168.1.11' \
          -e '192.168.1.15' )
      
      res=1
      resb=1
      resc=1
      resd=1
      
      case "$check_current_states" in *"10.0.0.4:3074"*) res=0;; esac
      case "$check_current_states" in *"192.168.1.11"*)  resb=0;; esac
      case "$check_current_states" in *"192.168.1.15"*)  resc=0;; esac
      case "$check_current_states" in *", rule 115"*)     resd=0;; esac
      
      set_led() {
          gpioctl -f "$GPIO_DEV" "$1" duty "$2" >/dev/null 2>&1
      }
      
      # --- LEDs ---
      if [ "$res" -eq 0 ] && [ "$resb" -eq 0 ]; then
          set_led 3 50; set_led 4 15; set_led 6 55; set_led 7 20; set_led 8 15
      elif [ "$res" -eq 0 ]; then
          set_led 3 0; set_led 4 0; set_led 6 55; set_led 7 20; set_led 8 15
      elif [ "$resb" -eq 0 ]; then
          set_led 3 50; set_led 4 15; set_led 6 0; set_led 7 0; set_led 8 0
      else
          set_led 3 0; set_led 4 0; set_led 6 0; set_led 7 50; set_led 8 0
      fi
      
      if [ "$resc" -eq 0 ] || [ "$resd" -eq 0 ]; then
          set_led 2 50; set_led 0 50
      else
          set_led 2 0;  set_led 0 0
      fi
      

      Make sure to upvote

      JonathanLeeJ 1 Reply Last reply Reply Quote 0
      • JonathanLeeJ Offline
        JonathanLee @JonathanLee
        last edited by JonathanLee

        • fixed lock file issues
        • use of -vss versus -vvss speeds up code 38%
        • set lock file to ram for less ssd use
        • added a email alert for an offline device

        Make sure to upvote

        1 Reply Last reply Reply Quote 0
        • JonathanLeeJ Offline
          JonathanLee
          last edited by

          use of this # --- Ping Pico ---
          if ! ping -c 3 -W 3000 "$PI_IP" >/dev/null 2>&1; then
          PICO_ONLINE=0
          else
          PICO_ONLINE=1
          fi

          seems to respond better as it will try 3 pings each one will wait 3 seconds for a reply if one gets a reply it sees it online if not you get your offline condition.

          Make sure to upvote

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Copyright 2026 Rubicon Communications LLC (Netgate). All rights reserved.
          Privacy Policy · Cookie Policy