• Want to invoke http.createServer outside of connecting to a network or creating access point. But I get this error:

    Error: Not connected to the internet

    My code follows this logic in event loop:

    1. Start AP
    2. Try to connect to network
    3. Start web server
    4. Stop AP when successfully connected to a network

    i.e.

    E.on('init', function() {
        APCheck = enableWifiScan();
        startAP();
      // If we try to connect to wifi at the same time we scan, there will be
      // conflicts and scan will return nothing
      setTimeout(function() {
        connectToWifi(); // If successful, stops AP
      }, 2000);
    
      // Create server anyway as we'll allow for control of the MCU through AP
      // if it has not connected to a network
      http.createServer(getPage).listen(80);
    });
    

    The reason for this is I want to be able to have the MCU serve a configuration page which will allow user to configure the network to connect to, making the device portable without hardcoding a network.

    I could probably start the server after access point has been created, add a check to see if a server has been instantiated after connecting to a network, but wondering if there's an easier way.

About

Avatar for pthieu @pthieu started