ESP-Now support for ESP32 (and ESP8266)

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

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

Post by davef » Mon Jul 25, 2022 2:39 am

- all 3 of them and Generic.
- will try that again ... it use to return true with v1.17 on all units.
- no
- will try that, probably tomorrow if it is not raining too hard!

I can check e0.get_peers as he is sitting beside me.

Last suggestion ... tomorrow.

Thank you for the hints.

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

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

Post by davef » Mon Jul 25, 2022 2:51 am

e0.get_peers()

Code: Select all

((b'\x08:\xf2\xab^\x04', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, 0, False),)
so, channel is 0, right?

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

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

Post by davef » Mon Jul 25, 2022 3:03 am

And on the repeater:

Code: Select all

e0.add_peer(local)
because local is on channel 6 (WiFi) does that mean e0 is still on channel 0?

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

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

Post by mekanixms » Mon Jul 25, 2022 8:09 am

Hi!

On the commit 44f65965b (espnow-g20-v1.19.1) for whatever reason I notice that espnow.peers_table is empty

Code: Select all

>>> e.espnow.peers_table
{}
but e.espnow.get_peers() returns the expected value

Code: Select all

>>> e.espnow.get_peers()
((b'\x94\xb9~\xe3\xb5\xc4', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 2, 0, False),)
precisely it shows the new peer.

Shouldn't peers_table be automatically populated when I add an user with add_peer??

I am running the code on STA_IF, both sender/receiver on the same channel (wlan interfaces but in espnow module, set the channels to 2, as you can see above)

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

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

Post by mekanixms » Mon Jul 25, 2022 10:50 am

In my prev post I tested with STA active, AP if disabled; same issues with AP enabled and STA active

After further testing, I see that the espnowObject.peers_table is only populated, with the new macs from add_peer, when both AP and STA interfaces are active (STA if can be disconnected but should be active, and of course same channel for all devices on the AP if).
This way it works well, sends the messages without errors.

Question: is this a bug? Shouldn't it work on either one of the interfaces, not necessarily both active in the same time ?

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

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

Post by davef » Mon Jul 25, 2022 7:57 pm

Having read several tutorials and howtos trying to do simultaneous ESPNow and WiFi I have the impression that this is even more difficult than trying to maintain a reliable WiFi connection.

For example:
https://randomnerdtutorials.com/esp8266 ... ore-100126
There are a few things you need to take into account if you want to use Wi-Fi to host a web server and use ESP-NOW simultaneously to receive sensor readings from other boards:

The ESP8266 sender boards must use the same Wi-Fi channel of the receiver board.
The Wi-Fi channel of the receiver board is automatically assigned by your Wi-Fi router.
The Wi-Fi mode of the receiver board must be access point and station (WIFI_AP_STA).
You can set up the same Wi-Fi channel manually, or you can add a simple spinet of code on the sender to set its Wi-Fi channel to the same of the receiver board.
The 3rd point where it talks about WIFI_AP_STA I haven't heard that mentioned here until you brought it up.

However, when you noted that this table was not populated could you ever get any messages through?

I had a test system going without having to have both STA and AP active. I would be interested to see your non-working code, ie before making STA and AP active. My test system was basically Glenn's proxy and sensor examples in the ESPNow and Wifi Operation section.

mekanixms
Posts: 28
Joined: Fri Oct 18, 2019 3:46 pm

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

Post by mekanixms » Mon Jul 25, 2022 8:49 pm

My tests are performed on ESP32 only and I can confirm a webserver works together with espnow if on_recv is used

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

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

Post by davef » Mon Jul 25, 2022 9:41 pm

I am only using ESP32. on_recv() required ... will need to read up about that one.

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

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

Post by davef » Mon Jul 25, 2022 10:54 pm

OK, after reading about on_recv() I wonder if your issue is the amount of data you are trying to send through ... before processing it. For recv(), irecv() and the e0 singleton example you only have rxbuf size 516 bytes.

Have you tried increasing that?
Last edited by davef on Mon Jul 25, 2022 11:54 pm, edited 1 time in total.

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

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

Post by davef » Mon Jul 25, 2022 11:54 pm

When using on_recv() do you find that now you do NOT need both STA and AP interfaces active?

Post Reply