Skip to content

Build1 publisher3 min readPublished

Termux's wake lock hands a retired Note 4's power budget to your own poll loop

A retired 2014 Galaxy Note 4 runs an open-source marine forecast service on Termux at 1.2 watts from the wall. Getting the draw that low took replacing a 1.5 second polling loop with a 20 second long poll.

The Engineer · Build desk

Illustration accompanying Termux's wake lock hands a retired Note 4's power budget to your own poll loop

What happened

  • A developer runs Maritime Watch, an open-source coastal safety engine, on a 2014 Galaxy Note 4 with 3GB of RAM under Termux and headless Linux, drawing 1.2 watts from the wall.
  • Conditions are graded against three hull classes, under 8 meters, 8 to 15 meters and over 15 meters, from hourly Open-Meteo marine forecasts paired with live AIS vessel traffic.
  • The Android side is two settings: termux-wake-lock to stop the background sleep killers, plus a battery optimization exemption for Termux, with tmux and SSH key auth covering headless operation.
  • The first Telegram bot listener polled on a 1.5 second sleep, left the phone warm to the touch, and showed battery current hovering around 118 mA.
  • The rewrite holds one keep-alive connection open against Telegram's getUpdates endpoint with a 20 second timeout.

Compiled by The EngineerSomething wrong?How this is made

Why it matters

  • cost Power stops being a line item at 0.864 kWh a month; the cost of this architecture is the debugging time to find a sleep interval.
  • constraint A wake lock is an opt-out of the operating system's power management, so every timer, retry and keepalive in the process bills straight to the battery. Any library that polls on a short interval becomes a power decision.
  • capability Because the internal battery carries the service through a mains cut, the 6:00 AM advisory does not depend on grid reliability at the developer's desk.
  • decision Before treating 1.2 watts as a budget for your own always-on job, check whether it can idle between fetches. The before-and-after here shows the client design setting the draw.

Each turn of that first listener paid for four things before it did any work: a DNS resolution, a full TLS handshake, a CPU wakeup out of deep sleep, and an Android radio power-state transition [15]. At a 1.5 second sleep interval that is 2,400 requests an hour, and the post says it kept the Cortex cores active almost continuously [14][15].

The replacement asks Telegram's getUpdates to hold the connection open for up to 20 seconds, with timeout set to 20 and allowed_updates narrowed to message [16]. If nothing arrives, the ceiling is 180 connections an hour, roughly a thirteenth of the old count [19].

Android's contribution to the fix is two settings. termux-wake-lock turns off the background sleep killers, and Termux goes into the operating system's battery optimization exemption list [12]. The install channel matters as well: F-Droid, because according to the post the Google Play Store release is abandoned [10]. None of that is hard. Those two settings take the operating system out of the decision about when the CPU idles. After that, every wakeup belongs to your code. The warm chassis and the 118 mA current reading came out of the poll loop [13].

The alternative the author weighed was a $6 per month low-tier cloud VPS [3]. At 1.2 watts continuous the phone uses 0.864 kWh over a 30 day month [20], so electricity would have to cost about $6.94 per kWh before the power bill reached the VPS bill [21]. The case rests instead on hardware that cost zero dollars because it was already in the house [4], and on a server that brings its own battery and its own Wi-Fi, Bluetooth and cellular radios [17]. The post says the internal battery keeps the server running for hours through a mains cut "without dropping a single packet" [17]. It is the only homelab UPS I have seen that comes with a stylus [22].

1.2 watts is a number for one workload: hourly marine forecasts from Open-Meteo, a live AIS feed, and one held-open socket [2][6][16]. For it to transfer, your service has to leave the cores idle between fetches and leave the radio in one state. The post gives the current draw before the rework and does not state a figure after it [18].

The phone computes a threshold comparison, once per hull class. Twenty knots with a 1.4 meter chop is a breezy afternoon on a 200 meter container vessel and a swamping risk in an 8 meter wooden skiff [9]. Maritime Watch grades the same forecast three ways, flagging small craft above 12 knots of chop or short-period waves over 0.8 meters, and allowing 18 to 20 knots for 8 to 15 meter boats depending on wave period [7]. The example 6:00 AM notification in the post reads: "Safe to head out between 07:00 and 14:00. At 15:00, gusts exceed 24 knots from the northeast; return to port by 14:30." [8]

What to watch

  • A current measurement taken after the long-poll rework, which would show how much of the 1.2 watts the socket still accounts for.
  • How the 2014 battery holds up under permanent mains charging, since the design depends on it as the UPS.
  • A breakdown of where the remaining draw goes: screen off, radios idle, or the held-open connection.
Loading claim ledger
Loading source directory links
Loading share composer
Loading topic controls
Loading related stories