In this example, additional request parameter will be used. The HW setup is the same as in the previous example.
We want to pass the parameters with one request which would provide us with full control over two LEDs.
First we add additional parameter from our parser:
var parts = req.url.split("/"), // split request url on "/" character
operator1 = parseInt(parts[1],10); // 10 is radix - decimal notation; the base in mathematical numeral systems
// (from 2 to 36)
operator2 = parseInt(parts[2],10); // 10 is radix - decimal notation;
Then we use parameters to control the LEDs:
if (operator1 == 0) {
console.log("Putting led to OFF");
board.digitalWrite(13, board.LOW);
}
if (operator1 == 1) {
console.log("Putting led ON");
board.digitalWrite(13, board.HIGH);
}
if (operator2 == 0) {
console.log("Putting led OFF");
board.digitalWrite(8, board.LOW);
}
if (operator2 == 1) {
console.log("Putting led ON");
board.digitalWrite(8, board.HIGH);
}
For example, the request: http://192.168.254.128:8080/1/1 will turn both LEDs ON.