# LoRaWAN energy-per-useful-event experiment

**Question:** in a battery-powered LoRaWAN sensor node, is it cheaper to send every
sample, or to run a tiny on-node classifier that only transmits when something
interesting happens — and should the spreading factor adapt at the same time?

**What this is:** a seeded, reproducible *simulation* experiment. It is not a
hardware measurement. All physics comes from public datasheets (Semtech
AN1200.13 airtime formula, SX1276 current consumption) and the reviewed
literature. Nothing here was measured on a physical node.

## Files

| file | what it is |
|---|---|
| `lora_energy_experiment.py` | the whole experiment, standard library + numpy/matplotlib |
| `results/summary.json` | every aggregate, with 95 % confidence intervals, plus the assumption block |
| `results/run_log.txt` | console output of the last run |
| `results/fig1_energy_per_event.png` | energy per correctly delivered event vs link margin |
| `results/fig2_coverage_and_false_alarms.png` | event coverage and non-event traffic |
| `results/fig3_false_alarm_sensitivity.png` | false-alarm-rate sensitivity at 4 dB margin |
| `results/fig4_battery_life.png` | projected life on 2 × AA |

## Reproduce

```bash
python3 -m venv .venv
./.venv/bin/pip install numpy matplotlib
./.venv/bin/python files/experiment/lora_energy_experiment.py
```

Runtime is about 3 seconds. Seeds are fixed, so the numbers reproduce exactly.

## Design

Four uplink policies, identical sensor and identical traffic:

| id | policy | transmits | spreading factor |
|---|---|---|---|
| A | always_fixed | every sample | SF7 |
| B | always_adaptive | every sample | lowest SF clearing a 10 dB margin |
| C | filter_fixed | only TinyML-flagged samples | SF7 |
| D | filter_adaptive | only TinyML-flagged samples | adaptive |

- 7 simulated days, one sample every 60 s (10,080 samples), 2 % of samples are
  events worth reporting.
- TinyML gate: 95 % sensitivity, 1 % false-alarm rate on normal samples.
- Link margin above the SF7 demodulation floor is swept 0–10 dB, with 6 dB
  log-normal shadowing per transmission; required SNR improves 2.5 dB per SF step.
- Packet error rate `exp(-0.5 · 10^(margin_dB/10))`.
- Energy: TX 120 mA at 17 dBm on 3.3 V, 150 ms of 7 mA overhead per transmission,
  sampling 20 ms at 5 mA, inference 12 ms at 8 mA.
- 30 independent repetitions per point; intervals are 95 % CI.

## Headline results (1 % false-alarm rate)

| link margin | A J/event | B J/event | C J/event | D J/event | D vs A | recall A | recall D |
|---|---|---|---|---|---|---|---|
| 0 dB | 2.943 | 21.572 | 0.160 | 0.680 | −76.9 % | 44.7 % | 86.5 % |
| 2 dB | 2.398 | 15.318 | 0.133 | 0.504 | −79.0 % | 54.9 % | 85.7 % |
| 4 dB | 1.967 | 9.771 | 0.112 | 0.332 | −83.1 % | 66.9 % | 85.0 % |
| 6 dB | 1.792 | 5.920 | 0.101 | 0.221 | −87.6 % | 73.7 % | 84.4 % |
| 8 dB | 1.575 | 3.580 | 0.090 | 0.146 | −90.7 % | 83.3 % | 86.1 % |
| 10 dB | 1.471 | 2.303 | 0.083 | 0.107 | −92.8 % | 88.8 % | 87.6 % |

Projected life on 2 × AA (2500 mAh): A = 2.16 y flat; D = 4.81 y at 0 dB rising to
30.16 y at 10 dB. C is above 30 y everywhere. These are ceilings: battery aging,
self-discharge and temperature are not modelled.

False-alarm sensitivity at 4 dB margin (policy C): 0.093 J/event at 0.1 % FAR,
0.113 J at 1 %, 0.195 J at 5 % — roughly 2× the energy for no measurable gain in
coverage (62.8 %, 62.2 %, 61.8 %).

## Known limitations

- Simulation, not silicon. No measured current traces.
- One node, no network congestion, no 1 % duty-cycle cap, no retransmissions.
- A single analytic packet-error model; real LoRa PER depends on interference.
- The "adaptive" rule is deliberately naive (target 10 dB margin) — that is the
  point of policy B being expensive, but a smarter controller would do better.
- Energy per delivered event ignores the cloud-side cost of false positives.
