Skip to main content

Scripts Reference

This page provides detailed information about all monitoring scripts deployed to routers.

Core Scripts

detect_router_identity.sh

Purpose: Router identification and caching

What it does:

  • Detects router IMEI by testing AT ports (/dev/ttyUSB*)
  • Caches IMEI in /etc/router_imei
  • Caches working AT port in /etc/router_at_port
  • Used by all other monitoring scripts

Dependencies: at-cmd utility


auto-update.sh

Purpose: Automatic script updates

What it does:

  • Checks Supabase for target version assignments
  • Downloads update packages from VPS server
  • Verifies SHA256 checksums
  • Creates backups before updates
  • Tests updated scripts
  • Rolls back on failure

Dependencies: curl, tar, sha256sum


Monitoring Scripts

Device Monitoring

push_devices.sh

Purpose: Network device discovery and monitoring

What it does:

  • Scans LAN subnet using nmap
  • Discovers active devices
  • Retrieves MAC addresses from ARP table
  • Gets hostnames from DHCP leases
  • Reports IP, MAC, hostname, and last seen timestamp

Dependencies: nmap, curl

Schedule: Every 5 minutes


push_dhcp.sh

Purpose: DHCP lease monitoring

What it does:

  • Reads /tmp/dhcp.leases file
  • Filters active (non-expired) leases
  • Reports MAC address, IP address, hostname, and expiration time
  • Only inserts new entries (no deletions)

Dependencies: curl

Schedule: Every 15 minutes


push_signal_strength.sh

Purpose: Cellular signal strength monitoring

What it does:

  • Uses AT commands to query modem (AT+CSQ)
  • Converts RSSI to dBm values
  • Implements retry logic (5 attempts)
  • Reports RSSI and dBm values

Dependencies: at-cmd, curl

Schedule: Every 15 minutes


push_sim_slot.sh

Purpose: SIM slot and ICCID monitoring

What it does:

  • Reads SIM GPIO value from /sys/class/gpio/sim/value
  • Gets ICCID using AT commands (AT+CCID, AT+QCCID)
  • Implements fallback to IMSI if ICCID fails
  • Reports active SIM slot and ICCID

Dependencies: at-cmd, curl

Schedule: Every 15 minutes


Configuration Files

supabase_config.env

Purpose: Database connection configuration

Contents:

SUPABASE_BASE_URL="https://your-project.supabase.co"
SUPABASE_API_KEY="your-api-key"
SUPABASE_TABLE_NAME_signal_strength="signal_strength"
SUPABASE_TABLE_NAME_dhcp_list="dhcp_list"
SUPABASE_TABLE_NAME_device_list="device_list"
SUPABASE_TABLE_NAME_sim_slot="sim_slot"

Crontab Configuration

# Run DHCP list push every 15 minutes
*/15 * * * * /root/scripts/push_dhcp.sh

# Run signal strength push every 15 minutes
*/15 * * * * /root/scripts/push_signal_strength.sh

# Run connected devices every 5 minutes
*/5 * * * * /root/scripts/push_devices.sh

# Run SIM slot info push every 15 minutes
*/15 * * * * /root/scripts/push_sim_slot.sh

# Check for updates every 2 hours
0 */2 * * * /root/scripts/auto-update.sh >> /var/log/auto-update.log 2>&1

Script Dependencies

Required Tools

All scripts require these base tools:

  • curl - HTTP requests to Supabase
  • nmap - Network scanning and device discovery
  • at-cmd - Cellular modem communication

Additional Tools (for auto-update)

  • tar - Archive handling (auto-update.sh)
  • sha256sum - Checksum verification (auto-update.sh)
  • ping - Network connectivity testing (auto-update.sh)

Installation

On OpenWrt routers, install required packages:

opkg update
opkg install curl nmap at-cmd

Note: The scripts use POSIX shell tools (grep, awk, cut, tr, cat, date, ip) for JSON parsing and data processing - these are built into OpenWrt.


Data Flow

  1. Router Identity: detect_router_identity.sh caches IMEI and AT port
  2. Monitoring: Each script uses cached identity to report data
  3. Data Storage: All data sent to Supabase tables
  4. Updates: auto-update.sh checks for script updates every 2 hours
  5. Scheduling: Crontab ensures regular execution

Troubleshooting Scripts

Common Issues

Missing Tools

# Check if required tools are installed
which curl nmap at-cmd

# For auto-update functionality, also check:
which tar sha256sum ping

Network Connectivity

# Test Supabase connectivity
curl -I https://your-project.supabase.co

Hardware Compatibility

  • Verify AT port is accessible: ls /dev/ttyUSB*
  • Check SIM slot detection: cat /sys/class/gpio/sim/value
  • Test cellular modem: at-cmd /dev/ttyUSB0 AT

File Permissions

# Check script permissions
ls -la /root/scripts/
chmod +x /root/scripts/*.sh

Manual Testing

Test individual scripts:

/root/scripts/detect_router_identity.sh
/root/scripts/push_devices.sh
/root/scripts/push_dhcp.sh
/root/scripts/push_signal_strength.sh
/root/scripts/push_sim_slot.sh
/root/scripts/auto-update.sh

Log Monitoring

Check for errors:

# System logs
logread | grep scripts

# Auto-update logs
tail -f /var/log/auto-update.log

# Cron logs
logread | grep cron