This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions.

If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

espnow — Support for the ESP-NOW protocol

This module provides an interface to the ESP-NOW protocol provided by Espressif on ESP32 and ESP8266 devices (API docs).


This module is still under development and its classes, functions, methods and constants are subject to change. This module is not yet included in the main branch of micropython. Until such a time that the code is accepted into the micropython main branch, the following resources are available: Source code | Pre-compiled images | Pull request (PR#6515). Please post issues on the micropython ESPNow Issues page.

Table of Contents:


ESP-NOW is a connection-less wireless communication protocol supporting:

  • Direct communication between up to 20 registered peers:

    • Without the need for a wireless access point (AP),

  • Encrypted and unencrypted communication (up to 6 encrypted peers),

  • Message sizes up to 250 bytes,

  • Can operate alongside Wifi operation (network.WLAN) on ESP32 and ESP8266 devices.

It is especially useful for small IoT networks, latency sensitive or power sensitive applications (such as battery operated devices) and for long-range communication between devices (hundreds of metres).

This module also support tracking the Wifi signal strength (RSSI) of peer devices.

Load this module from the esp module. A simple example would be:


import network
import espnow

# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF)  # Or network.AP_IF
sta.disconnect()   # For ESP8266

e = espnow.ESPNow()
peer = b'\xbb\xbb\xbb\xbb\xbb\xbb'   # MAC address of peer's wifi interface

e.send("Starting...")       # Send to all peers
for i in range(100):
    e.send(peer, str(i)*20, True)


import network
import espnow

# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF)
sta.disconnect()   # Because ESP8266 auto-connects to last Access Point

e = espnow.ESPNow()
peer = b'\xaa\xaa\xaa\xaa\xaa\xaa'   # MAC address of peer's wifi interface

while True:
    host, msg = e.recv()
    if msg:             # msg == None if timeout in recv()
        print(host, msg)
        if msg == b'end':

class ESPNow


class espnow.ESPNow

Returns the singleton ESPNow object. As this is a singleton, all calls to espnow.ESPNow() return a reference to the same object.


Some methods are available only on the ESP32 due to code size restrictions on the ESP8266 and differences in the Espressif API.


Initialise or de-initialise the ESPNow communication protocol depending on the value of the flag optional argument.

  • flag: Any python value which can be converted to a boolean type.

    • True: Prepare the software and hardware for use of the ESPNow communication protocol, including:

      • initialise the ESPNow data structures,

      • allocate the recv data buffer,

      • invoke esp_now_init() and

      • register the send and recv callbacks.

    • False: De-initialise the Espressif ESPNow software stack (esp_now_deinit()), disable callbacks, deallocate the recv data buffer and deregister all peers.

If flag is not provided, return the current status of the ESPNow interface.


True if interface is currently active, else False.

ESPNow.config(param=value, ...)
ESPNow.config('param')   (ESP32 only)

Set or get configuration values of the ESPNow interface. To set values, use the keyword syntax, and one or more parameters can be set at a time. To get a value the parameter name should be quoted as a string, and just one parameter is queried at a time.

Note: Getting parameters is not supported on the ESP8266.


rxbuf: (default=516) Get/set the size in bytes of the internal buffer used to store incoming ESPNow packet data. The default size is selected to fit two max-sized ESPNow packets (250 bytes) with associated mac_address (6 bytes) and a message byte count (1 byte) plus buffer overhead. Increase this if you expect to receive a lot of large packets or expect bursty incoming traffic.

Note: The recv buffer is allocated by Changing this value will have no effect until the next call of

timeout: (default=300,000) Default read timeout (in milliseconds). The timeout can also be provided as arg to recvinto().

rate: (ESP32 only, IDF>=4.3.0 only) Set the transmission speed for espnow packets. Must be set to a number from the allowed numeric values in enum wifi_phy_rate_t.


None or the value of the parameter being queried.

  • OSError(num, "ESP_ERR_ESPNOW_NOT_INIT") if not initialised.

  • ValueError() on invalid configuration options or values.

Sending and Receiving Data

A wifi interface (network.STA_IF or network.AP_IF) must be active() before messages can be sent or received, but it is not necessary to connect or configure the WLAN interface. For example:

import network

sta = network.WLAN(network.STA_IF)
sta.disconnect()    # For ESP8266

Note: The ESP8266 has a feature that causes it to automatically reconnect to the last wifi Access Point when set active(True) (even after reboot/reset). As noted below, this reduces the reliability of receiving ESP-NOW messages. You can avoid this by calling disconnect() after active(True).

ESPNow.send(mac, msg[, sync])
ESPNow.send(msg)   (ESP32 only)

Send the data contained in msg to the peer with given network mac address. In the second form, mac=None and sync=True. The peer must be registered with ESPNow.add_peer() before the message can be sent.

  • mac: byte string exactly 6 bytes long or None. If mac is None (ESP32 only) the message will be sent to all registered peers, except any broadcast or multicast MAC addresses.

  • msg: string or byte-string up to ESPNow.MAX_DATA_LEN (250) bytes long.

  • sync:

    • True: (default) send msg to the peer(s) and wait for a response (or not).

    • False send msg and return immediately. Responses from the peers will be discarded.


True if sync=False or if sync=True and all peers respond, else False.

  • OSError(num, "ESP_ERR_ESPNOW_NOT_INIT") if not initialised.

  • OSError(num, "ESP_ERR_ESPNOW_NOT_FOUND") if peer is not registered.

  • OSError(num, "ESP_ERR_ESPNOW_IF") the wifi interface is not active().

  • OSError(num, "ESP_ERR_ESPNOW_NO_MEM") internal ESP-NOW buffers are full.

  • ValueError() on invalid values for the parameters.

Note: A peer will respond with success if its wifi interface is active() and set to the same channel as the sender, regardless of whether it has initialised it’s ESP-Now system or is actively listening for ESP-Now traffic (see the Espressif ESP-Now docs).


Wait for an incoming message and return the mac adress of the peer and the message. Note: It is not necessary to register a peer (using add_peer()) to receive a message from that peer.


timeout: (Optional) If provided and not None, sets a timeout (in milliseconds) for the read. The default timeout (5 minutes) is set using ESPNow.config(). If timeout is less than zero, then wait forever.

  • (None, None) if timeout before a message is received, or

  • [mac, msg]: where:

    • mac is a bytestring containing the address of the device which sent the message, and

    • msg is a bytestring containing the message.

  • OSError(num, "ESP_ERR_ESPNOW_NOT_INIT") if not initialised.

  • OSError(num, "ESP_ERR_ESPNOW_IF") the wifi interface is not active().

  • ValueError() on invalid timeout values.

ESPNow.recv() will allocate new storage for the returned list and the peer and msg bytestrings. This can lead to memory fragmentation if the data rate is high. See ESPNow.irecv() for a memory-friendly alternative.


Works like ESPNow.recv() but will re-use internal bytearrays to store the return values: [mac, peer], so that no new memory is allocated on each call.


timeout: (Optional) Timeout in milliseconds (see ESPNow.recv()).

  • As for ESPNow.recv(), except that msg is a bytearray, instead of a bytestring. On the ESP8266, mac will also be a bytearray.


Note: You may also read messages by iterating over the ESPNow object, which will use irecv() method for alloc-free reads, eg:

import espnow
e = espnow.ESPNow();
for mac, msg in e:
    print(mac, msg)
    if mac is None:   # mac, msg will equal (None, None) on timeout
ESPNow.recvinto(data[, timeout])

Wait for an incoming message and return the length of the message in bytes. This is the low-level method used by both recv() and irecv() to read messages.


data: A list of at least two elements, [peer, msg]. msg must be a bytearray large enough to hold the message (250 bytes). On the ESP8266, peer should be a bytearray of 6 bytes. The MAC address of the sender and the message will be stored in these bytearrays (see Note on ESP32 below).

timeout: (Optional) Timeout in milliseconds (see ESPNow.recv()).

  • Length of message in bytes or 0 if timeout is reached before a message is received.


Note: On the ESP32:

  • It is unnecessary to provide a bytearray in the first element of the data list because it will be replaced by a reference to a unique peer address in the peer device table (see ESPNow.peers_table).

  • If the list is at latest 4 elements long, the rssi and timestamp values will be saved as the 3rd and 4th elements.


Check if data is available to be read with ESPNow.recv().

For more sophisticated querying of available characters use select.poll:

import uselect as select
import espnow

e = espnow.ESPNow()
poll = select.poll()
poll.register(e, select.POLLIN)

True if data is available to be read, else False.

ESPNow.stats() (ESP32 only)

A 5-tuple containing the number of packets sent/received/lost:

(tx_pkts, tx_responses, tx_failures, rx_packets, dropped_rx_packets)

Incoming packets are dropped when the recv buffers are full. To reduce packet loss, increase the rxbuf config parameters and ensure you are reading messages as quickly as possible.

Note: Dropped packets will still be acknowledged to the sender as received.

Peer Management

The Espressif ESP-Now software requires that other devices (peers) must be registered before we can send() them messages. It is not necessary to register a peer to receive a message from that peer.


Set the Primary Master Key (PMK) which is used to encrypt the Local Master Keys (LMK) for encrypting ESPNow data traffic. If this is not set, a default PMK is used by the underlying Espressif esp_now software stack.

Note: messages will only be encrypted if lmk is also set in ESPNow.add_peer() (see Security in the Espressif API docs).


pmk: Must be a byte string, bytearray or string of length espnow.KEY_LEN (16 bytes).




ValueError() on invalid pmk values.

ESPNow.add_peer(mac[, lmk][, channel][, ifidx][, encrypt])
ESPNow.add_peer(mac, param=value, ...)   (ESP32 only)

Add/register the provided mac address as a peer. Additional parameters may also be specified as positional or keyword arguments:

  • mac: The MAC address of the peer (as a 6-byte byte-string).

  • lmk: The Local Master Key (LMK) key used to encrypt data transfers with this peer (unless the encrypt parameter is set to False). Must be:

    • a byte-string or bytearray of string of length espnow.KEY_LEN (16 bytes), or

    • any non True python value (default= b''), signifying an empty key which will disable encryption.

  • channel: The wifi channel (2.4GHz) to communicate with this peer. Must be an integer from 0 to 14. If channel is set to 0 the current channel of the wifi device will be used. (default=0)

  • ifidx: (ESP32 only) Index of the wifi interface which will be used to send data to this peer. Must be an integer set to network.STA_IF (=0) or network.AP_IF (=1). (default=0/network.STA_IF). See ESPNow and Wifi Operation below for more information.

  • encrypt: (ESP32 only) If set to True data exchanged with this peer will be encrypted with the PMK and LMK. (default = False)

ESP8266: Keyword args may not be used on the ESP8266.

Note: The maximum number of peers which may be registered is 20 (espnow.MAX_TOTAL_PEER_NUM), with a maximum of 6 (espnow.MAX_ENCRYPT_PEER_NUM) of those peers with encryption enabled (see ESP_NOW_MAX_ENCRYPT_PEER_NUM in the Espressif API docs).

  • OSError(num, "ESP_ERR_ESPNOW_NOT_INIT") if not initialised.

  • OSError(num, "ESP_ERR_ESPNOW_EXIST") if mac is already registered.

  • OSError(num, "ESP_ERR_ESPNOW_FULL") if too many peers are already registered.

  • ValueError() on invalid keyword args or values.


Deregister the peer associated with the provided mac address.



  • OSError(num, "ESP_ERR_ESPNOW_NOT_INIT") if not initialised.

  • OSError(num, "ESP_ERR_ESPNOW_NOT_FOUND") if mac is not registered.

  • ValueError() on invalid mac values.

ESPNow.get_peer(mac) (ESP32 only)

Return information on a registered peer.


(mac, lmk, channel, ifidx, encrypt): a tuple of the “peer info” associated with the mac address.

  • OSError(num, "ESP_ERR_ESPNOW_NOT_INIT") if not initialised.

  • OSError(num, "ESP_ERR_ESPNOW_NOT_FOUND") if mac is not registered.

  • ValueError() on invalid mac values.

ESPNow.peer_count() (ESP32 only)

Return the number of registered peers:

  • (peer_num, encrypt_num): where

    • peer_num is the number of peers which are registered, and

    • encrypt_num is the number of encrypted peers.

ESPNow.get_peers() (ESP32 only)

Return the “peer info” parameters for all the registered peers (as a tuple of tuples).

ESPNow.mod_peer(mac, lmk, [channel], [ifidx], [encrypt]) (ESP32 only)
ESPNow.mod_peer(mac, 'param'=value, ...) (ESP32 only)

Modify the parameters of the peer associated with the provided mac address. Parameters may be provided as positional or keyword arguments (see ESPNow.add_peer()).

Callback Methods

ESPNow.on_recv(recv_cb[, arg=None]) (ESP32 only)

Set a callback function to be called as soon as possible after a message has been received from another ESPNow device. The function will be called with arg as an argument, eg:

def recv_cb(e):
e.on_recv(recv_cb, e)
ESPNow.irq(irq_cb) (ESP32 only)

Set a callback function to be called as soon as possible after a message has been received from another ESPNow device. The function will be called with espnow.EVENT_RECV_MSG as the first argument and a list of the peer and received message as the second argument, eg:

def irq_cb(code, data):
    if code == espnow.EVENT_RECV_MSG:
        peer, msg = data
        print(peer, msg)

Note: irq() and on_recv() will each replace the current callback function, so only one of these methods will be active at any given time.

The on_recv() and irq() callback methods are an alternative method for processing incoming espnow messages, especially if the data rate is moderate and the device is not too busy but there are some caveats:

  • The scheduler stack can easily overflow and callbacks will be missed if packets are arriving at a sufficient rate or if other micropython components (eg, bluetooth, machine.Pin.irq(), machine.timer, i2s, …) are exercising the scheduler stack. This method may be less reliable for dealing with bursts of messages, or high throughput or on a device which is busy dealing with other hardware operations.

  • For more information on scheduled function callbacks see: micropython.schedule().




If the underlying Espressif ESPNow software stack returns an error code, the micropython ESPNow module will raise an OSError(errnum, errstring) exception where errstring is set to the name of one of the error codes identified in the Espressif ESP-Now docs. For example:

    e.send(peer, 'Hello')
except OSError as err:
    if len(err.args) < 2:
        raise err
    if err.args[1] == 'ESP_ERR_ESPNOW_NOT_INIT':
    elif err.args[1] == 'ESP_ERR_ESPNOW_NOT_FOUND':
    elif err.args[1] == 'ESP_ERR_ESPNOW_IF':
        raise err

Wifi Signal Strength (RSSI) - (ESP32 only)

The ESPNow object maintains a peer device table which contains the signal strength of the last received message for all known peers. The peer device table can be accessed using ESPNow.peers_table and can be used to track device proximity and identify nearest neighbours in a network of peer devices. This feature is not available on ESP8266 devices.


A reference to the peer device table: a dict of known peer devices and rssi values:

{peer: [rssi, time_ms], ...}


  • peer is the peer MAC address (as bytes);

  • rssi is the wifi signal strength in dBm (-127 to 0) of the last message received from the peer; and

  • time_ms is the time the message was received (in milliseconds since system boot - wraps every 12 days).


>>> e.peers_table
{b'\xaa\xaa\xaa\xaa\xaa\xaa': [-31, 18372],
 b'\xbb\xbb\xbb\xbb\xbb\xbb': [-43, 12541]}

Note: the mac addresses returned by recv() are references to the peer key values in the peer device table.

Note: RSSI and timestamp values in the device table are updated only when the message is read by the application.

Supporting asyncio

A supplementary module (aioespnow) is available to provide uasyncio support.

Note: Asyncio support is available on all ESP32 targets as well as those ESP8266 boards which include the uasyncio module (ie. ESP8266 devices with at least 2MB flash memory).

A small async server example:

import network
import aioespnow
import uasyncio as asyncio

# A WLAN interface must be active to send()/recv()

e = aioespnow.AIOESPNow()  # Returns AIOESPNow enhanced with async support
peer = b'\xbb\xbb\xbb\xbb\xbb\xbb'

# Send a periodic ping to a peer
async def heartbeat(e, peer, period=30):
    while True:
        if not await e.asend(peer, b'ping'):
            print("Heartbeat: peer not responding:", peer)
            print("Heartbeat: ping", peer)
        await asyncio.sleep(period)

# Echo any received messages back to the sender
async def echo_server(e):
    async for mac, msg in e:
        print("Echo:", msg)
            await e.asend(mac, msg)
        except OSError as err:
            if len(err.args) > 1 and err.args[1] == 'ESP_ERR_ESPNOW_NOT_FOUND':
                await e.asend(mac, msg)

async def main(e, peer, timeout, period):
    asyncio.create_task(heartbeat(e, peer, period))
    await asyncio.sleep(timeout), peer, 120, 10))
