G
Hi,
We're working on getting the documentation out there. In the meantime you can find it here: https://github.com/pycom/pycom-documentation/pull/387/files (near the bottom):
from network import WLAN
from network import ESPNOW
import binascii
import time
# The callback to be registered when a message has been sent to a Peer
def espnow_tx(result):
# "result" is the parameter in form of 2 element long tuple
# "peer" is the Peer which the message has been sent to
# "sent" is a boolean showing whether the message could be sent
peer, sent = result
mac = peer.addr()
if(sent == False):
print("Sending message to %s failed!" % binascii.hexlify(mac))
else:
print("Message sent to: %s" % (binascii.hexlify(mac)))
# The callback to be registered when a message has been received
def espnow_rx(result):
# "result" is the parameter in form of 3 element long tuple
# "mac" is the MAC address of the sender
# "peer" is the Peer which the message has been received from. If message has been received from a not registered Peer this parameter is None
# "msg" is the payload from the received message
mac, peer, msg = result
if(peer is not None):
print("Message received from %s with content: %s" % (binascii.hexlify(mac), msg))
peer.send("Sending back an answer")
# The ESPNOW module needs that WLAN is initialized
w = WLAN()
# Initialize the ESPNOW module
ESPNOW.init()
# Register the callback which will be called on TX
ESPNOW.on_send(espnow_tx)
# Register the callback which will be called on RX
ESPNOW.on_recv(espnow_rx)
# Add a dedicated Peer with MAC address: 11:22:33:44:55:66
p = ESPNOW.add_peer("112233445566")
# Send a message dedicated to the Peer
p.send("My Message")
# Sending 1 message to all Peers which are registered
ESPNOW.send(None, "Hello all Peers!")