ESP-Now support for ESP32 (and ESP8266)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

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

Post by BetterAutomations » Fri Apr 01, 2022 3:53 am

davef wrote:
Fri Apr 01, 2022 2:21 am
The documentation says he has put a RSSI function in, but check his GitHub as I am not sure it has made its way into images.
Not clear how that would help, please explain?

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

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

Post by BetterAutomations » Fri Apr 01, 2022 4:02 am

Anyone having bizarre behavior with .irecv()?
1.) I must manually paste .irecv() command before I can start my main code
2.) After about a minute of looping and successfully receiving packets, that stops working

Direct calls to .irecv() only work intermittently. I must first manually paste in an .irecv() at bootup. Tried writing in an .irecv() into the start of the code, no success. Only works when I paste it in manually. Then I call my main code manually. My code loops and calls .poll() and .irecv() again every 20 seconds or so. That works, packets flow, for about a minute and then just stops receiving. Not even restarting the loop works. Only a hard reset works at that point. A manual reset, then manual paste of another .irecv(), then load the main code. Ugh :x

The accessory (sender) is sending a JSON-encoded dict every five seconds. I know that is functional because the receiver picks up on it immediately when I do a manual reset and manually paste in an .irecv().

Am I maybe just flooding the receive buffer? Sending one broadcast every five seconds.

Pasted code:

Code: Select all

MicroPython v1.17-277-gb67384616-dirty on 2022-03-30; 8MB/OTA/ESPNow module with ESP32
Type "help()" for more information.
>>> import network
>>> from esp import espnow
>>> w0=network.WLAN(network.STA_IF)
>>> w0.active(True)
True
>>> espn = espnow.ESPNow()
>>> espn.init()
>>> while espn.poll(): espn.irecv()
(bytearray(b'\xe0\xe2\xe6L\x19\xf4'), bytearray(b'{"val": "coffee_maker", "cmd": "pair"}'))
>>> import _main
# This works for about a minute:
while True:
    # Connect to WiFi, sync NTP...
    while espn.poll():
        espn.irecv()
    # Debug output shows successful receipt of packet...
    # Post output to websocket server
    # Start loop again
Last edited by BetterAutomations on Sun Apr 03, 2022 11:36 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 » Fri Apr 01, 2022 7:01 am

It appeared that you might be having signal level problems. If the units are in the same room then you probably don't have that problem

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

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

Post by BetterAutomations » Fri Apr 01, 2022 11:20 am

davef wrote:
Fri Apr 01, 2022 7:01 am
It appeared that you might be having signal level problems. If the units are in the same room then you probably don't have that problem
The units are less than one meter apart. I'm going to buy two more ESP32 and ensure it is not some hardware failure.

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

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

Post by BetterAutomations » Sun Apr 03, 2022 11:31 pm

Just got a new unit from Amazon, seeing similar problems. That rules out hardware, I think.

It could be my code, but I can't see how. Doing everything the documentation suggests. Guess I cannot use ESP-Now for now. I'll wait 'til it gets officially added and try again.

Edit: Great. And the new hardware is now bricked.

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 Apr 04, 2022 1:08 am

Show us the commands that you are using to erase and program the device.

Also, there are various fixes floating around for problems during boot, ie 1-10uF on the enable button and then hold boot button for awhile release and then hit enable. I never have had to go through that performance.

Which actual bit of hardware are you using? CP2102?

Are any error messages thrown up?

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

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

Post by BetterAutomations » Mon Apr 04, 2022 1:43 pm

When I say "bricked" I mean unusable. The Wi-Fi stops working. I don't mean that I see errors in flashing or otherwise using. Until wlan.connect() they act normally. The newest Lolin that just arrived from Amazon, cannot even connect using the standard official firmware. (MicroPython v1.18 on 2022-01-17; ESP32 module (spiram) with ESP32, esp32spiram-20220117-v1.18.bin)
davef wrote:
Mon Apr 04, 2022 1:08 am
Show us the commands that you are using to erase and program the device.
esptool.py --chip esp32 --port $SERIALPORT erase_flash
esptool.py --port $SERIALPORT --baud 460800 write_flash --flash_size detect 0x1000 $FIRMWARE

davef wrote:
Mon Apr 04, 2022 1:08 am
Which actual bit of hardware are you using? CP2102?
CH340 built into Lolin D32 Pro but the ESP32_DevKitc_V4 that I've used do run CP2102. Never had any problems with either of them 'til now. Played with the DevKitc for about a year now.

davef wrote:
Mon Apr 04, 2022 1:08 am
Are any error messages thrown up?
Posted earlier when I was saying they bricked, the errors that look like this during wlan.connect(). Full output in the previous post.

Code: Select all

E (96386) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (96386) wifi:alloc eb len=76 type=2 fail, heap:150712

W (96386) wifi:m f probe req l=0

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

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

Post by BetterAutomations » Mon Apr 04, 2022 3:04 pm

Found someone who seems to be experiencing a similar issue with broadcasts. Their solution was to increase the WiFi buffer sizes in sdkconfig. Trying that now.
https://www.esp32.com/viewtopic.php?t=7421

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

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

Post by BetterAutomations » Mon Apr 04, 2022 4:32 pm

I tried setting them to their max, no good.
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=25
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=128
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=64
CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=128
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=128

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 Apr 04, 2022 8:14 pm

Mine is slightly different

Code: Select all

esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20210902-v1.17.bin
However, now that I have some idea of what you mean by "bricked" ... where do those errors appear? In rshell?

Probably the most effort that I had to put in over the last year is getting reliable WiFi connect, apparently without the benefit of seeing error messages like yours.

Post Reply