class aioespnow.AIOESPNow

The AIOESPNow class inherits all the methods of ESPNow and extends the interface with the following async methods.

async AIOESPNow.arecv()

Asyncio support for ESPNow.recv(). Note that this method does not take a timeout value as argument.

async AIOESPNow.airecv()

Asyncio support for ESPNow.irecv(). Note that this method does not take a timeout value as argument.

async AIOESPNow.asend(mac, msg, sync=True)
async AIOESPNow.asend(msg)

Asyncio support for ESPNow.send().

aioespnow.__aiter__()/async __anext__()

AIOESPNow also supports reading incoming messages by asynchronous iteration using async for; eg:

e = AIOESPNow()
async def recv_till_halt(e):
    async for mac, msg in e:
        print(mac, msg)
        if msg == b'halt':

Return an AIOESPNow object. This is a convenience function for adding async support to existing non-async code, eg:

import network
# import espnow
import aioespnow as espnow

e = espnow.ESPNow()  # Returns an AIOESPNow object

Broadcast and Multicast

All active ESP-Now clients will receive messages sent to their MAC address and all devices (except ESP8266 devices) will also receive messages sent to the broadcast MAC address (b'\xff\xff\xff\xff\xff\xff') or any multicast MAC address.

All ESP-Now devices (including ESP8266 devices) can also send messages to the broadcast MAC address or any multicast MAC address.

