I am working on python sl4a script to scan wifi networks around me, search for specific SSID by partial match (network name is HOME1234 and script should find all networks which contain HOME), retrieve full network SSID from list by index and connect to it.
Problem is that function Android().wifiGetScanResults() returns variable of type sl4a.result. What i need it to do is to output this as list so algorithm can search trough every element and return its index.
This is algorithm: number=[my_list.index(i) for i in my_list if "HOME" in i]
my_list: List to search trough
HOME: Name of network to search for
This is code
from sl4a import *
from time import *
a=Android()
def find_net():
try:
print("Scanning")
a.wifiLockAcquireFull()
a.wifiStartScan()
sleep(5)
print("Scan completed")
aps=list(a.wifiGetScanResults())
print("Got results")
try:
number=[aps.index(i) for i in aps if "HOM" in i]
except:
print("Nothing found")
return number
except:
print("Scan Failed")
print(find_net())
This code gives this result
Scanning
Scan completed
Got results
Nothing found
Scan Failed
None
#[QPython] Press enter to exit
Please note that this is runned in qpython3 on android
Printing out everything is good! Every sl4a call will return something like
Result(id=1, result=None, error=None), so I ran this:And I got:
Looks like something went wrong when running
wifiStartScan, I can't control it since it's in sl4a. Also, only callingwifiGetScanResultscan still get the results since the documentation saidwifiGetScanResultsreturns the list of access points found during "the most recent" Wifi scan and Android itself performs the scan frequently.The results are a list of dictionaries, each one contains these keys: "capabilities", "frequency", "ssid", "bssid", "level". So what you want may be: