8. ESPNOW - CRCibernetica/circuitpython-ideaboard GitHub Wiki

ESPNOW is a protocol build into the ESP32 that allows direct communication between two or more ESP32s, no WIFI Access Point is required.

In order to send data using ESPNOW the sending IdeaBoard must know the MAC Address in the format of a bytearray of the receiving IdeaBoard(s).

The MAC Address can be found by typing the following commands into the Shell (REPL):

>>> import wifi
>>> wifi.radio.mac_address
b'\xd4\xd4\xda\x16\xb7\x1c'

In this case the MAC Address is: b'\xd4\xd4\xda\x16\xb7\x1c'

Install the following code in the IdeaBoard that is going to send the information. Replace b'ªªªªªª' with the MAC Address of the receiver.

import espnow

e = espnow.ESPNow()
peer = espnow.Peer(mac=b'ªªªªªª')
e.peers.append(peer)

e.send("Starting...")
for i in range(10):
    e.send(str(i)*20)
e.send(b'end')

Install and run the following code in the IdeaBoard that is going to be the receiver:

import espnow

e = espnow.ESPNow()
packets = []

while True:
    if e:
        packet = e.read()
        packets.append(packet)
        if packet.msg == b'end':
            break

print("packets:", f"length={len(packets)}")
for packet in packets:
    print(packet)