ESP-Now support for ESP32 (and ESP8266)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
davef
Posts: 134
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: ESP-Now support for ESP32 (and ESP8266)

Post by davef » Fri Jan 08, 2021 6:56 pm

Following on from your example if I then try to bring up the network interface:

Code: Select all

>>> sta_if = network.WLAN(network.STA_IF)
>>> sta_if.active(True)
True
>>> sta_if.ifconfig(('192.168.10.99', '255.255.255.0', '192.168.10.1', '8.8.8.8'))
>>> sta_if.isconnected()
False
>>> 
I will now check the official image.

User avatar
Roberthh
Posts: 2272
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP-Now support for ESP32 (and ESP8266)

Post by Roberthh » Fri Jan 08, 2021 8:16 pm

I do not see a call to sta_if.connect(). Without that, the module will not connect,

davef
Posts: 134
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: ESP-Now support for ESP32 (and ESP8266)

Post by davef » Fri Jan 08, 2021 8:29 pm

Ah, let me focus a bit harder!

Sorry, my previous post was incorrect ... it did not reflect that I was actually doing a re-connect in the code I was testing. I have gone through the process as Peter suggested, line by line, and the re-connection works.

Also, my program now works at home-base, maybe because it is a different wireless router. I will re-check at the remote location.

Thank you for the support guys.

Dave

davef
Posts: 134
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: ESP-Now support for ESP32 (and ESP8266)

Post by davef » Fri Jan 15, 2021 11:11 pm

I have started to test the return values of most of the methods but still don't understand:
import network

w0 = network.WLAN(network.STA_IF)
w0.active(True)

.. method:: ESPNow.send(mac, msg, [sync=True]) (ESP32 only)
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``.

Arguments:
- ...
- ``True``: (default) send ``msg`` to the peer and wait for a response
(or not). Returns ``False`` if any peers fail to respond.

- ``False`` handover ``msg`` to the esp_now software stack for
transmission and return immediately.
Responses from the peers will be discarded.
Always returns ``True``.
1) what is the format for ESPNow.send for a ESP8266?
2) if I get 'False' being returned how do I know if it is because a peer did not respond or that the msg has been handed over to the esp_now software stack?
3) the last line "Always returns "True", What does that mean?

Post Reply