I've been reading the docs for rtctime, rtcfifo etc. and I assume plenty of people have used them to create devices that push sensor data to a collector. I wondered whether there's an established best pattern.
I've already got it periodically writing one reading to a collector (over HTTP, but that's an implementation detail). Now I'd like it to recover if the collector isn't available.
My guess is (LUA-like pseudocode -- for brevity I've pretended everything is synchronous -- assume the real thing would be callback-oriented):
-- on boot
wifi init
sntp.sync()
if not rcfifo.read() then
rtcfifo.prepare()
end
rtcfifo.put(rtctime.get(), readsensor(), 0, "temp")
while rcfifo.peek() do
if not write_to_collector(rtcfifo.peek()) then
break
end
rtcfifo.pop()
end
rtctime.dsleep(sleepTime)
Is that basically it, or is there something I've missed? Or a neater way (perhaps avoiding using both "peek" and "pop").
Are any of you sharing the code for a working sensor project that uses this?