ws281x/src/esp_now.py

28 lines
614 B
Python

import network
import espnow
import select
# A WLAN interface must be active to send()/recv()
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.disconnect() # Because ESP8266 auto-connects to last Access Point
ap_mac = ap.config('mac')
print(ap_mac)
print(ubinascii.hexlify(ap_mac))
e = espnow.ESPNow()
e.active(True)
poll = select.poll()
poll.register(e, select.POLLIN)
poll.poll(0)
while True:
for event in poll.poll(0) :
if event[0] == e:
host, msg = e.recv()
if msg: # msg == None if timeout in recv()
print(host, msg)