Last active
July 10, 2025 02:04
-
-
Save todbot/19a2823bc2318ae03203d3adf43b3078 to your computer and use it in GitHub Desktop.
Simple demo of ESPnow broadcast function on CircuitPython
This file contains hidden or 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
# espnow-simple_hacky_receiver.py -- show ESPnow working broadcast on CircuitPython | |
# 9 Jul 2025 - @todbot | |
# tested on QTPY ESP32-S2 and FunHouse (ESP32-S2) | |
import time | |
import wifi | |
import espnow | |
# https://github.com/adafruit/circuitpython/issues/9380#issuecomment-2463013607 | |
# hack to switch channel that is used for ESPNow | |
# this takes just a few milliseconds, so doesn't waste a lot of power | |
wifi.radio.start_ap(" ", "", channel=6, max_connections=0) | |
wifi.radio.stop_ap() | |
e = espnow.ESPNow() | |
while True: | |
time.sleep(0.3) | |
print("loop") | |
if not e: # returns True if packet | |
continue | |
packet = e.read() | |
print("packet:", packet.msg, packet) |
This file contains hidden or 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
# espnow-simple_hacky_sender.py -- show ESPnow broadcast working on CircuitPython | |
# 9 Jul 2025 - @todbot | |
# tested on QTPY ESP32-S2 and FunHouse (ESP32-S2) | |
import time | |
import wifi | |
import espnow | |
# https://github.com/adafruit/circuitpython/issues/9380#issuecomment-2463013607 | |
# hack to switch channel that is used for ESPNow | |
# this takes just a few milliseconds, so doesn't waste a lot of power | |
wifi.radio.start_ap(" ", "", channel=6, max_connections=0) | |
wifi.radio.stop_ap() | |
e = espnow.ESPNow() | |
peer = espnow.Peer(mac=b'\xff\xff\xff\xff\xff\xff', channel=6) # broadcast | |
e.peers.append(peer) | |
print("here we go") | |
while True: | |
print("sending", time.monotonic()) | |
try: | |
e.send("Hello there %.1f" %time.monotonic(), peer) # note extra peer arg | |
except Exception as ex: | |
print("ex:",ex) | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment