STA or AP mode browser unable to connect to ESP8266-12

Posted on
Page
of 2
/ 2
Next
  • Sun 2017.02.19

    Attempting to connect to an ESP8266-12 using the browser. Always getting error "This site can’t be reached 192.168.1.71 refused to connect"

    Windows 10 Home ver 10.0.14393 Build 14393 laptop running Chrome ver 56.0.2924.87 Firefox ver 51.0.1 WebIDE ver 0.65.9 Espruino ver 1v89

    1v89 Copyright 2016 G.Williams
    

    Have modified the @MaBe example to add wrapper functions to quickly access status detail (see below)

    It appears I am able to connect at the transport layer, just can't gain access at the application layer

    I am able to determine the IP addr using gateway access 192.168.1.254 and locate the device detail beneath Home Network Devices (in this case I.P. is 192.168.1.71)

    I am able to ping the device from the command line

    I am able to connect through the WebIDE calling wrapper funtions in the left panel to display the status as a station i.e. wifi.getAPIP(), wifi.getAPDetails(), wifi.getIP(), wifi.getStatus()

    wifi.getStatus()
    {
      "mode": "sta",
      "station": "connected",
      "ap": "disabled",
      "phy": "11n",
      "powersave": "none",
      "savedMode": "off"
     }
    wifi.getIP()
    {
      "ip": "192.168.1.71",
      "netmask": "255.255.255.0",
      "gw": "192.168.1.254",
      "mac": "5c:cf:7f:88:f4:a0"
     }
    wifi.getAPIP()
    {
      "ip": "0.0.0.0",
      "netmask": "0.0.0.0",
      "gw": "0.0.0.0",
      "mac": "5e:cf:7f:88:f4:a0"
     }
    wifi.getAPDetails()
    {
      "status": "disabled",
      "authMode": "open",
      "hidden": false, "maxConn": 4,
      "ssid": "2WIRE113",
      "password": "",
      "savedSsid": null
     }
    =undefined
    

    Confirmed through network settings not using a proxy server

    Viewed LMHOSTS file to make sure no garbage had been deposited there

    Fiddler also confirms the issued request and captures the resultant error

    [Fiddler] The connection to '192.168.1.71' failed. 
    Error: ConnectionRefused (0x274d). 
    System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it 192.168.1.71:80
    

    Have even attempted adding this snippet in the left panel of the WebIDE

    http.createServer(pageHandler).listen(80­80);
    

    and typing 192.168.1.71 or 192.168.1.71:8080 in the browser address bar

    [Fiddler] The connection to '192.168.1.71' failed. 
    Error: TimedOut (0x274c). 
    System.Net.Sockets.SocketException A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.1.71:80
    

    Any ideas, code snippets, would be appreciated. Thank you Robin

    Edit Sun 2017.02.19

    Even in AP mode a request to 192.168.4.1 results in:

    [Fiddler] The connection to '192.168.4.1' failed. 
    Error: TimedOut (0x274c). 
    System.Net.Sockets.SocketException A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.4.1:80
    
  • Test Telnet. Connect on port 23 from
    IDE. If works, check or post up your http response handler function code - problem most likely in there

  • Please note nothing is listening on port 80 unless you actually start a server listening on that port.

    http://www.espruino.com/Internet

    var http = require("http");
    http.createServer(function (req, res) {
      res.writeHead(200);
      res.end("Hello World");
    }).listen(80);
    
  • @Ollie, thank you for your quick reply - was hoping there was an alternate option above in case "If works" failed ;-)

    Had actually tried that with several IP:Port selections. After I have entered the IP:Port in the 'Connect over TCP Address' edit field and attempt to connect using the Orange button in the upper-left of the WebIDE I get, after a five second wait, a Red 'x' and 'Connection Failed' in lower right hand corner of WebIDE. I'm never able to get a dedicated :23 port to connect.

    The puzzling part, why am I able to ping from the command line? (low-level) but unable to connect from browser, nor the WebIDE via telnet.

    I'm tempted to reflash back to older 1v84 as I did see browser activity one time, but only after I had manually entered ssid and p/w into http.connect() method.

  • Good catch @Wilberforce. I re-checked my listen(8080) and now notice that Fiddler and the browser response are indicating '80' when I actually specified '8080' I have seen '80' as a sort of shorthand for the default http '8080' but not sure if their response now, is an indicator or if we have stumbled upon a clue here.

  • When you wrote this

    http.createServer(pageHandler).listen(80­80);
    

    You're setting up the server to listen on port 8080 i.e http://ip address :8080. It is distinct from port 80. 80 is the default for http - so the only one you don't have to explicitly call in the URI if your server is listening on port 80. Similarly 443 is the default for a server offering SSL/TLS via HTTPS

    You need to contact the server using the port it is listening on - if that is port 80 you can omit it.

    Beyond that you need to have a response handler - your pageHandler function that can output the correct response that a browser can use/understand. The Espruino page on Internet has numerous examples that will help you write the handler function.

    Edit:
    Re Telnet. Once you have Wifi setup and you are connected. If you know the IP address of your board, and set that up on the communications page as x.x.x.x:23, you should be able to establish a Telnet connection - unless the build of Espruino you are using has had Telnet option turned off. Standard builds should have Telnet enabled.

  • Sat 2017.02.25

    Quoting King Arthur had to consult "The Book of Armaments!"

    I have previously used port 8080 as an alternative to no port specified when using http. Bewildered when omitting that and the browser wouldn't connect.

    Confirmed that :8080 is an official alternative for :80

    This is a list of Internet socket port numbers used by protocols of the transport layer of the Internet Protocol Suite for the establishment of host-to-host connectivity

    8080 TCP UDP Alternative port for HTTP. See also ports 80 and 8008. Official

    and also at: https://www.reference.com/technology/por­t-8080-used-ca5f438b749de7de

    Port 8080 is an alternative to port 80 and is used primarily for http traffic. It is named 8080 for its correlation to 80

    What I found during testing is that the wifi.connect() function takes the .listen(8080) port reference literally, requiring the absolute use of 192.168.1.71:8080 in the address field of the browser. It is not recognized as an alternative to http browser requests, if not included.
    e.g. Espruino 1v89 at this testing doesn't follow the spec verbatim, port :8080 can not be assumed an alternative and be resolvable when making a request without a port designation, such as 192.168.1.71

    This subtle difference forces the use of .listen(80) when it is desired that no port is specified.

  • Sat 2017.02.25

    The Espruino page on Internet has numerous examples

    but only when connected as a station. It is also required to be able to connect via code or a command in the WebIDE left panel.

    I'm still struggling with connecting to the ESP8266-12 using a 192.168.4.1 request only from the browser in ap mode. The browser never connects and times out.

    This site can’t be reached

    192.168.4.1 took too long to respond.
    Try:
    Checking the connection
    Checking the proxy and the firewall
    Running Windows Network Diagnostics
    ERR_CONNECTION_TIMED_OUT

    I have been successful at connecting as a station and using wifi.getAPIP(), wifi.getAPDetails(), wifi.getIP(), wifi.getStatus() (see post #1 above) to view the status while viewing responses from the browser when in station mode. A request of 192.168.4.1 is never recognized in ap mode as seen by wifi.getStatus()

    Even tried forcing the IP

    var settings = {ip:'192.168.4.1',gw:'192.168.1.254',net­mask:'255.255.255.0'};
    wifi.setAPIP(settings, setTimeout(function(){http.createServer(­pageHandler).listen(80);},300));
    

    but found function setAPIP() is not available in

    1v89 Copyright 2016 G.Williams
    
    
    Uncaught Error: Function "setAPIP" not found!
     at line 3 col 8
    
    

    and the module I have wont accept a (re)flash of 1v91 http://forum.espruino.com/comments/13481­959/

    I have used Chrome's suggestion to to verify there is no proxy server set and made sure the LAN setting 'Automatically detect settings' is set.

    I have turned off the firewall and disabled anti-virus during testing.

    Currently at a loss for other ideas to test out.

  • Hi @Robin,

    by default the AP is active, use this calls to check

    > Wifi = require('Wifi');
    
    >Wifi.getAPDetails();
    ={
      "status": "enabled",
      "authMode": "open",
      "hidden": false, "maxConn": 4,
      "ssid": "ESP_05C100",
      "password": "",
      "savedSsid": null,
      "stations": [  ]
     }
    
    >Wifi.getAPIP();
    ={
      "ip": "192.168.4.1",
      "netmask": "255.255.255.0",
      "gw": "192.168.4.1",
      "mac": "5e:cf:7f:05:c1:00"
     }
    
    

    A browser connection to 192.168.4.1 will only work if are attached to that AP and when added code like Ollie pointed out above.

  • Hi @MaBe,
    I re-checked and have similar connected (as ap) details as in your inclusion. My browser refuses to connect when using 192.168.4.1 typed into the URL addr field, but is compliant when using the after the fact known 192.168.1.71 IP.

    I've been using your example along with modifications that are at the 'Internet' page that Ollie pointed out. Each time, the browser page only pops up when the browser is pointed to the exact IP (192.168.1.71) that can only be detected after inspection of the 192.168.1.254 router table. I'm attempting to get a page to render at 192.168.4.1 as the IoT device powers up, just as a PC or TV might connect as they power up.

    Am I to understand from your last response, that it is not possible using the current version of Espruino, unless one hard codes the values in script or does a 192.168.1.254 router lookup first to then type in that IP addr into the browser addr field?

    Could the development platform be the issue. I believe Ollie uses a Mac, I'm using Windows 10 What development platform is you PC?

  • I use a Mac too.

    Does ping 192.168.4.1 work for you ?

  • if pings works your pc is connected to ESP AP

    than add this code and connect to http://19.168.4.1:8080 with a browser

    var server = http.createServer(function (req, res) {
          res.writeHead(200);
          res.write('<html><body><H1>Hello World</H1></body></html>');
    });
    
    server.listen(8080);
    
  • Mark, Thank you.

    This is puzzling as I mentioned I was able to ping the device in post #1 above.
    Have used many variants like the one you so graciously provided, and all I get this time with the above snippet and typing 192.168.4.1:8080 into browser is:

    This site can’t be reached

    192.168.4.1 took too long to respond.
    Search Google for 192 168 8080
    ERR_CONNECTION_TIMED_OUT

    Unable to get the router to forget the IP using factory defaults without the possibility of having to make a service call at cost from a device reset.

    This might rule out whether Windows 10 or the router is part of the issue.

    I note that sta is not config:

    wifi.getStatus()
    {
      "mode": "sta+ap",
      "station": "off",
      "ap": "enabled",
      "phy": "11n",
      "powersave": "none",
      "savedMode": "off"
     }
    wifi.getIP()
    {
      "ip": "0.0.0.0",
      "netmask": "0.0.0.0",
      "gw": "0.0.0.0",
      "mac": "5c:cf:7f:88:f4:a0"
     }
    wifi.getAPIP()
    {
      "ip": "192.168.4.1",
      "netmask": "255.255.255.0",
      "gw": "192.168.4.1",
      "mac": "5e:cf:7f:88:f4:a0"
     }
    wifi.getAPDetails()
    {
      "status": "enabled",
      "authMode": "open",
      "hidden": false, "maxConn": 4,
      "ssid": "ESP_88F4A0",
      "password": "",
      "savedSsid": null,
      "stations": [  ]
     }
    
  • post #1 shows a disabled AP, so now way to ping 192.168.4.1 of the ESP AP.

    The station of the ESP is active, so do http://192.168.1.71:8080

  • A http server can run on ESP AP and Station, so no need to start AP if Station is ok for you.

  • Big clue,

    If I use:

    setTimeout(function(){wifi.startAP(C.SSI­D,null,
                                          function(err){
          wifi.connect("2WIRE113", {password: "3321205212"},
    	  function(err){
    	  if(err)console.log(err);
    	  else console.log("connected!");
    	});
        }
                                          );       },700);
    

    such that I have the sta config along with the ap

    wifi.getStatus()
    {
      "mode": "sta+ap",
      "station": "connected",
      "ap": "enabled",
      "phy": "11n",
      "powersave": "none",
      "savedMode": "off"
     }
    wifi.getIP()
    {
      "ip": "192.168.1.71",
      "netmask": "255.255.255.0",
      "gw": "192.168.1.254",
      "mac": "5c:cf:7f:88:f4:a0"
     }
    wifi.getAPIP()
    {
      "ip": "192.168.4.1",
      "netmask": "255.255.255.0",
      "gw": "192.168.4.1",
      "mac": "5e:cf:7f:88:f4:a0"
     }
    wifi.getAPDetails()
    {
      "status": "enabled",
      "authMode": "open",
      "hidden": false, "maxConn": 4,
      "ssid": "ESP_88F4A0",
      "password": "",
      "savedSsid": null,
      "stations": [  ]
     }
    

    now, I'm not able to ping 192.168.4.1 'Request timed out' which explains why the browser won't connect. Can ping 192.168.1.71

    Now the big question, why am I not able to ping?

    No proxy enabled, Firewall off and disabled virus scan. Points to Windows 10 to me.

    Also tried tracert

    C:\Users\Robin>tracert -h 3 192.168.4.1

    Tracing route to 192.168.4.1 over a maximum of 3 hops

    1 2 ms 3 ms 7 ms homeportal [192.168.1.254]
    2 * * * Request timed out.
    3 * * * Request timed out.

    Trace complete.

    Edit Sat 2017.02.25

    Getting closer. For those on a 2Wire ATT UVerse gateway/router - (likely USA)
    https://forums.att.com/t5/AT-T-Internet-­Equipment/Static-IP-Setup-3600-3800-3801­/td-p/3607065

    setup a static IP address of 192.168.4.1

    Now I am able to ping the ap and the sta, but still am unable to access via a browser page.

    Maybe that will be cured with a Windows 10 reboot. Will have to wait for that . . . .

  • Empty stations list means that no station is connected to SSID ESP_88F4A0.

    You can only ping ESP AP 192.168.4.1 if you join SSID ESP_88F4A0

  • Ah, good point Mark,

    Even though I'm getting a 'connected' reply using the snippet above, the stations array is still
    empty [ ] implying what you just indicated. Is there another trick in resolving how to join?
    The snippet above is very similar to the joinWifi() function in the source you created.

    In case our posts crossed, after a static router config I am now able to ping 192.168.4.1 through a cmd window, however browser still wont connect. Is there a ping equiv using the WebIDE?

    Incidentally, thank you for staying responsive while I test. I'm in the CST time zone in the USA, where are you located?

  • http://192.168.1.71:8080 works because your PCs is in the same network as the ESP-Station

    Connect you PC to SSID ESP_88F4A0 and http://192.168.4.1:8080 will work.

    Sorry, but what are you trying to achieve ?

    Edit: located in Germany

  • Amazing this Internet thing, how we are able to have near instant communication while 3000+ mi apart!

    It must be getting late for you so I'll attempt to wrap up.

    Sorry, but what are you trying to achieve ?

    I must brush up on my German as apparently I'm not getting my point across. ;-)
    I tried to explain that in post #10 above, I'll give it another shot.

    I'd like my IoT device to power up in a state where the user need only type 192.168.4.1 into the browser to gain access to a web page that would enable them to enter their ssid and p/w to gain access.

    I attmepted the JoinWifi.js example you created, but could only get a web page to render after I had viewed the router settings 192.168.1.254 and visually acquired the IP in order to enter that into the browser. Trying 192.168.4.1 was futile. It will be near impossible to provide simple connect instructions to users that most likely wont have a clue about router IP settings, nor how to diagnose. Look at the issues I'm having, despite having a bit of a clue as to how to continue.

    My problems were compounded by the fact the IoT device is not connected to the PC via wifi directly. It is actually connecting via the router as indicated by the failed tracrt report. That gave me the clue that maybe my TV configured router may have the default ap mode disabled. No clue why I didn't think of that a week ago despite everyone indicating that 192.168.4.1 is a known ap default.

    Could the stations array [ ] be a feature completed after 1v89 ?

    Still, with all the progress today, still am unable to connect via the browser. Maybe a reboot is now required.

    Thank you for your continuing assistance.
    Robin

  • I'd like my IoT device to power up in a state where the user need only type 192.168.4.1 into the browser to gain access to a web page that would enable them to enter their ssid and p/w to gain access.

    This is only possible if connected to the ESPs AP

    OK - let me try to explain a possible way how to manage this:

    • ESP can not connect to a AP, so ESP offers his own AP and starts a http server to receive a SSID and Password to connect to over simple html form offered by that server.

    • Take a smart phone, connect to the ESP APs and open a browser to connect to 192.168.4.1 and enter SSID and Password. sample page

    • Now ESP tries to connect to that given AP and if connected saves that information and stops his AP and http server

    Is this what you are thinking of ?

  • Simple answer, yes

    Take a smart phone, connect to the ESP APs and open a browser to connect to 192.168.4.1

    What is the process of 'connect to the ESP AP'

    Isn't the browser doing just that when we type 192.168.4.1 into the addr field and hit CR?

    Aren't we doing that task as in the code snippet from post #16 above? e.g. isn't the station
    binding to the ap when we use wifi.connect() and we see "mode": "sta+ap"

  • What is the process of 'connect to the ESP AP'

    iPhone user would choose Settings -> Wifi -> connect to ESP AP

    Sure you can also use the PC and choose Wifi Setting and connect to ESP AP

    Aren't we doing that task as in the code snippet from post #16 above? e.g. isn't the station
    binding to the ap when we use wifi.connect() and we see "mode": "sta+ap"

    No, "192.168.1.0" is the Wifi-Network your PC and ESP Station is connected created by your Wifi-Router.

    "192.168.4.0" is the Wifi-Network created by the ESP when AP is started

    So there are two different Wifi-Networks and you can only join to one at the time with a single Wifi card.

  • Thank you for the detailed explanation.

    you can only join to one at the time

    I'm going to need to read up on networking as my understanding is a bit flawed. This also presents a snafu with my overall project idea, that the end user will need two connections and a bit more than a basic understanding, so the feasibility is now in question.

    Will be taking a break to do that research. Thanks for the exchange this evening, it has been quite enjoyable.

  • Yes - do some research, you will soon figure out that most of the IoT devices use this technic to get integrated into Wifi networks. So keep on going with your idea !

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

STA or AP mode browser unable to connect to ESP8266-12

Posted by Avatar for Robin @Robin

Actions