Thanks Dave. I had hoped the Managing wifi channels paragraph and examples addressed that.
The channel is actually set in the network.WLAN.config() method, not the ESPNow.config() method. See https://docs.micropython.org/en/latest/ ... LAN.config.
Thanks Dave. I had hoped the Managing wifi channels paragraph and examples addressed that.
OK - I get it now. Yeah - the espnow docs imply you could/should just register peers on different channels with add_peer() and espnow will automatically handle switching channels. In practice, however, I have found that very unreliable depending on the ESP-IDF version (and fails if you are connected to a wifi AP) and is not a good mode of operation if you also want to receive messages from those peers. It is much easier to just run all your peers on the same channel and set that with w0.config(channel=X) - or just rely on the default channel=1.
So, if I am prepared to miss the 1 in a 1,000,000 messages on the ESPNow interface then I don't need to do any connection testing in my code?f the ESP device is connected to a Wifi Access Point that goes down, the device will 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 w0.config(reconnects=0), which will also disable the automatic re-connection after losing connection.
Hi Guido,Guido wrote: ↑Thu Jul 21, 2022 1:28 amI am testing the espnow functionality using a Pre-compiled image (firmware-esp32-GENERIC.bin)
The Espnow functionality is working great but I noticed I cannot import the 'urequests' lib anymore.
It looks like 'urequests' is not included in the pre-compiled image?
(I was able to import this lib when I was using the offical 1.19.1 generic-esp32-image)
Code: Select all
from esp import espnow
import network
import time
import ubinascii
import components.device_type.DeviceType as DeviceType
class ESPNowController():
def __init__(self):
self.wlan = network.WLAN(network.STA_IF) # network.STA_IF Or network.AP_IF
self.wlan.active()
print ('wifi initialized')
self.esp_now = espnow.ESPNow()
self.esp_now.init()
print ('esp_now initialized')
def get_current_mac(self):
return ubinascii.hexlify(self.wlan.config('mac'),':').decode()
# return self.wlan.config('mac')
def add_peer(self, mac):
self.esp_now.add_peer(mac)
def send_data(self, data):
try:
self.esp_now.send("test")
except OSError as err:
print("Error: {0}".format(err))
time.sleep_ms(1000)