lf_wifi_msgs.py: Add standalone wifi messages script - #381
Conversation
| since_ts = self.timestamp_ms(latest[-1]) if latest else 0 | ||
| cursor = int(since_ts) | ||
| while not self._poll_stop.is_set() and not (stop and stop()): | ||
| batch = self.since(cursor + 1) # +1: since=time is inclusive |
There was a problem hiding this comment.
This can break if two events have same ms timestamp? Maybe instead do not increment the timestamp by one and filter out any previously read events?
There was a problem hiding this comment.
Right , Fixed it!
Storing previous events based on resource and time-stamp, assuming WiFi messages polling are small and won't bloat memory
Thanks
There was a problem hiding this comment.
Done! Made it cursor based.
It advances since_ts to the newest time-stamp in the batch on each pass and seen holds one entry, or a few if several messages share the timestamp. It will make sure the seen do not grow along with the life of generator
c0aa27b to
3e3bf0a
Compare
3e3bf0a to
b393286
Compare
timestamp_ms() is documented to return None on a missing or non-numeric stamp. The guard only covers latest being empty — not timestamp_ms returning None. Reproduced: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' duration() handles exactly this case with an explicit if base_ms is None: fallback. poll() should do the same. Fix: since_ts = self.timestamp_ms(latest[-1]) if latest else None then if since_ts is None: since_ts = 0.
The dedupe key is (resource, time-stamp), and seen is a set. Two different messages from the same resource in the same millisecond collapse to one key, so once the first is delivered the second is discarded forever. Reproduced with a stub — FIRST delivered, SECOND at the same ms never appears, LATER arrives fine: yielded: ['LATER'] Silent loss, not a hang — which makes it worse in a log-tailing tool where nobody notices. Wi-Fi messages from a busy resource routinely land in the same millisecond. Fix: key on message content too, e.g. (resource, time-stamp, text_as_str), or count occurrences per (resource, ts) and skip only as many as were already yielded.
render() always writes a complete JSON array, and the poll loop calls it once per entry. The result is concatenated arrays:
Anything consuming --outfile msgs.json from a poll run will fail to parse it. Fix: in poll mode emit JSON Lines (one compact object per line) — that's the normal shape for a tail — or document that --output json is batch-only and reject the combination. @abhisheksharma-candela Please check these above |
b393286 to
03ec5d2
Compare
@haricharan-candela Addressed these suggestions |
Signed-off-by: Abhishek sharma <abhishek.sharma@candelatech.com>
03ec5d2 to
48b1bea
Compare
Add standalone wifi messages script
Pull LANforge Wi-Fi messages from the GUI REST API (
/wifi-msgs).CLI query modes:
--last N most recent N messages
--first N oldest N messages still buffered
--since TS everything since a LANforge epoch-ms stamp
--duration 30s|5m everything from the last
--between A B everything between two epoch-ms stamps
--poll [--interval] keep printing new messages as they arrive