ESP8266 logger that is offline half the time: where do I get the time from?
Solar powered ESP8266 logging a tank temperature every 10 minutes at a remote pump site. It wakes from deep sleep, reads, and tries to send to Hermetry over a shared hotspot that is up maybe half the time. When it’s down I keep readings in RTC memory and send them later as an array with ts.
The issue is the time. NTP only works when the hotspot is up, and the ESP’s own clock in deep sleep drifts minutes per day. I had an idea: there are always a few other Wi-Fi networks in range. Can I read a time from their broadcast frames without connecting? Some kind of timestamp is in there, I’ve seen it in Wireshark.
That field is the TSF, it’s the access point’s own uptime counter in microseconds. Not a date or time.
Aoife’s right, and we went down the same road on our first trackers. What we ended up doing: two cases.
When the reading goes out right away, send a flat object with no ts. Hermetry stamps it with the time it arrived, which for a 10-minute temperature is plenty.
For the buffered ones you need a clock you trust. A DS3231 RTC module costs a few dollars, drifts about a minute a year, and runs from a coin cell while the ESP sleeps. Set it from NTP every time the hotspot is up and read it on every wake.
Don’t make up times. If the clock isn’t set yet (fresh coin cell, never been online) mark those readings and drop them or send them without ts. Hermetry refuses a record more than 10 minutes in the future as bad_ts, and a record in the past lands at the wrong place on the chart, which nobody notices for months. ts has to be milliseconds UTC. All on Timestamps, late and duplicate readings.
One gotcha with the DS3231 boards: the cheap ones have a charging circuit for the coin cell that you should remove if you use a CR2032.
DS3231 fitted, charging resistor removed (thanks Jason, mine had it), NTP sets it when the hotspot is up. Buffered readings now land at the right times, and the two days of readings from before the first sync I sent without ts. Thanks Kevin.
- Bu konuyu yanıtlamak için giriş yapmış olmalısınız.
Sohbete katılın
Soru sormak ve yanıtlamak, yararlı gönderileri beğenmek ve sorununuzu çözen yanıtı işaretlemek için oturum açın. Her katkı puan ve seviye kazandırır.

