โ† Back to Use Cases
EDGE, IOT, AND APPS

Remote Control Signals

Send narrow, time-bound commands (e.g., "reboot", "change interval", "enable sensor X") via presigned URLs so field devices can act without long-lived credentials.

The Problem

You have field devices that need to receive occasional commands: reboot, change sampling interval, enable/disable sensors, or update configuration. Storing long-lived credentials on devices is risky. Cloud IoT platforms are expensive and complex.

You want to send time-limited, single-use command links that devices can execute without holding credentials.

The WrenDB Solution

Use presigned URLs to create time-limited command signals. Devices poll for commands (public read). Control systems generate presigned URLs that update command values, expiring after 15 minutes. No credentials on devices.

Step-by-Step Guide

1

Set up command stash

Create a stash for device commands:

Terminal
# Create command stash
curl -X POST https://wrendb.com/api/stash

{
  "stash_id": "commands789...",
  "master_token": "token-remote123...",
  "message": "Save this token securely..."
}

# Initialize with "none" (no pending commands)
curl -X POST https://wrendb.com/api/item/commands789.../device-01-cmd \
  -d "none"
2

Device polls for commands

Lightweight device firmware:

device_firmware.py
import requests
import time
import os

STASH_ID = "commands789..."
DEVICE_ID = "device-01"
POLL_INTERVAL = 60  # seconds

def check_for_command():
    """Poll for pending commands (public read - no auth)"""
    try:
        response = requests.get(
            f"https://wrendb.com/api/item/{STASH_ID}/{DEVICE_ID}-cmd",
            timeout=10
        )
        return response.text if response.status_code == 200 else "none"
    except:
        return "none"

def execute_command(cmd):
    """Execute the received command"""
    if cmd == "reboot":
        print("๐Ÿ”„ Rebooting device...")
        os.system("sudo reboot")
    elif cmd.startswith("interval:"):
        interval = int(cmd.split(":")[1])
        print(f"โฑ๏ธ Changing poll interval to {interval}s")
        global POLL_INTERVAL
        POLL_INTERVAL = interval
    elif cmd.startswith("enable:"):
        sensor = cmd.split(":")[1]
        print(f"โœ… Enabling sensor: {sensor}")
        # Enable sensor logic...
    elif cmd == "none":
        pass  # No command
    else:
        print(f"โ“ Unknown command: {cmd}")

def main_loop():
    print(f"Device {DEVICE_ID} started, polling every {POLL_INTERVAL}s")

    while True:
        cmd = check_for_command()
        if cmd != "none":
            print(f"๐Ÿ“ฅ Received command: {cmd}")
            execute_command(cmd)

        time.sleep(POLL_INTERVAL)

if __name__ == "__main__":
    main_loop()
3

Send time-limited commands

Generate presigned command URLs:

send_command.sh
#!/bin/bash

STASH_ID="commands789..."
TOKEN="$REMOTE_CONTROL_TOKEN"
DEVICE_ID="$1"
COMMAND="$2"

if [ -z "$DEVICE_ID" ] || [ -z "$COMMAND" ]; then
  echo "Usage: send_command.sh DEVICE_ID COMMAND"
  echo "Examples:"
  echo "  send_command.sh device-01 reboot"
  echo "  send_command.sh device-01 interval:120"
  echo "  send_command.sh device-01 enable:temp-sensor"
  exit 1
fi

# Generate presigned URL that sets the command
PRESIGNED_URL=$(curl -X POST \
  "https://wrendb.com/api/item/$STASH_ID/$DEVICE_ID-cmd/presign" \
  -H "Authorization: Bearer $TOKEN" \
  -d "$COMMAND" | jq -r '.url')

echo "๐Ÿ“ก Command ready for $DEVICE_ID: $COMMAND"
echo "URL: $PRESIGNED_URL"
echo "(Expires in 15 minutes)"

# Or directly set the command (requires token)
curl -X PUT "https://wrendb.com/api/item/$STASH_ID/$DEVICE_ID-cmd" \
  -H "Authorization: Bearer $TOKEN" \
  -d "$COMMAND"

echo "โœ… Command sent to $DEVICE_ID"

Why This Works

  • No device credentials - Devices only read public URLs
  • Time-limited - Presigned URLs expire after 15 minutes
  • Simple polling - No WebSockets or push notifications needed
  • Audit trail - All commands logged in stash

Related Use Cases

Device Mode Switches - IoT device state management One-click Approvals - Time-limited approval workflows