https://toitlang.org/ logo
wifi.scan causes an Assertion_Failed error
# help
t
Has someone used [toit-zygote](https://github.com/kasperl/toit-zygote/tree/main) with
2.0.0-alpha.164
? I am consistently getting an error:
Copy code
[jaguar] INFO: program 2ac875c7-df00-7451-802b-18ee470e6a99 started
INFO: scanning for wifi access points

******************************************************************************
Decoding by `jag`, device has version <2.0.0-alpha.164>
******************************************************************************
ASSERTION_FAILED error.
  0: NetworkServiceClient      <sdk>/system/api/network.toit:116:5
  1: WifiServiceClient         <sdk>/system/api/wifi.toit:33:5
  2: service_                  <sdk>/net/wifi.toit:33:34
  3: run-global-initializer__.<block> <sdk>/core/objects.toit:291:28
  4: run-global-initializer__  <sdk>/core/objects.toit:257:1
  5: scan                      <sdk>/net/wifi.toit:136:14
  6: run                       src/setup.toit:71:20
  7: main.<block>              src/setup.toit:61:53
  8: catch.<block>             <sdk>/core/exceptions.toit:124:10
  9: catch                     <sdk>/core/exceptions.toit:122:1
 10: catch                     <sdk>/core/exceptions.toit:85:10
 11: main                      src/setup.toit:61:3
******************************************************************************

[jaguar] ERROR: program 2ac875c7-df00-7451-802b-18ee470e6a99 stopped - exit code 1
This minimal example is also enough to trigger the error:
Copy code
toit
// wifi_scan.toit
import log
import net.wifi

main:
  log.info "scanning for wifi access points"
  channels := ByteArray 12: it + 1
  print "channels: $(channels)"
  // next line triggers assertion_failed error
  access_points := wifi.scan channels
  print access_points
Test:
Copy code
bash
jag flash
jag run wifi_scan.toit
f
Thanks. We recently enabled asserts by default. Without looking at the code it is likely that there is an assert here that (wrongly?) triggers. We will look at it. In the meantime try to run with
-O2
t
Actually I think this is
jag
interfering with the application.
jag run -D jag.disabled wifi_ap.toit
does not cause the assertion_failed error but the scan fails in any case. The issue with setup.toit appears to be related but different - I will dig further.
f
Interesting. Thanks for investigating. Could also be that the assertion assumes that no wifi connection was established.
t
Copy code
git clone https://github.com/kasperl/toit-zygote.git
cd toit-zygote
jag pkg install
jag flash
jag container install setup src/setup.toit -D jag.disabled -D jag.timeout=2m
jag container install app src/main.toit
jag monitor
results in:
Copy code
[toit] INFO: starting <v2.0.0-alpha.164>
[toit] DEBUG: clearing RTC memory: invalid checksum
[toit] INFO: running on ESP32 - revision 1.0
[jaguar] INFO: container 'app' started
[jaguar] INFO: container 'setup' started with {jag.disabled: true, jag.timeout: 120}
INFO: scanning for wifi access points

******************************************************************************
Decoding by `jag`, device has version <2.0.0-alpha.164>
******************************************************************************
ASSERTION_FAILED error.
  0: NetworkServiceClient      <sdk>/system/api/network.toit:116:5
  1: WifiServiceClient         <sdk>/system/api/wifi.toit:33:5
  2: service_                  <sdk>/net/wifi.toit:33:34
  3: run-global-initializer__.<block> <sdk>/core/objects.toit:291:28
  4: run-global-initializer__  <sdk>/core/objects.toit:257:1
  5: scan                      <sdk>/net/wifi.toit:136:14
  6: run                       src/setup.toit:71:20
  7: main.<block>              src/setup.toit:61:53
  8: catch.<block>             <sdk>/core/exceptions.toit:124:10
  9: catch                     <sdk>/core/exceptions.toit:122:1
 10: catch                     <sdk>/core/exceptions.toit:85:10
 11: main                      src/setup.toit:61:3
******************************************************************************

[jaguar] ERROR: container 'setup' stopped - exit code 1
[wifi] DEBUG: connecting
[wifi] DEBUG: connected
...
Not sure why this would cause the assertion if jag.disabled is true.
k
I'll take a look!
f
The assertion seems to be unrelated to Jaguar.
k
Is it the assertion I already fixed, perhaps?
t
As suggested by @floitsch, adding
-O2
worked:
Copy code
jag container install setup src/setup.toit -D jag.disabled -D jag.timeout=2m -O2
jag container install app src/main.toit -O2
I am using the pre-built envelopes, specifically
v2.0.0-alpha.164/firmware-esp32.envelope
- is this commit merged into this?
k
I don't think we've merged this to the release branch, but I'll check again.
Here are the changes on master that aren't on the 164 branch: https://github.com/toitlang/toit/compare/branch-164...master
The fix (
2a13c0d606e894bf97d1717fc9b7df906db21212
) is on master, but not on the release branch.
We'll have to merge it over or release from master. Thanks for making us aware!
The issue is that the Zygote code is explicitly requesting the wifi service - not just any network service - and that leads to this assertion failure.
The assertion has been fixed; we'll get a fix out in Jaguar tomorrow.
t
Thanks. We do the same STA->AP flow with our IDF code but I didn't quite grasp the service assertion nuances when I dug into the traceback. I must say I am enjoying both writing Toit code and getting rapid responses and fixes for issues!
k
Decided to go for cherry picking the single needed change and to release a small fix in the form of SDK v2.0.0-alpha.165. It is brewing on the build bots. We will release the new SDK and update Jaguar when it is ready.
I will keep you posted!
Just sent out Jaguar v1.43.4 with the updated SDK. Do give it a spin!
t
Just did and it works as expected - thanks! Closing this issue.
3 Views