Library espnow

To use this library in your code:

import esp32.espnow
ESP-NOW communication for ESP32 devices.
ESP-NOW is a proprietary protocol developed by Espressif for low-power, connection-less communication between ESP32 devices.
Devices can either communicate by broadcasting messages to all devices in range, or by sending messages to specific devices using their MAC address. In both cases, a key can be used to encrypt the messages.
Limitations
Messages are at most 1470 bytes long. For broadcast messages there is no guarantee that messages are correctly delivered. For direct messages, the implementation ensures that the PHY layer has received the message, but there is no guarantee that the message is processed by the receiving device.
ESP-NOW only supports 20 peers, although one peer-slot can be used to communicate with all devices in range by specifying the broadcast address.
By default only 7 keys can be used. This can be changed in the sdkconfig, but that requires building a custom envelope.
In theory, ESP-NOW can run at the same times as Wifi, but this library currently does not support this.
Examples
Broadcasting an unencrypted message:

service := espnow.Service
service.add-peer espnow.BROADCAST-ADDRESS
service.send "hello world"
    --address=espnow.BROADCAST-ADDRESS
service.close
Receiving a message:

service := espnow.Service
message := service.receive  // Blocks until a message is received.
sender := message.address
data := message.data.to-string
print "Received datagram from $sender: $data"
service.close
Sending to a peer with encryption:

// On both sides, create a key for the peer.
key := espnow.Key.from-string "0123456789abcdef"
// The address of the receiver.
peer := espnow.Address.parse "aa:bb:cc:dd:ee:ff"

service := espnow.Service
service.add-peer peer --key=key
service.send "hello world" --address=peer
service.close
Receiving from a peer with encryption:

key := espnow.Key.from-string "0123456789abcdef"
// The address of the sender.
peer := espnow.Address.parse "ff:ee:dd:cc:bb:aa"

service := espnow.Service
service.add-peer peer --key=key

message := service.receive  // Blocks until a message is received.
sender := message.address
data := message.data.to-string
print "Received datagram from $sender: $data"
service.close

Globals

PHY mode for 11a.

PHY mode for 11b.

PHY mode for 11g.

PHY mode for HE20.

PHY mode for HT20.

PHY mode for HT40.

PHY mode for Low Rate (LR)

PHY mode for VHT20.

11 Mbps with long preamble.

11 Mbps with short preamble.

12 Mbps.

18 Mbps.

1 Mbps with long preamble.

24 Mbps.

2 Mbps with long preamble.

2 Mbps with short preamble.

36 Mbps.

48 Mbps.

54 Mbps.

5.5 Mbps with long preamble.

5.5 Mbps with short preamble.

6 Mbps.

9 Mbps.

Long range, 250 Kbps (MODE-LR).

Long range, 500 Kbps (MODE-LR).

MCS0 with long GI.
6.5 Mbps for 20MHz (MODE-HT20).
13.5 Mbps for 40MHz (MODE-HT40).
8.1 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS0 with short GI.
7.2 Mbps for 20MHz (MODE-HT20).
15 Mbps for 40MHz (MODE-HT40).
8.6 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS1 with long GI.
13 Mbps for 20MHz (MODE-HT20).
27 Mbps for 40MHz (MODE-HT40).
16.3 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS1 with short GI.
14.4 Mbps for 20MHz (MODE-HT20).
30 Mbps for 40MHz (MODE-HT40).
17.2 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS2 with long GI.
19.5 Mbps for 20MHz (MODE-HT20).
40.5 Mbps for 40MHz (MODE-HT40).
24.4 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS2 with short GI.
21.7 Mbps for 20MHz (MODE-HT20).
45 Mbps for 40MHz (MODE-HT40).
25.8 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS3 with long GI.
26 Mbps for 20MHz (MODE-HT20).
54 Mbps for 40MHz (MODE-HT40).
32.5 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS3 with short GI.
28.9 Mbps for 20MHz (MODE-HT20).
60 Mbps for 40MHz (MODE-HT40).
34.4 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS4 with long GI.
39 Mbps for 20MHz (MODE-HT20).
81 Mbps for 40MHz (MODE-HT40).

MCS4 with short GI.
43.3 Mbps for 20MHz (MODE-HT20).
90 Mbps for 40MHz (MODE-HT40).
51.6 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS5 with long GI.
52 Mbps for 20MHz (MODE-HT20).
108 Mbps for 40MHz (MODE-HT40).
48.8 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS5 with short GI.
57.8 Mbps for 20MHz (MODE-HT20).
120 Mbps for 40MHz (MODE-HT40).
68.8 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS6 with long GI.
58.5 Mbps for 20MHz (MODE-HT20).
121.5 Mbps for 40MHz (MODE-HT40).
65 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS6 with short GI.
65 Mbps for 20MHz (MODE-HT20).
135 Mbps for 40MHz (MODE-HT40).
77.4 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS7 with long GI.
65 Mbps for 20MHz (MODE-HT20).
135 Mbps for 40MHz (MODE-HT40).
81.3 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS7 with short GI.
72.2 Mbps for 20MHz (MODE-HT20).
150 Mbps for 40MHz (MODE-HT40).
86 Mbps for 20MHz (MODE-HE20, WiFi-6).

MCS8 with long GI.
A WiFi HE 20MHz (MODE-HE20, WiFi-6) rate, 97.5 Mbps.
This rate might not be supported by all devices.

MCS8 with short GI.
A WiFi HE 20MHz (MODE-HE20, WiFi 6) rate.
This rate might not be supported by all devices.

MCS9 with long GI.
A WiFi HE 20MHz (MODE-HE20, WiFi 6) rate, 108.3 Mbps.
This rate might not be supported by all devices.

MCS9 with short GI.
A WiFi HE 20MHz (MODE-HE20, WiFi 6) rate.
This rate might not be supported by all devices.