To send() a broadcast message, the broadcast (or multicast) MAC address must first be registered using add_peer(). send() will always return True for broadcasts, regardless of whether any devices receive the message. It is not permitted to encrypt messages sent to the broadcast address or any multicast address.

Note: ESPNow.send(None, msg) will send to all registered peers except the broadcast address. To send a broadcast or multicast message, you must specify the broadcast (or multicast) MAC address as the peer. For example:

bcast = b'\xff' * 6
e.send(bcast, "Hello World!")

ESPNow and Wifi Operation

ESPNow messages may be sent and received on any active() WLAN interface (network.STA_IF or network.AP_IF), even if that interface is also connected to a wifi network or configured as an access point. When an ESP32 or ESP8266 device connects to a Wifi Access Point (see ESP32 Quickref) the following things happen which affect ESPNow communications:

  1. Power saving mode (ps_mode=WIFI_PS_MIN_MODEM) is automatically activated; and

  2. The radio on the esp device changes wifi channel to match the channel used by the Access Point.

Power Saving Mode: The power saving mode causes the device to turn off the radio periodically (search the internet for “DTIM Interval” for further details), making it unreliable in receiving ESPNow messages. This can be resolved by either of:

  1. Disabling the power-saving mode on the STA_IF interface (ESP32 only);

    • Use sta.config(ps_mode=WIFI_PS_NONE)

  2. Turning on the AP_IF interface will also disable the power saving mode. However, the device will then be advertising an active wifi access point.

    • You may also choose to send your messages via the AP_IF interface, but this is not necessary.

    • ESP8266 peers must send messages to this AP_IF interface (see below).

  3. Configuring ESPNow clients to retry sending messages.

