guild icon
Toit
#ESPNow crashes on ESP32-S3
Thread channel in help
theHuanter
theHuanter 03/18/2024 11:31 PM
When I try to add a peer to a ESPNow device to connect to a ESPNow Station I am receiving a crash (will post in a new message)

I am starting the station with:
service := espnow.Service.station --key=null //3030F9791AE4 service.add-peer (Address #[0x30, 0x30, 0xf9, 0x79, 0x1a, 0xe4]) --channel=1

and the client side using:
service := espnow.Service.station --key=null print "Add peer" service.add-peer ADDRESS --channel=1

I also flashed the device using the proxy option:
Flashing: jag flash -p COM19 --chip=esp32s3 --uart-endpoint-rx=44
Monitor: jag monitor -p COM19 --proxy
theHuanter
theHuanter 03/18/2024 11:31 PM
log
floitsch
floitsch 03/18/2024 11:45 PM
I will see if I can reproduce
theHuanter
theHuanter 03/19/2024 07:57 AM
It might has to do with the fact that I am using ESPNow which somehow crashes the WiFi when it tries to turn it off for espnow and reboots the device which then of course stops my program. But I am also getting in a loop there if I try to run it as a container
theHuanter
theHuanter 03/19/2024 09:54 AM
I tried to create a minimal implementation and got this error now:
theHuanter
theHuanter 03/19/2024 09:55 AM
Client:
import esp32.espnow import esp32.espnow show Address import log import gpio import .utils logger ::= log.Logger log.DEBUG_LEVEL log.DefaultTarget --name="bouy" // Station MAC: 3030F9791AE4 ADDRESS ::= Address #[0x30, 0x30, 0xF9, 0x79, 0x1A, 0xE4] main args: logger.debug "MACA: $get-mac-address-str" logger.debug "Start ESP-NOW" service := espnow.Service.station --key=null service.add-peer ADDRESS --channel=11 paket := "test-data".to_byte_array logger.debug "Send datagram: \"$paket\"" service.send paket --address=ADDRESS
theHuanter
theHuanter 03/19/2024 09:55 AM
Station:
import gpio import esp32.espnow import esp32.espnow show Address import log import .utils logger ::= log.Logger log.DEBUG_LEVEL log.DefaultTarget --name="station" main: logger.debug "MACA: $get-mac-address-str" logger.debug "Start Station" service := espnow.Service.station --key=null //3030F97919C8 service.add-peer (Address #[0x30, 0x30, 0xF9, 0x79, 0x1A, 0xE4]) --channel=11 while true: print "Waiting for data" datagram := service.receive logger.debug "Received data $datagram.stringify"
theHuanter
theHuanter 03/19/2024 09:56 AM
I am also confused again which MACA I have to add as a peer on each side
theHuanter
theHuanter 03/19/2024 12:48 PM
I refactored the code to look absolut identical:
Station:
import esp32.espnow import esp32.espnow show Address import log import gpio import .utils ADDRESS ::= Address #[0x30, 0x30, 0xF9, 0x79, 0x1A, 0xE4] CHANNEL ::= 0 logger ::= log.Logger log.DEBUG_LEVEL log.DefaultTarget --name="station" main args: logger.debug "MACA: $get-mac-address-str" logger.debug "Start Station" service := espnow.Service.station --key=null service.add-peer ADDRESS --channel=CHANNEL while true: print "Waiting for data" datagram := service.receive logger.debug "Received data $datagram.stringify"
theHuanter
theHuanter 03/19/2024 12:48 PM
Client:
import esp32.espnow import esp32.espnow show Address import log import gpio import .utils ADDRESS ::= Address #[0x30, 0x30, 0xF9, 0x79, 0x1A, 0xE4] CHANNEL ::= 0 logger ::= log.Logger log.DEBUG_LEVEL log.DefaultTarget --name="bouy" main args: logger.debug "MACA: $get-mac-address-str" logger.debug "Start ESP-NOW" service := espnow.Service.station --key=null service.add-peer ADDRESS --channel=CHANNEL paket := "test-data".to_byte_array logger.debug "Send datagram: \"$paket\"" service.send paket --address=ADDRESS
theHuanter
theHuanter 03/19/2024 12:49 PM
with that I am receiving the data
theHuanter
theHuanter 03/19/2024 12:52 PM
I changed the channel to be 0 on the client side. It seems that I can not change the channel and it is always 0.
I tried to set it to 1 on the station side and kept it 0 on the client side and still was able to send data. Setting it to 1 on the client side was giving me the channel error again. I think this came with an update of the IDF
theHuanter
theHuanter 03/19/2024 12:52 PM
something similar is explained here: https://esp32.com/viewtopic.php?t=18291
theHuanterOPtheHuanter
It might has to do with the fact that I am using ESPNow which somehow crashes the WiFi when it tries to turn it off for espnow and reboots the device which then of course stops my ...
floitsch
floitsch 03/19/2024 01:17 PM
WiFi and ESPNow don't work together, and Toit doesn't protect itself well against it.
If you ever try to use both at the same time you will get a crash.
theHuanter
theHuanter 03/19/2024 01:17 PM
I thought that is was the proxy is "fixing" for me
floitsch
floitsch 03/19/2024 01:18 PM
No. The proxy allows you to still have access to your device even without WiFi.
floitsch
floitsch 03/19/2024 01:18 PM
It gives you a different way of interacting with the ESP32 since you must turn off WiFi.
floitsch
floitsch 03/19/2024 01:18 PM
It would work with ethernet, though.
floitsch
floitsch 03/19/2024 01:19 PM
But Jaguar doesn't use ethernet yet (iirc).
theHuanter
theHuanter 03/19/2024 01:19 PM
no ethernet in this project. How can I disable wifi?
floitsch
floitsch 03/19/2024 01:19 PM
With Jaguar you have to add a flag when running the program or installing the container.
floitsch
floitsch 03/19/2024 01:20 PM
-D jaguar.disabled
theHuanter
theHuanter 03/19/2024 01:20 PM
what happens currently is that whenever I call jag run ... it will crash and I have to call it a second time
floitsch
floitsch 03/19/2024 01:23 PM
I would forget the proxy for now since the committed version doesn't work nicely yet. I have a PR outstanding which should improve things.
Until then my recommendation is:
- jag run -D jag.disabled -D jag.timeout=45s my-app.toit. This gives your app 45s to run before Jaguar kills it, so it can accept new requests. If your app stops earlier Jaguar will start up earlier too.
- jag container install -D jag.disabled -D jag.timeout=1000000m my-container my-app.toit. But in this scenario, I would add a small test to the beginning of your code:
main: pin := gpio.Pin 32 --input --pull-up if pin.get == 0: return // Normal code.
This gives you the option of going into Jaguar by just pulling pin 32 (or whichever you want) low (connecting it to ground) when resetting your device.
theHuanter
theHuanter 03/19/2024 01:25 PM
okay I see - the channel part seems to be still valid anyway. If I change it from 0 to 1 they can not connect anymore
floitsch
floitsch 03/19/2024 01:25 PM
Fwiw, ESPNow + WiFi is always limited.
It is possible (not in Toit) to have both, but the ESPNow would then need to use the same frequency as the WiFi. And it can't force a specific frequency.
theHuanter
theHuanter 03/19/2024 01:26 PM
for this project I would not need WiFi tho
floitsch
floitsch 03/19/2024 01:26 PM
I will have a look at the channel.
floitsch
floitsch 03/19/2024 01:26 PM
You would need to turn off WiFi while using ESPNow.
theHuanter
theHuanter 03/19/2024 01:27 PM
if I fail with this disable option I can anyway always simply re-flash the device, right?(edited)
floitsch
floitsch 03/19/2024 01:27 PM
Yes.
floitschfloitsch
You would need to turn off WiFi while using ESPNow.
theHuanter
theHuanter 03/19/2024 01:29 PM
is this related to the channel issue?
floitsch
floitsch 03/19/2024 01:36 PM
If WiFi is running at the same time all bets are off.
theHuanterOPtheHuanter
something similar is explained here: https://esp32.com/viewtopic.php?t=18291
floitsch
floitsch 03/19/2024 03:36 PM
Yes. this is a good hint.
I will see if I can fix it.
floitsch
floitsch 03/20/2024 12:42 PM
The new SDK now disallows WiFi and EspNow at the same time.
It also changed the API slightly for the channel, which is now given at construction time of the station.
bitphlipphar
bitphlipphar 03/20/2024 12:54 PM
Jaguar v1.31.0 is out with the new SDK.
theHuanter
theHuanter 03/23/2024 11:16 AM
@bitphlipphar it seems that I can not send data anymore with this version?!

