O'Reilly logo

Full Stack Web Development with Raspberry Pi 3 by Soham Kamani

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

Understanding how our node process takes readings

In order to integrate our sensor reading code into our server, first. let's understand what is happening under the hood whenever we execute the node script that takes our sensor readings. Let's review the snippet of code that actually called for the sensor readings:

    /*    Section A    */    sensor.read(11, 4, function(err, temperature, humidity) {        /*        Section B        */        //After reading the sensor, we get the temperature     and humidity readings        if (!err) {            //If there is no error, log the readings to the     console            console.log('temp: ' + temperature.toFixed(1) +     '°C, ' +                'humidity: ' + humidity.toFixed(1) + '%'                )        }    });    /*    Section C    */

Immediately, we can see that the sensor.read method is not synchronous; ...

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