https://toitlang.org/ logo
wifi
# help
f
Hello, I need to read the wifi rssi dbm of my esp32
f
If you do a
scan
(https://libs.toit.io/net/wifi/library-summary#scan(3%2C0%2C0%2Cpassive%2Cperiod-per-channel-ms ) you should get
AccesPoint
(https://libs.toit.io/net/wifi/class-AccessPoint) objects back which have an rssi field
f
👍
how do i get the index of an element on a list?
f
The
.do
doesn't do that. So either use a
for i := ...
loop, or
list.size.repeat: | i | ...
g
How can I read the rssi of Jaguar's (or Artemis's?) wifi connection? Scan returns a list, but which SSID is Jaguar connected to? I can wifi.open an ap and get the rssi but that requires ssid AND password. Is there a way to network := jaguar.open.wifi ? Do I have to resort to saving a spare copy of wifi credentials? THANK YOU.
f
Good question. I'm not sure it's possible, but I will have a look tomorrow. It might also be possible to read the wifi configuration that Jaguar uses
I think the easiest is to just open a wifi-client without any credentials:
Copy code
import net.wifi

main:
  wifi-client := wifi.open null
  print wifi-client.access-point.ssid
  print wifi-client.signal-strength
I haven't looked too deep, but that either reuses an existing connection, or connects with the saved credentials (which is what Jaguar also uses).
@kasperl is that the best way?
g
Works great! I could never find correct syntax for wifi.open null. RSSI is printing as "1.0" or "0.98461538461538467004" or "0.96923076923076922906". What is that in dB?
f
I had to look at the code myself 🙂 (not 100% sure it was intended to be used this way). The value is basically what we get from the esp-idf slightly modified:
Copy code
/**
  Returns the signal strength of the current access point association
    as a float in the range [0..1].

  Throws an exception if this network isn't currently connected to an
    access point.
  */
  signal-strength -> float:
    info := (client_ as WifiServiceClient).ap-info handle_
    rssi := info[WIFI-SCAN-RSSI_]
    // RSSI is usually in the range [-100..-35].
    rssi = min 65 (max 0 rssi + 100)
    return rssi / 65.0
If you use the
wifi-client.access-point
you can get the integer value from there.
g
It's perfect! Thank you.