[bouy] DEBUG: MACA: 3030F9791AE4 [bouy] DEBUG: Start ESP-NOW [bouy] DEBUG: Add peer: 30:30:f9:79:1a:e4 on channel 0 [bouy] DEBUG: Send datagram: "#[0x74, 0x65, 0x73, 0x74, 0x2d, 0x64, 0x61, 0x74, 0x61]" ****************************************************************************** Decoding by `jag`, device has version <2.0.0-alpha.134> ****************************************************************************** EXCEPTION error. ESP-Now send failed 0: Service.send.<block> <sdk>\esp32\espnow.toit:149:9 1: Mutex.do.<monitor-block> <sdk>\monitor.toit:28:27 2: __Monitor__.locked_.<block> <sdk>\core\monitor_impl_.toit:123:12 3: __Monitor__.locked_ <sdk>\core\monitor_impl_.toit:95:3 4: Mutex.do <sdk>\monitor.toit:28:3 5: Service.send <sdk>\esp32\espnow.toit:143:17 6: main espnow\test-bouy-minimal.toit:26:11 ******************************************************************************
theHuanter
theHuanter 03/23/2024 11:16 AM
the station is also on channel 0
theHuanter
theHuanter 03/23/2024 11:16 AM
CLIENT Code:
import esp32.espnow import esp32.espnow show Address import log import gpio import .utils import .rgb-led show RGBLED ADDRESS ::= Address #[0x30, 0x30, 0xF9, 0x79, 0x1A, 0xE4] CHANNEL ::= 0 logger ::= log.Logger log.DEBUG_LEVEL log.DefaultTarget --name="bouy" led := RGBLED main args: led.blue logger.debug "MACA: $get-mac-address-str" logger.debug "Start ESP-NOW" service := espnow.Service.station --key=null logger.debug "Add peer: $ADDRESS on channel $CHANNEL" service.add-peer ADDRESS --channel=CHANNEL paket := "test-data".to_byte_array logger.debug "Send datagram: \"$paket\"" service.send paket --address=ADDRESS
floitsch
floitsch 03/23/2024 11:16 AM
Can you try a different channel?
theHuanter
theHuanter 03/23/2024 11:17 AM
Station:
import esp32.espnow import esp32.espnow show Address import log import gpio import .utils import .rgb-led show RGBLED ADDRESS ::= Address #[0x30, 0x30, 0xF9, 0x79, 0x1A, 0xE4] CHANNEL ::= 0 logger ::= log.Logger log.DEBUG_LEVEL log.DefaultTarget --name="station" led := RGBLED main args: led.green logger.debug "MACA: $get-mac-address-str" logger.debug "Start Station" service := espnow.Service.station --key=null logger.debug "Add peer: $ADDRESS on channel $CHANNEL" service.add-peer ADDRESS --channel=CHANNEL while true: print "Waiting for data" datagram := service.receive logger.debug "Received data $datagram.stringify"
floitsch
floitsch 03/23/2024 11:17 AM
Maybe it must be greater than 0.
floitsch
floitsch 03/23/2024 11:18 AM
I think I only tested 1+.
theHuanter
theHuanter 03/23/2024 11:19 AM
let me check if I am actually running the latest version
floitsch
floitsch 03/23/2024 11:20 AM
The new version takes the channel as argument to the station construction
floitsch
floitsch 03/23/2024 11:20 AM
It ignores it for add-peer and should give you a deprecation warning if you do use it.
theHuanter
theHuanter 03/23/2024 11:24 AM
it says add-peer is deprecated?
theHuanter
theHuanter 03/23/2024 11:24 AM
espnow\test-station-minimal.toit:21:11: warning: Deprecated 'Service.add-peer'
service.add-peer ADDRESS
^~~~
floitsch
floitsch 03/23/2024 11:25 AM
See my last message
theHuanter
theHuanter 03/23/2024 11:25 AM
yes yes that why I am saying it. I add the channel via the service(edited)
theHuanter
theHuanter 03/23/2024 11:25 AM
just like in the example but I still get the deprecation warning
theHuanter
theHuanter 03/23/2024 11:26 AM
ah no sorry
floitsch
floitsch 03/23/2024 11:26 AM
You shouldn't use --channel for add-peer anymore since you gave it to the constructor earlier(edited)
theHuanter
theHuanter 03/23/2024 11:27 AM
yes yes I was changing the wrong file
floitsch
floitsch 03/23/2024 11:27 AM
Classic :🙂:
theHuanter
theHuanter 03/23/2024 11:28 AM
it says now it is already in use
floitsch
floitsch 03/23/2024 11:28 AM
Could be the WiFi is running?
theHuanter
theHuanter 03/23/2024 11:28 AM
I have not disabled it yet, so I guess so
floitsch
floitsch 03/23/2024 11:29 AM
We would have crashed with an earlier release ..
theHuanter
theHuanter 03/23/2024 11:29 AM
okay I disabled it
theHuanter
theHuanter 03/23/2024 11:29 AM
that seems to work
👍1
theHuanter
theHuanter 03/23/2024 11:31 AM
so sorry to bring that up again: currently I am in development and would like to just disable wifi forever. I am connected via USB and I am also enabled the proxy. so it should be fine to do so, right?
theHuanter
theHuanter 03/23/2024 11:31 AM
at some point I would just like to keep it running for a while and don't want it to stop the container
floitsch
floitsch 03/23/2024 11:33 AM
The proxy doesn't fully work yet but is close. Hopefully next Jaguar release.
theHuanter
theHuanter 03/23/2024 11:33 AM
but it seems that the client can still not send its data
floitsch
floitsch 03/23/2024 11:33 AM
I will probably also add an option never to use WiFi.
theHuanter
theHuanter 03/23/2024 11:33 AM
I just added a 5m timeout for now
floitsch
floitsch 03/23/2024 11:33 AM
At the moment you just need to use a big timeout
theHuanter
theHuanter 03/23/2024 11:34 AM
[bouy] DEBUG: Add peer: 30:30:f9:79:1a:e4 on channel 2 [bouy] DEBUG: Send datagram: "#[0x74, 0x65, 0x73, 0x74, 0x2d, 0x64, 0x61, 0x74, 0x61]" ****************************************************************************** Decoding by `jag`, device has version <2.0.0-alpha.143> ****************************************************************************** EXCEPTION error. ESP-Now send failed 0: Service.send.<block> <sdk>\esp32\espnow.toit:157:9 1: Mutex.do.<monitor-block> <sdk>\monitor.toit:28:27 2: __Monitor__.locked_.<block> <sdk>\core\monitor_impl_.toit:123:12 3: __Monitor__.locked_ <sdk>\core\monitor_impl_.toit:95:3 4: Mutex.do <sdk>\monitor.toit:28:3 5: Service.send <sdk>\esp32\espnow.toit:151:17 6: main espnow\test-bouy-minimal.toit:25:11 ******************************************************************************
theHuanter
theHuanter 03/23/2024 11:34 AM
they are both on channel 2 now
floitsch
floitsch 03/23/2024 11:34 AM
But if your program stops/crashes Jaguar still starts up
theHuanterOPtheHuanter
``` [bouy] DEBUG: Add peer: 30:30:f9:79:1a:e4 on channel 2 [bouy] DEBUG: Send datagram: "#[0x74, 0x65, 0x73, 0x74, 0x2d, 0x64, 0x61, 0x74, 0x61]" *...
floitsch
floitsch 03/23/2024 11:34 AM
Ok. I will have another look on Monday
floitsch
floitsch 03/23/2024 11:35 AM
Can you show me the espnow code for both?
theHuanter
theHuanter 03/23/2024 11:35 AM
could give me a hint on the peer again? I am adding the MACA of the station on both sides! the client and the station, that is correct, right? (thts how I did it beefore)
theHuanter
theHuanter 03/23/2024 11:36 AM
station:
import esp32.espnow import esp32.espnow show Address import log import gpio import .utils import .rgb-led show RGBLED ADDRESS ::= Address #[0x30, 0x30, 0xF9, 0x79, 0x1A, 0xE4] CHANNEL ::= 2 logger ::= log.Logger log.DEBUG_LEVEL log.DefaultTarget --name="station" led := RGBLED main args: led.green logger.debug "MACA: $get-mac-address-str" logger.debug "Start Station" service := espnow.Service.station --key=null --channel=CHANNEL logger.debug "Add peer: $ADDRESS on channel $CHANNEL" service.add-peer ADDRESS while true: print "Waiting for data" datagram := service.receive logger.debug "Received data $datagram.stringify"
theHuanterOPtheHuanter
could give me a hint on the peer again? I am adding the MACA of the station on both sides! the client and the station, that is correct, right? (thts how I did it beefore)
floitsch
floitsch 03/23/2024 11:36 AM
Don't remember, but if that's what you did before then it should still work. Didn't change anything there
theHuanter
theHuanter 03/23/2024 11:36 AM
Client:
import esp32.espnow import esp32.espnow show Address import log import gpio import .utils import .rgb-led show RGBLED ADDRESS ::= Address #[0x30, 0x30, 0xF9, 0x79, 0x1A, 0xE4] CHANNEL ::= 2 logger ::= log.Logger log.DEBUG_LEVEL log.DefaultTarget --name="bouy" led := RGBLED main args: led.blue logger.debug "MACA: $get-mac-address-str" logger.debug "Start Bouy" service := espnow.Service.station --key=null --channel=CHANNEL logger.debug "Add peer: $ADDRESS on channel $CHANNEL" service.add-peer ADDRESS paket := "test-data".to_byte_array logger.debug "Send datagram: \"$paket\"" service.send paket --address=ADDRESS
floitsch
floitsch 03/23/2024 11:37 AM
Shouldn't the address be different for the two?
theHuanter
theHuanter 03/23/2024 11:37 AM
yea thats the part I never get in this ESPNow thing
theHuanter
theHuanter 03/23/2024 11:38 AM
AAHHH
theHuanter
theHuanter 03/23/2024 11:38 AM
man
theHuanter
theHuanter 03/23/2024 11:38 AM
OF COURSE I changed the station now, its the other device(edited)
theHuanter
theHuanter 03/23/2024 11:39 AM
:🙄:
floitsch
floitsch 03/23/2024 11:39 AM
As long as it eventually works :🙂:
theHuanter
theHuanter 03/23/2024 11:40 AM
it does! of course... thats the pain when you work with 2 identical hardware and start swapping there behavior
floitsch
floitsch 03/23/2024 11:40 AM
:🙂:
theHuanter
theHuanter 03/23/2024 11:41 AM
I always used the other one as station
theHuanter
theHuanter 03/23/2024 11:42 AM
pretty bad that you have to hardcode the MACA for that. I might use broadcast later or so. I wanted to try this because it can handle more devices (which is not really needed tbh)
theHuanter
theHuanter 03/23/2024 11:42 AM
okay - man sorry for wasting your time here
theHuanterOPtheHuanter
okay - man sorry for wasting your time here
floitsch
floitsch 03/23/2024 11:50 AM
Np.
90 messages in total