Page 1 of 1

Trying to get SSID of current connected Wifi AP as global variable

Posted: 10 Mar 2020 14:21
by p50kombi
Hi All,

I am trying to get the name of the Wifi network I am currently connected to in a widget on screen.
I use this widget to swich wifi on and off and to show what I am connected to atm.
I found a bit of code on here and adapted it as follows:

Code: Select all

wifiManager=callJavaMethod(getContext(), "android.content.Context", "getSystemService(java.lang.String)", "wifi");
scanResults=callJavaMethod(wifiManager, "android.net.wifi.WifiManager", "getScanResults()");

for(sr in scanResults)
{
  global_network_ssid=getJavaField(sr, "android.net.wifi.ScanResult", "SSID");

}
but that just shows a randon name of one of the networks available as it just picks one at random of all the networks it scans.
I also know I can get the name of the current connected SSID from WifiInfo#getSSID which I found on here:
https://developer.android.com/reference ... i/WifiInfo
but I can't seem to figure out (as I have no coding background) how to adapt above script to write the global_network_ssid as the value of getSSID

Any help would be greatly appreciated, thanks very much...

Re: Trying to get SSID of current connected Wifi AP as global variable

Posted: 10 Mar 2020 14:38
by anuraag
There is an condition WiFi Connected available to get currently connected ssid. It will give you ssid variable.

Re: Trying to get SSID of current connected Wifi AP as global variable

Posted: 10 Mar 2020 14:49
by p50kombi
Thanks, now only thing is which script do I use to let global_wifi_ssid be the variable ssid?

for some reason my brain is having a meltdown.

Re: Trying to get SSID of current connected Wifi AP as global variable

Posted: 10 Mar 2020 14:52
by anuraag
Use script action after above condition. Put

Code: Select all

global_wifi_ssid = ssid

Re: Trying to get SSID of current connected Wifi AP as global variable

Posted: 10 Mar 2020 14:54
by p50kombi
tried that, that just gives the global variable out as ssid for some reason

Re: Trying to get SSID of current connected Wifi AP as global variable

Posted: 10 Mar 2020 14:57
by p50kombi
sorry, gives the value as null, not ssid

Re: Trying to get SSID of current connected Wifi AP as global variable

Posted: 10 Mar 2020 15:07
by p50kombi
sorted it, I used it as a trigger, not as a condition.
using at a condition, now the script works.

Thanks for your help.