Controlling the relay using aREST commands from a web browser
In the next section, we will see how to control a digital output from a web browser using Rest
commands. Let's dive into it, to see more details:
Configuring the web server
You can now either copy the code inside a file called outputcontrol.js, or just get the complete code from the folder for this project and execute it with Node.js. Open the terminal on your Raspberry Pi and type the following:
sudo node output control.js
We define the GPIO of the device importing the commands, by using the following:
var gpio = require('rpi-gpio');
Now we will create our web server using Node.js using the following lines.
We import the require packages that are necessary to run. We declare the libraries using the following:
var express = require('express'); var app = express();
Define the body parser and open the port, in this case, 8099:
var Parser = require('body-parser'); var port = 8099;
Use the body-parser:
app.use...