ESPNOW Unstable in AP+STA mixed mode

Recurrent H/W and software problems
Tony_A
Posts: 16
Joined: Sun Dec 31, 2023 8:08 am
Has thanked: 7 times
Been thanked: 5 times

ESPNOW Unstable in AP+STA mixed mode

Post by Tony_A »

Have been learning and experimenting with ESPNOW.

Had an earlier post on why ESPNOW didn't work in AP mode and have learned that it doesn't work in AP mode and has to be in either STA or mixed AP+STA mode. So have deleted that post.

Experience so far.

In a more conventional STA mode where esp32 devices connect to central home router and also the development PC with browser.
At least with 2 esp32 devices, everything looks and works reasonably smoothly.

However, once esp32 devices are configured in AP+STA mode, using fake STA as per Help manual. Everything becomes unstable.
PC development browser starts disconnecting and have hard time to reconnect.

Using one esp32 device as simple example sender to send few characters every second, to second esp32 device as simple example receiver.
At least every second transmission reports a tx error and data is not received by receiving device.

Looks like there are some kind of wireless network conflicts happening in the background.
Have tried different wifi channels without any improvement.

Would appreciate feedback from anyone that has successfully used ESPNOW with esp32 devices set in AP+STA mixed mode.



If I can get this to work, it will be a deployment in stand alone espnow network without a central wifi router, so esp32 devices must work as stand alone in AP+STA mode.

PS.
In AP+STA mode, I use seperate PCs to connect to each esp32 device using defined different AP SSid and IP 192.168.4.1. So 2 esp32 devices and their separate development PC are totally isolated from each other. There is no connection to central home wifi router.


UPDATE

Have tried different configuration of STA and STA+AP mode.

In STA mode, I don't see any issues.
as soon as one node, receiver for example, if configured in STA+AP, then the receiver becomes unstable and not very responsive.
It keeps disconnecting the development PC.
Sender starts reporting tx errors.
Receiver may receive and print less than 10 received messages (string of less than 6 characters) in 1 minute, while they are sent at 1 second interval.

Not seeing memory leaking , ramfree reports constant value during the run.

Would be good if Francesco could provide advice and or do a test himself.

Devices are standard esp32 and use recent Annex32 firmware, 1.52.7. Have tried with earlier 1.52.4 with same problem

Another Update

While Receiver in STA+AP mode and being unstable as described above.
printing IP$ returns 0.0.0.0 0.0.0.0 0.0.0.0

Originally when started it was initialized in AP mode with IP 192.168.4.1
As per help manual, to put it in AP +STA there is a command at start of program WIFI.CONNECT "AA", "" ' dummy STA connection to set up mixed wifi Ap+Sta
User avatar
cicciocb
Site Admin
Posts: 2058
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1357 times
Contact:

Re: ESPNOW Unstable in AP+STA mixed mode

Post by cicciocb »

Yes, you are right, the module become slow, probably due to mixed/wrong internal WIFI address / Routing.

I'm trying to see how fix that, probably doing a separate command to put the module in AP+STA mode
User avatar
cicciocb
Site Admin
Posts: 2058
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1357 times
Contact:

Re: ESPNOW Unstable in AP+STA mixed mode

Post by cicciocb »

Bon,
finally I found (and remembered :lol: ) that the ESPNOW requires that all the modules share the same WIFI channel (the same radio frequency).
image.png
So, you just need to put manually, in the config page, the channel number that must be the same for all your ESPNOW modules and the same of your STA access point.
image.png
The mixed AP+STA mode is required only for mixed ESP32 / ESP8266 combinations
image.png
edit:
Take care that the MAC address changes when the module is in STA or AP mode
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 2058
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1357 times
Contact:

Re: ESPNOW Unstable in AP+STA mixed mode

Post by cicciocb »

I've just uploaded another version, the 1.52.8 that fixes the IP address in AP mode
Tony_A
Posts: 16
Joined: Sun Dec 31, 2023 8:08 am
Has thanked: 7 times
Been thanked: 5 times

Re: ESPNOW Unstable in AP+STA mixed mode

Post by Tony_A »

Thank You Francesco.

Have tried with new firmware 1.52.8.

IP address in AP mode can now be changed, :D .

In AP config , Have placed both devices on same radio channel, have done this before.
Have the correct receiver mac address.
Receiving some transmissions.

However, espnow in mixed mode still has the previous problem, slow and unstable.
Possibly, few more transmissions are received now. But lots of Tx errors, receiver in mixed mode is very slow and not responsive, development browser keeps disconnecting and very slow to load and respond.
IP address configuration looks OK now.
But still some underlaying problem in mixed mode?

I had a receiver running a bit longer and looks like there is also a memory leak, eventually it ran out of ram.
Tony_A
Posts: 16
Joined: Sun Dec 31, 2023 8:08 am
Has thanked: 7 times
Been thanked: 5 times

