Last active
January 26, 2022 06:36
-
-
Save anecdata/c59d67a3aea4b3d45bc1326a43938837 to your computer and use it in GitHub Desktop.
CircuitPython Espressif Monitor mode ambient frame count per channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import wifi | |
QUEUELEN = 128 # ESP32-S2 (ESP32-S3 can be much longer) | |
NS_PER_CH = 5_000_000_000 # nanoseconds per channel | |
def monitor_ambient(channel, duration): | |
report = {} | |
monitor = wifi.Monitor() | |
monitor.deinit() | |
monitor = wifi.Monitor(channel=channel, queue=QUEUELEN) | |
# maxq is the longest the core queue gets during the channel sampling period | |
report["maxq"] = 0 | |
# total count of frames lost because the core queue was full | |
report["lost"] = 0 | |
report["frames"] = 0 | |
report["time"] = 0 | |
start_ns = time.monotonic_ns() | |
while True: | |
# queue stats | |
if monitor.queued() > report["maxq"]: | |
report["maxq"] = monitor.queued() | |
report["lost"] += monitor.lost() | |
# frame stats | |
received = monitor.packet() | |
if received != {}: | |
report["frames"] += 1 | |
elapsed_ns = time.monotonic_ns() - start_ns | |
if elapsed_ns > duration: | |
report["time"] = elapsed_ns | |
report["fps"] = 1_000_000_000 * (report["frames"] / report["time"]) | |
break | |
return report | |
while True: | |
print("-"*49) | |
print("Count ambient frames...") | |
print(f' Ch frames/s queued lost') | |
for channel in range(1, 14): | |
print(f' {channel:2d}...', end="\r") | |
report = monitor_ambient(channel, NS_PER_CH) | |
print(f' {channel:2d}', end="") | |
print(f'{report["fps"]:9.1f}', end="") | |
print(f'{report["maxq"]:7d}', end="") | |
print(f'{report["lost"]:5d}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: