← all lessons
Capstone · #18 of 20

Wi‑Fi Transmit Strategy

Batching, Retries, Timeouts, Security

Why it matters

Wi‑Fi is power-hungry and unreliable. Efficient transmission strategy is critical for battery life.

The idea

Power Consumption

Wi‑Fi is expensive:
        <h3>Connection Strategy</h3>
        <ul>
          <li><strong>Connect once</strong> per cycle (not per reading)</li>
          <li><strong>Reuse connection</strong> if still valid</li>
          <li><strong>Timeout</strong>: Give up after 10 seconds</li>
          <li><strong>Turn off Wi‑Fi</strong> immediately after transmit</li>
        </ul>

        <h3>Transmission Protocol</h3>
        Options:
        <ul>
          <li><strong>HTTP POST</strong>: Simple, works with any server</li>
          <li><strong>MQTT</strong>: Efficient, designed for IoT</li>
          <li><strong>HTTPS</strong>: Secure but more power (TLS overhead)</li>
        </ul>

        <h3>Batching</h3>
        Send multiple readings at once:
        <ul>
          <li>Store readings in RTC memory</li>
          <li>Transmit batch when Wi‑Fi connects</li>
          <li>Reduces connection overhead</li>
        </ul>

        <h3>Retry Strategy</h3>
        <ul>
          <li><strong>Exponential backoff</strong>: Wait longer between retries</li>
          <li><strong>Max retries</strong>: 3 attempts, then give up</li>
          <li><strong>Error handling</strong>: Log failures, continue to sleep</li>
        </ul>

Demo

Wi‑Fi transmission is network communication, not visual. Review this before implementing data transmission.

Key takeaways

Going deeper

For production, use MQTT with QoS level 1 (at least once delivery). For simple projects, HTTP POST to a webhook is sufficient. Always use HTTPS in production (but accept the power cost). Consider using a message queue (like AWS IoT Core) for reliability.

Math details

Power consumption:
  Wi‑Fi idle: 20mA × 10s = 200mAs (wasteful!)
  Wi‑Fi connect: 80mA × 2s = 160mAs
  Wi‑Fi transmit: 170mA × 0.2s = 34mAs
  Total: ~194mAs (if Wi‑Fi turned off immediately)

Connection overhead:
  TCP handshake: ~100ms
  TLS handshake: ~500ms (HTTPS)
  HTTP request: ~50ms
  Total: ~650ms (HTTP) or ~1150ms (HTTPS)

Batching benefit:
  Single reading: 650ms overhead
  10 readings: 650ms + (10 × 50ms) = 1150ms
  Overhead per reading: 115ms (vs 650ms single)

Implementation

LLM Prompt: Wi‑Fi Transmit with Retry