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

Controlling a relay from a Raspberry Pi Zero using Restful API and Node.js


In this section, we will show you how to control a relay module connected to an Arduino UNO board, a relay for sending commands from a web browser. Let's do it.

JSON structure

JavaScript Object Notation  (JSON) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language.

JSON is built on two structures:

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.

  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

First, we need to know how to apply the JSON format that we use to describe this structure, as follows:

{"data": "Pin D6 set to 1", "id": "1", "name": "Arduino", "connected": true}

This is the format that we need to follow and make responsive...