main.js
// This handles any received data from the POST request
This handles any received data from the POST request
This handles any received data from the POST request
function handlePOST(req, callback) {
  var data = "";
  req.on("data", function(d) {
    data += d;
  });
  req.on("end", function() {
    var postData = {};
    data.split("&").forEach(function(el) {
      var els = el.split("=");
      postData[els[0]] = decodeURIComponent(els[1]);
    });
    console.log("[handlePOST] ", postData);
    if (postData.s) {
      setTimeout(function() {
        console.log("[handlePOST] httpSrv.close");
        httpSrv.close();
        wifi.stopAP();
        checkWifiStation();
        wifiConnect(postData);
      }, 3000);
    }
     call our callback (to send the HTML result)
    callback();
  });
}
function handlePOST ( req , callback ) { var data = "" ; req . on ( "data" , function ( d ) { data += d ; } ) ; req . on ( "end" , function ( ) { var postData = { } ; data . split ( "&" ) . forEach ( function ( el ) { var els = el . split ( "=" ) ; postData [ els [ 0 ] ] = decodeURIComponent ( els [ 1 ] ) ; } ) ; console . log ( "[handlePOST] " , postData ) ; if ( postData . s ) { setTimeout ( function ( ) { wifi . stopAP ( ) ; checkWifiStation ( ) ; wifiConnect ( postData ) ; } , 3000 ) ; } callback ( ) ; } ) ; }
This handles any received data from the POST request
This handles any received data from the POST request
// All data received from the client, so handle the url encoded data we got // If we used 'close' then the HTTP request would have been closed and we // would be unable to send the result page. // finally our data is in postData // do stuff with it! // //console.log("[handlePOST] httpSrv.close"); //httpSrv.close(); // // // call our callback (to send the HTML result)