Re: ESPNOW Unstable in AP+STA mixed mode

Post by Tony_A »

Another Update.

Following setup works.

Sender esp32 device set up in STA mode and connected to central home wifi router.

Receiver esp32 set up in AP mode in config settings, so boots up in AP mode.
In Receiving program, if WIFI.CONNECT connects as STA to central home wifi router, then ESPNOW reception works OK.
No obvious observation of other unstable and slow problems as described before.

Possible conclusions??

Device works OK in mixed AP+STA mode if STA is connected to common AP router, same as the sending device, or if connected to a valid working AP such as central wifi router?
This is not practically possible in stand alone ESPNOW network that doesn't have a central AP or router.
The whole point of ESPNOW is that devices communicate with each other in a simple direct transceiver mode without wifi networking.

Device doesn't work in mxed AP+STA mode, if STA is connected to "fake" AP as described in Help manual.

Device is clearly having a problem dealing with "fake" non existent STA connection, maybe it keeps trying to connect to this "fake" connection without a timeout and overwhelms the whole operation making it slow etc??

Reason for STA connection requirement is that it is the only way to enable mixed mode AP+STA to make espnow work.

As Francesco indicated in earlier post above, a new command may be needed in Annex32 to enable AP+STA as a single dedicated mixed mode command. Making sure that the STA part of mixed mode DOESN'T ACTUALLY CONNECT or TRY TO CONNECT to some AP REAL OR FAKE.

I have looked at micropython example implementation, they enable STA and then do "Disconnect" from STA, as STA connection is not required.

Micropython espnow Receive example
Receiver:

import network
import espnow

# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.disconnect() # Because ESP8266 auto-connects to last Access Point
Tony_A
Posts: 16
Joined: Sun Dec 31, 2023 8:08 am
Has thanked: 7 times
Been thanked: 5 times

Re: ESPNOW Unstable in AP+STA mixed mode

Post by Tony_A »

Have done testing for more than an hour.

Sender in STA mode connected to home central wifi router. Works as expected.

Receiver boots up in AP mode.
In basic program using WIFI.connect to central home wifi router.
So, receiver is in mixed AP+STA mode and STA interface is connected to working AP (Home wifi).

Everything works as expected.
No Tx errors.
No other obvious issues.
Ramfree is totally stable in the Receiver.

I am now about 100% certain that a change needs to be made to Annex32
to make mixed mode AP+STA to work properly, possibly a new command in Annex32?
Activate STA mode. BUT don't require STA to be connected to any AP, Real active or Fake.

I fully understand that Francesco has a life and I don't want to make unreasonable demands.
But as espnow is very important to me to keep using Annex32.
I am pledging a modest financial contribution (Beer Money) as a small token incentive to get espnow fixed. I hope that other interested users will also continue to support Francesco to keep going with the wonderful Annex32.
User avatar
cicciocb
Site Admin
Posts: 2058
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1357 times
Contact:

Re: ESPNOW Unstable in AP+STA mixed mode

Post by cicciocb »

Hello Tony_A,
thanks for your contribution.

I already tried yesterday until I discovered that the mixed mode is not required, the receivers can stay in AP mode, you just need to use the MAC address of the module while is in AP mode (as it is different ref [Local Link Removed for Guests] ) and the same wifi channel .

I'm just testing again and I confirm that (I'm using an ESP32-S3 in STA mode connected with the router and an ESP32 in AP mode with the same WIFI channel of the router).

Take care that the wifi channel of the router can change automatically (it was the case for me this morning :D ) so probably you should fix it in the router settings.

Anyway, this do not inhibit me to fix the behavior when the module is in AP+STA mode :idea:
Tony_A
Posts: 16
Joined: Sun Dec 31, 2023 8:08 am
Has thanked: 7 times
Been thanked: 5 times

Re: ESPNOW Unstable in AP+STA mixed mode

Post by Tony_A »

Thank You Francesco.
you just need to use the MAC address of the module while is in AP mode (as it is different ref MAC ADDRESS )
I'm sorry I don't understand , what different mac address?

I get the mac address of the receiving module using mac$ (wlog mac$).
I then put/copy this mac address in the sender module program.

Another option is to use broadcast mac address "FF:FF:FF:FF:FF:FF" in the sender program.
Then ALL receivers will receive the message.

But I cant get espnow to work just in AP mode, can you show me example and code that works?
User avatar
cicciocb
Site Admin
Posts: 2058
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1357 times
Contact:

Re: ESPNOW Unstable in AP+STA mixed mode

Post by cicciocb »

When the module is in AP mode it has a different MAC address; this is because, when the module works in AP+STA mode, each packet must be addressed to the right interface.

This is an extract of the help :
image.png
You do not have the required permissions to view the files attached to this post.
Post Reply