You are reading a single comment by @Ollie and its replies. Click here to read the full conversation.
  • Here you go. This is your path routing example.

    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).lis­ten(port);
      console.log("Listening on " + wifi.getIP().ip + ":" + port);
    }
    
    // Connect to Wifi
    wifi.stopAP();
    wifi.connect("xxxx", {"password":"xxxx"}, createServer);
    
    
About

Avatar for Ollie @Ollie started