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

User avatar
By AdrianM
#39609 As I understand it, If I set up wifi.setmode(wifi.STATIONAP) the ESP is supposed to be both accessible as an Access Point, and via an IP on the LAN once connected. So with this code as init.lua:
Code: Select alltries=0
ssid="xxxxxx"
pswd="xxxxxx"
--start by setting both station and AP modes
wifi.setmode(wifi.STATIONAP)
wifi.ap.config({ssid="ESP",pwd = "12345678"})
tmr.alarm(0, 100, 1, function(Q) 
    if wifi.ap.getip() == nil then
        tries=tries+1   --wait for AP to come up
    else
        tmr.stop(0)
        print("after "..tries.." AP IP=",wifi.ap.getip())
       
        --now connect to LAN
        wifi.sta.config(ssid,pswd)
        wifi.sta.connect()
        tries=0
        tmr.alarm(0, 100, 1, function(Q) 
            if wifi.sta.getip() == nil then
                tries=tries+1 --wait for LAN to come up
            else
                tmr.stop(0)
                print("after "..tries.." STA IP=",wifi.sta.getip())
                dofile("server.lua") --start serving like...
                                     --   srv=net.createServer(net.TCP)
                                     --   srv:listen(80,function(conn)
            end
        end)
    end
end)

I get the following:
after 0 AP IP= 192.168.1.1 255.255.255.0 192.168.1.1
after 31 STA IP= 192.168.1.173 255.255.255.0 192.168.1.254

While I can connect to ESP AP, and get pages from the server at 192.168.1.1, I can't connect to the server via the LAN on 192.168.1.173

Am I right in thinking this would require another net.createServer(net.TCP) and there can only be one TCP connection?

If so, what might be the use of STATIONAP mode?
User avatar
By Flavio Stutz
#43033 I think you have routing issues there. Your ESP8266 AP has the same network address (192.168.1.0/255.255.255.0) as your "LAN" network. Try to change the AP address to something else, for example, "192.168.10.0"
User avatar
By edwin
#58053 maybe i misunderstand your code but where are giving the login id for your LAN. without those ofcourse there is no connection.

the fact that the " ip's are the same" as i read in the reply isnt the issue as you either lo on on your LAN or on the esp8266 AP (' test' ) and once that connection is established go to 192.168.4.1
User avatar
By marcelstoer
#58054
AdrianM wrote:While I can connect to ESP AP, and get pages from the server at 192.168.1.1, I can't connect to the server via the LAN on 192.168.1.173
Am I right in thinking this would require another net.createServer(net.TCP) and there can only be one TCP connection?


That's correct. The docs don't say but you'd get a descriptive error message if you tried to create a second server.

So, to me the question might be how you could know whether the server socket was bound to the AP (192.168.1.1) or to the station (192.168.1.173). You obviously figured that out but it may not have been clear at first.