From 1fd9e7fa8623efa3262806f9d65eb9d3d025b033 Mon Sep 17 00:00:00 2001 From: dahanzimin <353767514@qq.com> Date: Mon, 19 Jan 2026 12:10:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0espnow=20=E6=94=AF=E6=8C=81wi?= =?UTF-8?q?fi=E8=81=94=E7=BD=91=E4=B8=8E=E5=B9=BF=E6=92=AD=E5=85=B1?= =?UTF-8?q?=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micropython/origin/build/lib/radio.py | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/boards/default_src/micropython/origin/build/lib/radio.py b/boards/default_src/micropython/origin/build/lib/radio.py index e45b8e2f..a5ae46b6 100644 --- a/boards/default_src/micropython/origin/build/lib/radio.py +++ b/boards/default_src/micropython/origin/build/lib/radio.py @@ -15,14 +15,13 @@ from ubinascii import hexlify, unhexlify import network class ESPNow(espnow.ESPNow): - def __init__(self, channel=1, txpower=20): - self._channel = channel - self._txpower = txpower + def __init__(self, channel=None, txpower=20): self._on_handle = {} self._once_irq = True self._nic = network.WLAN(network.STA_IF) #if version else network.WLAN(network.AP_IF) self._nic.active(True) - self._nic.config(channel=self._channel, txpower=self._txpower) + if channel is not None: + self.set_channel(channel, txpower) super().__init__() self.active(True) @@ -46,11 +45,8 @@ class ESPNow(espnow.ESPNow): elif err.args[1] == 'ESP_ERR_ESPNOW_IF': self._nic.active(True) elif err.args[1] == 'ESP_ERR_ESPNOW_NOT_FOUND': - super().add_peer(_peer, channel=self._channel) - try: - return super().send(_peer, str(msg)) - except: - raise OSError("ESPNOW channel ({}) conflicts with WiFi channel ({})".format(self._channel, self.channel)) + super().add_peer(_peer, channel=self.channel) + return super().send(_peer, str(msg)) elif err.args[1] == 'ESP_ERR_ESPNOW_NO_MEM': raise OSError("internal ESP-NOW buffers are full") elif err.args[1] == 'ESP_ERR_ESPNOW_ARG': @@ -66,11 +62,11 @@ class ESPNow(espnow.ESPNow): else : return None,None - def set_channel(self, channel=None, txpower=None): - self._channel = self._channel if channel is None else channel - self._nic.config(channel=self._channel, txpower=self._txpower if txpower is None else txpower) - if self._channel != self.channel: - print("Warning: The set channel ({}) does not match the actual channel ({})".format(self._channel, self.channel)) + def set_channel(self, channel=1, txpower=20): + if not self._nic.isconnected(): + self._nic.config(channel=channel, txpower=txpower) + else: + print("Warning: WiFi is connected, the actual espnow channel is {}".format(self.channel)) def _cb_handle0(self, event_code, data): '''Callback processing conversion'''