var wifi = require("Wifi");
// All routing in here
function router(req ,res){
var a = url.parse(req.url, true);
res.writeHead(200,{'Content-Type': 'text/plain'});
p = a.path.split("/");
// Test for path formatted to set the temp
if (p.length == 3 && p[1] == "set") {
var temp = parseFloat(p[2]);
res.write("The temp sent to the server was " + temp + "C");
} else {
res.write("The request was not formatted to set the temp");
}
res.end("");
}
// When connected create webserver
function createServer(){
var port = 8080;
require("http").createServer(router).listen(port);
console.log("Listening on " + wifi.getIP().ip + ":" + port);
}
// Connect to Wifi
wifi.stopAP();
wifi.connect("xxxx", {"password":"xxxx"}, createServer);
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.
Here you go. This is your path routing example.