New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Keep MQTT open on LTE or reconnect for every send? Trying to cut our data bill

Keep MQTT open on LTE or reconnect for every send? Trying to cut our data bill

Solved 4 3

We have 22 pump controllers on irrigation wells, each with an ESP32 and a SIM7600 LTE modem, SIMs on a pooled 500 MB/month plan. They send one reading every 5 minutes (flow, pressure, pump state) to Hermetry over MQTT/TLS and keep the connection open with keepalive 60.

Last month the pool ran out on day 24. Per SIM that’s about 25 MB/month for what should be tiny payloads, roughly 80 bytes of JSON every 5 minutes. A colleague says “always connected” is the problem and we should connect, publish, disconnect every time. Another says that’s worse because of TLS.

Who’s right? I’d like numbers if anyone has measured it. And if we change it, will Hermetry show the wells as offline between sends?

Timestamps in UTC or it didn't happen.
♥ 0

Your colleague #2 is probably right. A full TLS handshake costs kilobytes, a keepalive ping is tiny.

♥ 0

I measured this on our trailer trackers last year because our carrier bill was silly. Rough numbers from packet captures on a SIM7600, TLS 1.2, the platform’s broker:

  • full reconnect (TCP + TLS handshake with certificate chain + CONNECT + SUBSCRIBEs): about 5 to 6 KB
  • one keepalive round trip (PINGREQ/PINGRESP inside TLS, plus TCP/IP headers and ACKs): roughly 150 to 200 bytes
  • your 80-byte reading as a QoS 1 publish inside TLS with PUBACK: also a couple of hundred bytes

So reconnecting every 5 minutes would cost about 8,640 handshakes a month, 45+ MB. Way worse. Keepalive 60 is 43,200 pings a month, around 8 MB. That’s a big chunk of your 25 MB.

What worked for us:

Keepalive up to 300 s (the broker serves anything above its maximum at 300 anyway). That cuts pings by five. Check your carrier doesn’t drop idle NAT sessions faster; ours held 6 minutes, some drop at 2 to 4. If you see keepalive_timeout in the device’s Log tab, step it down.

Batch. Instead of one publish every 5 minutes, buffer 3 readings and send them as one array with timestamps (ESP32 has NTP, so ts is fine):

[{"ts":1762336800000,"values":{"flow":12.1,"pressure":2.4,"pump":1}},
 {"ts":1762337100000,"values":{"flow":12.3,"pressure":2.4,"pump":1}},
 {"ts":1762337400000,"values":{"flow":11.9,"pressure":2.3,"pump":1}}]

Same data, one publish, and it also counts as one message against the monthly quota instead of three.

Look for chatty extras. In our case the worst was the firmware sending client attributes (IP, RSSI, firmware version) on every publish. Only send them on change.

On offline: with Live connection as the online rule they stay online as long as the MQTT session is open, so with keepalive 300 nothing changes. If you ever do go connect-send-disconnect, switch them to a profile with Recent message, otherwise they’d show offline between sends.

Still waiting for the gateway to reconnect.
Accepted solution♥ 8

Numbers are in after two weeks. Keepalive 300 (our carrier is fine with it, no timeouts in the Log tab), batches of 3, attributes only on change. Projected ~9 MB per SIM per month, down from 25. The attribute chatter was the surprise: our firmware was publishing lan.ip and cell.rssi as attributes with every reading. Moved rssi into telemetry every 15 minutes instead. Thanks Kevin, those measurements saved me a week.

Timestamps in UTC or it didn't happen.
♥ 0

Nice. If the pumps ever need commands, keep in mind a reading batched for 15 minutes doesn’t delay those, they come down the open session.

♥ 0
Viewing 5 posts – 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Join the conversation

Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

Share