Accessory:
Code: Select all
broadcast = b'\xff\xff\xff\xff\xff\xff'
add_peer(broadcast)
send(broadcast, '')
Code: Select all
peer = irecv()[0]
add_peer(peer)
Code: Select all
broadcast = b'\xff\xff\xff\xff\xff\xff'
add_peer(broadcast)
send(broadcast, '')
Code: Select all
peer = irecv()[0]
add_peer(peer)
Just tested it. I was almost correct.BetterAutomations wrote: ↑Wed Mar 30, 2022 2:12 amSo is pairing an accessory device without encryption as simple as this?
Code: Select all
from esp import espnow
import network
w0=network.WLAN(network.STA_IF)
w0.active(True)
e = espnow.ESPNow()
e.init()
broadcast = b'\xff\xff\xff\xff\xff\xff'
e.add_peer(broadcast)
e.send(broadcast, 'Hello')
Code: Select all
from esp import espnow
import network
w0=network.WLAN(network.STA_IF)
w0.active(True)
e = espnow.ESPNow()
e.init()
while True:
host, msg = e.irecv()
if msg:
e.add_peer(host)
break
Code: Select all
>>> w0.config('mac')
b'\xe0\xe2\xe6L\x19\xf4'
>>>
Code: Select all
>>> e.get_peers()
((b'\xe0\xe2\xe6L\x19\xf4', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, 0, False),)
>>>
Code: Select all
rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4252
load:0x40078000,len:12500
load:0x40080400,len:3392
entry 0x4008060c
could not find module '_boot.py'
MicroPython v1.13-1283-gc768704cf-dirty on 2022-03-30; 8MB/OTA/ESPNow module with ESP32
Type "help()" for more information.
>>> from esp import espnow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: can't import name espnow
>>>
Code: Select all
# git clone glenn20's code
. $HOME/esp-idf/export.sh
cd ~/glenn20/ports/esp32/
vi boards/GENERIC_OTA/mpconfigboard.h
# Change this #define:
#define MICROPY_HW_BOARD_NAME "8MB/OTA/ESPNow module with ESP32"
vi boards/GENERIC_OTA/sdkconfig.board
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-ota.csv"
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESP32_SPIRAM_SUPPORT=y
CONFIG_SPIRAM_CACHE_WORKAROUND=y
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
CONFIG_SPIRAM_USE_MEMMAP=y
vi partitions-ota.csv
# Set up that as I always do
export FLASH_SIZE=8MB
export BOARD=GENERIC_OTA
make clean
make
Code: Select all
cdevidal@ubuntuvm:~/glenn20/ports/esp32$ ls ~/glenn20/docs/library/espnow.rst
ls: cannot access '/home/cdevidal/glenn20/docs/library/espnow.rst': No such file or directory
cdevidal@ubuntuvm:~/glenn20/ports/esp32$
Code: Select all
import network
from esp import espnow
def cb(espn):
while espn.poll():
print(repr(espn.irecv()))
w0=network.WLAN(network.STA_IF)
w0.active(True)
espn = espnow.ESPNow()
espn.config(on_recv=cb)
espn.init()
Code: Select all
import network
from esp import espnow
espn = espnow.ESPNow()
w0=network.WLAN(network.STA_IF)
w0.active(True)
espn.init()
broadcast = b'\xff\xff\xff\xff\xff\xff'
espn.add_peer(broadcast)
Code: Select all
>>> espn.send(broadcast, 'Test')
True
>>>
Code: Select all
>>>
>>>
Code: Select all
>>> (bytearray(b'4\xab\x95ZU`'), bytearray(b'Test'))
>>>
Code: Select all
E (45979) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (45979) wifi:alloc eb len=76 type=2 fail, heap:151108
W (45979) wifi:m f probe req l=0
E (46099) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (46099) wifi:alloc eb len=76 type=2 fail, heap:151108
W (46099) wifi:m f probe req l=0
E (46229) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (46229) wifi:alloc eb len=76 type=2 fail, heap:151108
W (46229) wifi:m f probe req l=0
E (47079) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (47079) wifi:alloc eb len=76 type=2 fail, heap:151184
W (47079) wifi:m f probe req l=0
E (48809) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (48809) wifi:alloc eb len=76 type=2 fail, heap:151108
W (48809) wifi:m f probe req l=0
E (48939) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (48939) wifi:alloc eb len=76 type=2 fail, heap:151108
W (48939) wifi:m f probe req l=0
E (49059) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (49059) wifi:alloc eb len=76 type=2 fail, heap:151108
W (49059) wifi:m f probe req l=0
E (49189) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (49189) wifi:alloc eb len=76 type=2 fail, heap:151108
W (49189) wifi:m f probe req l=0
E (49309) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (49309) wifi:alloc eb len=76 type=2 fail, heap:151108
W (49309) wifi:m f probe req l=0
E (49439) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (49439) wifi:alloc eb len=76 type=2 fail, heap:151108
W (49439) wifi:m f probe req l=0
E (50279) wifi:esf_buf: t=2 l=76 max:32, alloc:32 no eb, TXQ_BLOCK=0
W (50279) wifi:alloc eb len=76 type=2 fail, heap:151052
W (50279) wifi:m f probe req l=0
Code: Select all
MicroPython v1.18 on 2022-01-17; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>> import network
>>> sta_if = network.WLAN(network.STA_IF)
>>> sta_if.active(True)
>>> sta_if.connect('My SSID', 'Passphrase')
E (83336) wifi:sta is connecting, return error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: Wifi Internal Error
>>>
Code: Select all
OSError: Wifi Internal Error
Hmm. Not just callbacks. Central is intermittently not responding at all.BetterAutomations wrote: ↑Thu Mar 31, 2022 7:54 pmAnyone have a problem with intermittent firing of on_recv callbacks? Mine intermittently work, even with a bare minimum implementation. I'm working on dynamic pairing with an unencrypted peer.
Central:Accessory:Code: Select all
import network from esp import espnow def cb(espn): while espn.poll(): print(repr(espn.irecv())) w0=network.WLAN(network.STA_IF) w0.active(True) espn = espnow.ESPNow() espn.config(on_recv=cb) espn.init()
Send a message:Code: Select all
import network from esp import espnow espn = espnow.ESPNow() w0=network.WLAN(network.STA_IF) w0.active(True) espn.init() broadcast = b'\xff\xff\xff\xff\xff\xff' espn.add_peer(broadcast)
Central just ignores it:Code: Select all
>>> espn.send(broadcast, 'Test') True >>>
But sometimes after a hard reset, it works:Code: Select all
>>> >>>
Code: Select all
>>> (bytearray(b'4\xab\x95ZU`'), bytearray(b'Test')) >>>
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()
>>> espn.irecv()
Code: Select all
>>> while True:
... espn.send(broadcast, 'Testing')
... sleep(1)
...
True
True
True
Code: Select all
>>> while True:
... espn.send(broadcast, 'Test')
... sleep(1)
...
False
False
True
False
False
False
False
It was, yes. Even flashing to standard unmodified official uPy firmware binaries, I could no longer connect to WiFi. Pull the device off for some time and it resets itself and eventually starts working again. I don't know what's going on. Found a third ESP32 and am testing with that now. So far it hasn't bricked it. I could blame it on faulty hardware if one chip bricked, but a second bricked in exactly the same way.davef wrote: ↑Fri Apr 01, 2022 12:57 amI often see this error:when my ESP32 Generic runs someone else program that only has a boot.py and a main.pyCode: Select all
OSError: Wifi Internal Error
A hard reset sorts it then I shift most of the code in main to my_program.py and problem goes away.
Haven't seen this with any ESPNow on Generic.
By "bricked" do you mean the hardware is no longer useful?