In the previous recipes, we created a simple web server application to read data from a given pin on the board, or to control a given pin. However, this is not convenient, as you always need to change the code every time you change the pin you want to control.
Here, we are going to learn how to create an API so that you can control any pin on the board from a web browser.
You don't need anything specific for this recipe, apart from an up-and-running Galileo board with the IoT image, which is connected to your local network.
In this recipe, we are going to define an API for our Galileo board that will allow us to control any pin on the board, just from a web browser. This is the complete code:
// Required modules var m = require("mraa"); var util = require('util'); var express = require('express'); var app = express(); // API routes app.get('/api/read', function (req, res) { // Get pin var pin = req.query.pin; // Return...