O'Reilly logo

Internet of Things Programming with JavaScript by Ruben Oliva Ramos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required