• Hi all, I'm making an access portal for client to connect, using code from https://gist.githubusercontent.com/wilbe­rforce/cc6025a535b8a4c7e2910d4ba7845f11/­raw/1e119c8ce11e81b190dc368cf7bfe4f4567b­a82d/gistfile1.txt

    I tried to connect it using my iPhone, sometimes the captive portal doesn't prompt and I have to manually open iOS Chrome and fill in 192.168.4.1 to load the portal page

    moreover, when I fill in the wifi info for the ESP12e, and that the ESP-12e connected to the local wifi network successfully, obtained an IP of 192.168.8.12, then something strange happened: the ESP-12e webserver no longer listen web request from 192.168.4.1, and it now only listen to 192.168.8.12, which means, my iPhone failed to have any new interaction with ESP-12e thr 192.168.4.1, which made the captive portal unresponsive, and therefore the captive portal failed to notify my iPhone that it has obtained an IP of 192.168.8.12 from the local network

    as a result, I have no way to figure the ESP-12e's wifi IP address from its captive portal page :( this is bad

    how to ensure the web server listen to both wifi staton (192.168.8.12) and AP (192.168.4.1) ? thanks in advance

  • How to make a webserver that listen to both the access point network interface and station network interface?

  • Sorry, you are a bit out of luck... The moment you tried to connect, it (Espruino wifi) picked up your home(?) WiFi access point and not the ESP12e's access point. The Web server then just uses this connection and is then listening on that connection... / network.

    ...after all it is not an Apache...

  • Wed 2019.09.10

    Hi @Unreality, although I don't have a definitive answer to your situation, I too had a similar situation two years ago.

    This might provide some insight on what was tried (code ex) and what might be possible:

    'STA or AP mode'

    http://forum.espruino.com/conversations/­300549/

    What version of Espruino has been flashed? Following the above format and adhering to the guidelines at:

    http://forum.espruino.com/conversations/­335009/

    would greatly assist us in assisting you. It is difficult to understand what else has been tried. Code page appears fine. Posting the output would make it easier for others to assist in providing some insight. . . .

    Has the use of 'Fiddler' been attempted to watch the connection attempts, and does that provide any additional detail?

  • I'm pretty sure ESP8266 can function simultaneously in both station and access point mode?
    Indeed I think that may be the default mode. Use wifi.getStatus and check mode. You are looking for sta+ap.

  • Hi,

    the idea behind this code is to integrate a device into an existing wlan by entering the connection data and then stop the access point if connected to that given wlan.

  • Wed 2019.07.10

    'ESP8266 can function simultaneously in both station and access point mode'

    I agree @Ollie, I just checked post #16 in first link (300549) from #4 above. The snippet of code to check that truth is in post #16 also.

  • wifi.getStatus()
    ={
    mode: "sta+ap",
    station: "connected",
    ap: "enabled",
    phy: "11n",
    powersave: "ps-poll",
    savedMode: "sta+ap"
    }

    Espruino 2.0+

  • Sure, you can ran it as both, but you have to make sure the station connects to the desired wifi network / access point / SSID... I may be wrong, but that is how I understand getting a wifi connection and (dhcp driven) ip address.

    To get around (changing) ip address(es), a host name can be given so that browser url input can be book marked...

  • It is probably just a case of modifying the codebase you are using. Here is some code that runs ESP8266 as station and access point.

    let ap_ssid="test";
    let ap_authMode="wpa_wpa2";
    let ap_pwd="testtest";
    
    let st_ssid="ssid";
    let st_pwd="pwd";
    
    let port=8080;
    
    let http = require('http');
    let wifi = require("Wifi");
    
    let startServer = function(port){
      let server = http.createServer(function (req, res) {
          res.writeHead(200, {'Content-Type': 'text/html'});
          res.end(`AP IP: ${wifi.getAPIP().ip}</br>STA IP: ${wifi.getIP().ip}`);
      });
      console.log("server started");
      server.listen(port);
    };
    
    console.log("disconnecting all..");
    wifi.disconnect();
    
    // start ap
    wifi.startAP(ap_ssid,{
      "authMode" : ap_authMode,
      "password" : ap_pwd
    },(err)=>{
      if (!err) {
        console.log("AP started");
      } else {
        console.log("could not start AP"); 
      }
      
      // conect as station
      wifi.connect(st_ssid, {password:st_pwd}, (err) => {
        if (!err){
          console.log("station connected");
          startServer(port);
        }else{
          console.log("could not connect as station");
        }
      });
    });
    
    

    The server/page can be connected to on AP IP: 192.168.4.1 (port 8080) and the router allocated IP of 192.168.1.34 in this example.

    Both the AP IP and station IP are displayed in the page.

    AP IP: 192.168.4.1
    STA IP: 192.168.1.34
    

    Perhaps you can modify from here to suit your needs.

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

http server switching network interface after it connected to a wifi

Posted by Avatar for Unreality @Unreality

Actions