Receiving messages from an ESP8266 device: Strangely, an ESP32 device connected to a wifi network using method 1 or 2 above, will receive ESP-Now messages sent to the STA_IF MAC address from another ESP32 device, but will reject messages from an ESP8266 device!!!. To receive messages from an ESP8266 device, the AP_IF interface must be set to active(True) and messages must be sent to the AP_IF MAC address.

Managing wifi channels: Any other espnow devices wishing to communicate with a device which is also connected to a Wifi Access Point MUST use the same channel. A common scenario is where one espnow device is connected to a wifi router and acts as a proxy for messages from a group of sensors connected via espnow:


import network, time, espnow

sta, ap = wifi_reset()  # Reset wifi to AP off, STA on and disconnected
sta.connect('myssid', 'mypassword')
while not sta.isconnected():              # Wait until connected...
sta.config(ps_mode=network.WIFI_PS_NONE)  # ..then disable power saving
#  # Alternative to above

# Print the wifi channel used AFTER finished connecting to access point
print("Proxy running on channel:", sta.config("channel"))
e = espnow.ESPNow();
for peer, msg in e:
    # Receive espnow messages and forward them to MQTT broker over wifi


import network, espnow

sta, ap = wifi_reset()   # Reset wifi to AP off, STA on and disconnected
sta.config(channel=6)    # Change to the channel used by the proxy above.
peer = b'0\xaa\xaa\xaa\xaa\xaa'  # MAC address of proxy
e = espnow.ESPNow();;
while True:
    msg = read_sensor()
    e.send(peer, msg)

