As the title says... Chat on...

User avatar
By Keith Richardson
#45459 I wish to serve a web page that includes the ESP8266 received signal strength. wifi.ap.getap() should be able to do this for me, but it seems to run asynchronously, i.e. the program continues whilst the function is running (it can take a significant period of time). This code illustrates the problem
Code: Select allfunction Getss()
    Config = {}
    Config.ssid = "myssid"
    Config.channel = 4
    wifi.setmode(wifi.STATION)
    wifi.sta.getap(Config, function(t)
        SigStrength = "No signal"
       for k,v in pairs(t) do
          if k == "myssid" then
             SigStrength = string.sub(v, 3, 5) .. " dbm"
             break
          end
       end
       print("Signal strength: " .. SigStrength)
    end)
end

Getss()
print("fred")

I would expect an output like this
Code: Select all> dofile("SigStrength.lua");
> Signal strength: -29 dbm
fred

But I get
Code: Select all> dofile("SigStrength.lua");
fred
> Signal strength: -29 dbm

In the actual code, I want the function to return the signal strength so that it can be inserted into the HTML, but this problem causes an attempt to insert null data into the string.
Any ideas?