In Chapter 3, Running a Node Server on the Pi, we developed a node server that had APIs to obtain the temperature and humidity. We did not return real data but used a mock hardcoded response to give the impression of real data. In this section, we will be integrating the code that we discussed in Chapter 4, Extracting Information from the GPIO Pins, and including it in our server code so that every time you make a request to the temperature and humidity APIs, you get real, live data.
Let's take the example of the temperature API:
app.get('/temperature', function(req, res) {
res.send('24 °C');
});
Now, we add the code for reading from the sensor inside this API:
app.get('/temperature', function (req, res) {
sensor.read(11, 4, function (err, temperature,
humidity)...