Book Image

Full Stack Web Development with Raspberry Pi 3

By : Soham Kamani
Book Image

Full Stack Web Development with Raspberry Pi 3

By: Soham Kamani

Overview of this book

Modern web technology and portable computing together have enabled huge advances in the Internet of Things (IoT) space,as well as in areas such as machine learning and big data. The Raspberry Pi is a very popular portable computer for running full stack web applications. This book will empower you to master this rapidly evolving technology to develop complex web applications and interfaces. This book starts by familiarizing you with the various components that make up the web development stack and that will integrate into your Raspberry Pi-powered web applications. It also introduces the Raspberry Pi computer and teach you how to get up and running with a brand new one. Next, this book introduces you to the different kinds of sensor you’ll use to make your applications; using these skills, you will be able to create full stack web applications and make them available to users via a web interface. Later, this book will also teach you how to build interactive web applications using JavaScript and HTML5 for the visual representation of sensor data. Finally, this book will teach you how to use a SQLite database to store and retrieve sensor data from multiple Raspberry Pi computers. By the end of this book you will be able to create complex full stack web applications on the Raspberry Pi 3 and will have improved your application’s performance and usability.
Table of Contents (13 chapters)
2
Getting Up-and-Running with Web Development on the Raspberry Pi

Reading from the sensor

Now that everything's connected, let's take a reading from our sensor. The DHT11 sensor gives us a 40-bit reading over the time span of 2 seconds. Timing and reading each bit can be a complex task. Fortunately for us, there are libraries present to make our lives easier.

Node.js does not have the required support for the DHT11 sensor, and we need to install the bcm2835 library in order to interface with the sensor.

To install the library, run the following commands:

wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.52.tar.gz
tar -xvzf bcm2835-1.52.tar.gz
cd bcm2835-1.52
./configure
make
sudo make check
sudo make install

Next, go to the ~/sensor-project/server directory and create a new file called obtain-readings.js.

Install the node-dht-sensor library:

npm install --save node-dht-sensor

Populate the contents of the obtain-readings.js file:

   ...