Accessing the data remotely
In the previous projects of this chapter, we learned how to measure and store data on your Pi. However, in a smart home, the best is to be able to access data remotely, for example, from your smartphone or computer. We will see many similar examples in later chapters of this book, but in this chapter, I just wanted to give you a glimpse of what is possible.
The module we are going to use here is Express, a server framework that is really easy to use with Node.js. Express works by defining routes, which is what will be served to the client if a request is made on a specific URL.
First, we'll import Express and define a main route that will send back the temperature and humidity measurements:
var express = require('express'); var app = express(); app.get('/', function (req, res) { var readout = sensor.read(); answer = 'Temperature: ' + readout.temperature.toFixed(2); answer += ' Humidity: ' + readout.humidity.toFixed...