Other issues to take care with when using ESPNow with wifi are:

  • Set WIFI to known state on startup: Micropython does not reset the wifi peripheral after a soft reset. This can lead to unexpected behaviour. To guarantee the wifi is reset to a known state after a soft reset make sure you deactivate the STA_IF and AP_IF before setting them to the desired state at startup, eg.:

    import network, time
    def wifi_reset():   # Reset wifi to AP_IF off, STA_IF on and disconnected
      sta = network.WLAN(network.STA_IF);
      ap = network.WLAN(network.AP_IF);
      while not
      sta.disconnect()   # For ESP8266
      while sta.isconnected():
      return sta, ap
    sta, ap = wifi_reset()

    Remember that a soft reset occurs every time you connect to the device repl and when you type ctrl-D. See Issue 9004 for more information.

  • STA_IF and AP_IF always operate on the same channel: the AP_IF wil change channel when you connect to a wifi network; regardless of the channel you set for the AP_IF (see Attention Note 3 ). After all, there is really only one wifi radio on the device, which is shared by the STA_IF and AP_IF virtual devices.

  • Disable automatic channel assignment on your wifi router: If the wifi router for your wifi network is configured to automatically assign the wifi channel, it may change the channel for the network if it detects interference from other wifi routers. When this occurs, the ESP devices connected to the wifi network will also change channels to match the router, but other ESPNow-only devices will remain on the previous channel and communication will be lost. To mitigate this, either set your wifi router to use a fixed wifi channel or configure your devices to re-scan the wifi channels if they are unable to find their expected peers on the current channel.

  • Micropython re-scans wifi channels when trying to reconnect: If the esp device is connected to a Wifi Access Point that goes down, micropython will automatically start scanning channels in an attempt to reconnect to the Access Point. This means espnow messages will be lost while scanning for the AP. This can be disabled by sta.config(reconnects=0), which will also disable the automatic reconnection after losing connection.

  • Some versions of the ESP IDF only permit sending ESPNow packets from the STA_IF interface to peers which have been registered on the same wifi channel as the STA_IF:

    ESPNOW: Peer channel is not equal to the home channel, send fail!

