I want to execute following code infinitely. However, if two devices are connected, the infinity loop is freeze at second scanning section(The second scanning section means that infinity loop begins second time and scan command is executed). Why this problem appears?
while true do
print("Hi")
s = io.popen("iw wlan0 scan")
s:close()
print("Done")
dis = io.popen("iw wlan0 disconnect")
dis:close()
c = io.popen("iw wlan0 connect Name")
c:close()
print("Goes to Scan")
end
Also, If I type commands in command line by hand(scan -> disconnect -> connect -> scan), then scan print result is repeat from 5 to 6 times automatically at second scanning. (When I execute scan command, the printed result is SYNC - End of SCAN, restore to 20MHz channel 32, Total BSS[02] bImprovedScan ............. Resume for bImprovedScan, SCAN_PENDING ............... and this printed text is repeat from 5 to 6 times). Is this situation is related to this problem?
I don't know what the iw
command does, but using a pipe without reading anything from it and closing it immediately after opening it opens the possibility that the program never executes.
I suggest using os.execute
instead of io.popen
:
while true do
print("Hi")
os.execute("iw wlan0 scan; iw wlan0 disconnect; iw wlan0 connect Name")
print("Goes to Scan")
end