Book Image

Internet of Things Programming with JavaScript

Book Image

Internet of Things Programming with JavaScript

Overview of this book

The Internet of Things is taking the tech world by storm, and JavaScript is at its helm. This book will get you to grips with this exciting new technology. Where do Node.js, HTML5 and Windows 10 IoT Core come in with JavaScript and IoT? Why Raspberry Pi Zero rather than Arduino? How do you configure and build an IoT network from scratch? All your IoT JavaScript questions are answered in this book.
Table of Contents (15 chapters)
Internet of Things Programming with JavaScript
Credits
About the Author
www.packtpub.com
Customer Feedback
Preface

Monitoring the climate from a remote dashboard


Today, most smart homes are connected to the Internet, and this allows the user to monitor their home. In this section, we are going to learn how to monitor your climate remotely. First, we are simply going to add a sensor to our Raspberry Pi Zero and monitor the measurements from a cloud dashboard. Let's see how it works.

The following image shows the final connections:

Exploring the sensor test

var sensorLib = require('node-dht-sensor'); 
var sensor = { 
    initialize: function () { 
        return sensorLib.initialize(11, 4); 
    }, 
    read: function () { 
        var readout = sensorLib.read(); 
        console.log('Temperature: ' + readout.temperature.toFixed(2) + 'C, ' + 
            'humidity: ' + readout.humidity.toFixed(2) + '%'); 
        setTimeout(function () { 
            sensor.read(); 
        }, 2000); 
    } 
}; 
 
if (sensor.initialize()) { 
...