Book Image

Practical Internet of Things with JavaScript

By : Arvind Ravulavaru
Book Image

Practical Internet of Things with JavaScript

By: Arvind Ravulavaru

Overview of this book

In this world of technology upgrades, IoT is currently leading with its promise to make the world a more smarter and efficient place. This book will show you how to build simple IoT solutions that will help you to understand how this technology works. We would not only explore the IoT solution stack, but we will also see how to do it with the world’s most misunderstood programming language - JavaScript. Using Raspberry Pi 3 and JavaScript (ES5/ES6) as the base to build all the projects, you will begin with learning about the fundamentals of IoT and then build a standard framework for developing all the applications covered in this book. You will then move on to build a weather station with temperature, humidity and moisture sensors and further integrate Alexa with it. Further, you will build a smart wearable for understanding the concept of fall detection. You will then extend it with the 'If This Then That' (IFTTT) rules engine to send an email on fall detection. Finally, you will be working with the Raspberry Pi 3 camera module and surveillance with a bit of facial detection using Amazon Rekognition platform. At the end of the book, you will not only be able to build standalone exciting IoT applications but also learn how you can extend your projects to another level.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface

Building a smart socket


In this section, we are going to build a smart socket. The setup is going to be quite similar to what we had in Chapter 4, Smart Agriculture. Create a new folder named chapter5 and copy the contents of the chapter4 folder into it. The chapter4 folder has the code for the smart weather station, and now, we are going to add the required code for smart socket.

The smart socket is a simple electrical socket that can be controlled over the internet. That is, turn on the socket and turn off the socket. We are going to use a mechanical relay to achieve this.

We are going to start off by setting up the relay with the other sensors on the Raspberry Pi. I am going to use one Raspberry Pi to demonstrate the smart weather station as well as the smart socket. You can use two Raspberry Pis as well for this.

We are going to add the appropriate MQTT client code to the API engine; next, update the web, desktop, and mobile app to have a toggle switch to turn on/off the relay.

We are going...