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:
Start AP
Try to connect to network
Start web server
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.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
i.e.
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.