ESPNow and Sleep Modes

The machine.lightsleep([time_ms]) and machine.deepsleep([time_ms]) functions can be used to put the ESP32 and peripherals (including the WiFi and Bluetooth radios) to sleep. This is useful in many applications to conserve battery power. However, applications must disable the WLAN peripheral (using active(False)) before entering light or deep sleep (see Sleep Modes). Otherwise the WiFi radio may not be initialised properly after wake from sleep. If the STA_IF and AP_IF interfaces have both been set active(True) then both interfaces should be set active(False) before entering any sleep mode.

Example: deep sleep:

import network, machine, espnow

sta, ap = wifi_reset()            # Reset wifi to AP off, STA on and disconnected
peer = b'0\xaa\xaa\xaa\xaa\xaa'   # MAC address of peer
e = espnow.ESPNow()
e.add_peer(peer)                  # Register peer on STA_IF

print('Sending ping...')
if not e.send(peer, b'ping'):
  print('Ping failed!')                 # Disable the wifi before sleep
print('Going to sleep...')
machine.deepsleep(10000)          # Sleep for 10 seconds then reboot

Example: light sleep:

import network, machine, espnow

sta, ap = wifi_reset()            # Reset wifi to AP off, STA on and disconnected
peer = b'0\xaa\xaa\xaa\xaa\xaa'   # MAC address of peer
e = espnow.ESPNow()
e.add_peer(peer)                  # Register peer on STA_IF

while True:
  print('Sending ping...')
  if not e.send(peer, b'ping'):
    print('Ping failed!')               # Disable the wifi before sleep
  print('Going to sleep...')
  machine.lightsleep(10000)       # Sleep for 10 seconds
  sta.config(channel=6)           # Wifi loses config after lightsleep()