Skip to content

lf_wifi_msgs.py: Add standalone wifi messages script - #381

Merged
saurabhkakade21 merged 1 commit into
greearb:masterfrom
goyalsaurabh06:LISP-195-standalone_wifi_messages
Sep 2, 2026
Merged

lf_wifi_msgs.py: Add standalone wifi messages script#381
saurabhkakade21 merged 1 commit into
greearb:masterfrom
goyalsaurabh06:LISP-195-standalone_wifi_messages

Conversation

@abhisheksharma-candela

@abhisheksharma-candela abhisheksharma-candela commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

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

Comment thread py-scripts/lf_wifi_msgs.py Outdated
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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@abhisheksharma-candela abhisheksharma-candela Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right , Fixed it!
Storing previous events based on resource and time-stamp, assuming WiFi messages polling are small and won't bloat memory
Thanks

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@haricharan-candela

Copy link
Copy Markdown
Collaborator
  1. --poll crashes if the newest message has a non-numeric time-stamp
since_ts = self.timestamp_ms(latest[-1]) if latest else 0
since_ts = int(since_ts)

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.

  1. --poll silently drops messages that share a millisecond

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']
SECOND delivered? False

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.

  1. --poll --output json emits a stream that isn't valid JSON

render() always writes a complete JSON array, and the poll loop calls it once per entry. The result is concatenated arrays:

[
  {...}
]
[
  {...}
]

json.loads() -> JSONDecodeError: Extra data: line 10 column 1

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

Comment thread py-scripts/lf_wifi_msgs.py
Comment thread py-scripts/lf_wifi_msgs.py Outdated
Comment thread py-scripts/lf_wifi_msgs.py Outdated
Comment thread py-scripts/lf_wifi_msgs.py Outdated
Comment thread py-scripts/lf_wifi_msgs.py Outdated
Comment thread py-scripts/lf_wifi_msgs.py Outdated
Comment thread py-scripts/lf_wifi_msgs.py
@abhisheksharma-candela
abhisheksharma-candela force-pushed the LISP-195-standalone_wifi_messages branch from b393286 to 03ec5d2 Compare September 2, 2026 06:32
@abhisheksharma-candela

abhisheksharma-candela commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author
  1. --poll crashes if the newest message has a non-numeric time-stamp
since_ts = self.timestamp_ms(latest[-1]) if latest else 0
since_ts = int(since_ts)

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.

  1. --poll silently drops messages that share a millisecond

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'] SECOND delivered? False

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.

  1. --poll --output json emits a stream that isn't valid JSON

render() always writes a complete JSON array, and the poll loop calls it once per entry. The result is concatenated arrays:

[
  {...}
]
[
  {...}
]

json.loads() -> JSONDecodeError: Extra data: line 10 column 1

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

@haricharan-candela Addressed these suggestions

@abhisheksharma-candela abhisheksharma-candela added the Ready for review Ready for code review and feedback. label Sep 2, 2026
Signed-off-by: Abhishek sharma <abhishek.sharma@candelatech.com>
@saurabhkakade21
saurabhkakade21 merged commit 8c8b4c3 into greearb:master Sep 2, 2026
2 checks passed
@haricharan-candela haricharan-candela added Approved Approved for merging. and removed Ready for review Ready for code review and feedback. labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved Approved for merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants