O'Reilly logo

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

Internet of Things Programming with JavaScript

Book Description

Learn the art of bringing the Internet of Things into your projects with the power of JavaScript

About This Book

  • This is a practical guide to help you configure and build a complete distributed IoT system from scratch using JavaScript
  • Utilize the power of Node and HTML5 to develop web services and a centralized web server, enabling high-level communication between connected devices
  • Control all your connected devices from the browser by setting up a common dashboard

Who This Book Is For

This book is for developers who are interested in learning how to communicate with connected devices in JavaScript to set up an IoT system. Some basic knowledge of JavaScript is expected. Hobbyists who want to explore the potential of IoT in JavaScript will also find this book useful.

What You Will Learn

  • Develop the skills to connected devices prepared the field to interact with the devices in a network system Internet of Things
  • Find out how to connect sensors and actuators to the devices
  • Send data to a web server connected devices
  • Understand Internet of things using web services and database
  • Configure a dashboard using HTML5 and JavaScript
  • Control devices connected from a dashboard
  • Monitor different devices from the dashboard
  • Build an app for a smartphone to control different devices

In Detail

The Internet of Things (IoT) is an entirely new platform for developers and engineers, but one thing that remains consistent as we move into this new world, are the programming languages. JavaScript is the most widely used language over the Internet, and with IoT gaining momentum, you will learn how to harness the power of JavaScript to interact with connected devices. This book will teach you how to interact with endpoint devices by developing web services in JavaScript and also set up an interface to control all connected devices.

This book begins with setting up a centralized web server that serves as a hub for all connected devices. The book then progresses further towards building web services to facilitate high-level communication between connected devices. Using Arduino and Raspberry Pi Zero as endpoint devices, the book will show you how devices can communicate with each other, perform a wide range of tasks, and also be controlled from a centralized location using JavaScript. The book ends with creating a hybrid app to control the devices that can be run from a browser or installed on a smartphone.

Style and approach

This book offers step-by-step guidance on how to set up a distributed IoT system using JavaScript.

It will teach you how to interact with endpoint devices by developing web services in JavaScript and also set up an interface for controlling all connected devices.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Internet of Things Programming with JavaScript
    1. Internet of Things Programming with JavaScript
    2. Credits
    3. About the Author
    4. www.packtpub.com
      1. Why subscribe?
    5. Customer Feedback
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    7. 1. Getting Started with Raspberry Pi Zero
      1. Setting up Raspberry Pi Zero
        1. Preparing the SD card
        2. Installing the Raspbian operating system
        3. Debugging your Raspberry Pi Zero with a serial console cable
        4. Testing and accessing the serial COM interface
      2. Connecting to the home network and accessing remotely
        1. Connecting with an Ethernet adapter
        2. Accessing the Raspberry Pi Zero via SSH
        3. Connecting to the Wi-Fi network
      3. How to install the wireless tools
        1. Configuring IP address and wireless network
      4. Testing the communication
        1. Ping from a computer
      5. Updating the package repository
      6. Remote Desktop
        1. Remote Desktop with Windows
      7. Configuring a web server
      8. Testing the PHP installation
      9. Summary
    8. 2. Connecting Things to the Raspberry Pi Zero
      1. Connectting digital input - sensor DS18B20
        1. Hardware requirements
        2. Hardware connections
      2. Configuring the one-wire protocol
        1. Software configuration
        2. Displaying the readings on the screen
      3. Connecting analog inputs using an MCP3008 ADC Converter
      4. Raspberry Pi GPIO header
        1. Reading the data with a Python script
      5. Connecting an RTC
        1. I2C setup
      6. DS3231 module setup
        1. Hardware setup
      7. Testing the RTC
      8. I2C device setup
      9. Putting the real-time clock to final test
      10. Summary
    9. 3. Connecting Sensors - Measure the Real Things
      1. Measuring flow sensor to calculate the volume of water
        1. Hardware connections
        2. Reading the sensor signal
      2. Reading and counting pulses with Arduino
      3. Calculating water flow rate based on the pulses counted
      4. Calculating flow and volume of water:
        1. Displaying the parameters measured on an LCD
      5. Measuring the concentration of gas
        1. Connections with the sensor and Arduino board
      6. Measuring the level of alcohol with a sensor
      7. Detecting fire with a sensor
      8. Measuring the humidity for plants
      9. Measuring the level of water in a recipient
      10. Measuring temperature, humidity, and light and displaying data on an LCD
        1. Hardware and software requirements
        2. Testing sensors
        3. Displaying data on the LCD
      11. Detecting motion with a PIR sensor
        1. PIR sensor interfaced with Arduino
      12. Detecting if the door is open with a reed switch
      13. Detecting who can get in the house with a fingerprint sensor
        1. Hardware configuration:
        2. Save the fingerprint:
        3. Testing the sensor
      14. Summary
    10. 4. Control-Connected Devices
      1. Making a simple web server with Node.js
      2. Controlling a relay from a Raspberry Pi Zero using Restful API and Node.js
        1. JSON structure
        2. Commands with the aREST API
        3. Installing Node.js on your Raspberry Pi Zero
      3. Controlling the relay using aREST commands from a web browser
        1. Configuring the web server
      4. Configuring Node.js on a computer as a web server
        1. Downloading Node.js
        2. Installing Node.js
        3. Configuring web server port 8080 with Node.js
      5. Monitoring temperature, humidity, and light using Node.js with Arduino Wi-Fi
        1. Connecting to the Wi-Fi network
      6. Monitoring temperature, humidity, and light using Node.js with Arduino Ethernet
        1. Code for the application of the Arduino Ethernet shield
        2. Configuring the device in Node.js
      7. Summary
    11. 5. Adding a Webcam to Monitor Your Security System
      1. Interaction between Arduino and Raspberry Pi
        1. Installing Arduino IDE in Raspbian
        2. Remote access to Raspberry Pi
        3. Executing Arduino in a graphical interface
      2. Arduino interface in Raspian
        1. Preparing the interface
        2. Selecting the serial port
        3. Downloading a sketch from the graphical interface
      3. Controlling an output connected to Arduino from Raspberry Pi Zero
      4. Controlling the Arduino board from Python
        1. Hardware connections
      5. Connecting a TTL serial camera to Arduino and saving pictures to a micro SD
      6. Detecting motion with the serial TTL camera
      7. Controlling a snapshot from Raspberry Pi
        1. Code for the function to take a picture
      8. Controlling your camera from a web page
        1. Calling the Python scripts from PHP
        2. Code for Python scripts
      9. Monitoring your USB camera for security in a network
        1. Configuring Arduino YUN
        2. Monitoring from the MJPG-STREAMER server
        3. Monitoring the USB camera from the Raspberry Pi
      10. Summary
    12. 6. Building a Web Monitor and Controlling Devices from a Dashboard
      1. Configuring MySQL database server
        1. Installing MySQL
        2. Installing MySQL driver for PHP
        3. Testing PHP and MySQL
      2. Installing PhpMyAdmin for administrating databases
        1. Configuring the Apache server
        2. Entering to the phpMyAdmin remote panel
        3. Showing the Arduinobd database
        4. Sending data from Arduino and the Ethernet shield to the web server
      3. Datalogger with MySQL
        1. Programming the script software
        2. Testing the connection
      4. Data queries from the database
        1. Software for the scripts
        2. Scripts for specific data to be displayed
        3. Query for recording temperature
      5. Controlling and dimming a LED
        1. Software requirements
        2. Testing the LED
        3. Controlling the LED from an interface
      6. Controlling the speed of a DC motor
      7. Controlling Lights with electrical circuits
        1. Electrical appliances
      8. Other appliances
        1. Control a door lock
        2. Control watering plants
      9. Remote access from anywhere to your Raspberry Pi Zero
        1. How to access our modem to configure it
        2. Configuring Dynamic DNS
        3. Creating an account at No-ip.org
      10. Controlling lights and measuring current consumption
        1. Building the interface to control and monitor
          1. Installing Jade for Node.js
        2. Interface for controlling and monitoring
      11. Controlling and monitoring Arduino, Wi-Fi, and Ethernet shields on connected devices and sensors
        1. Building the code to control and monitor devices from a single interface
        2. Adding the devices to monitor and control
      12. Summary
    13. 7. Building a Spy Police with the Internet of Things Dashboard
      1. Spy microphone that detects noise
        1. Software code
      2. Regulating the current of an AC lamp dimmer
        1. Hardware requirements
        2. Software code
      3. Controlling access with an RFID card
        1. Hardware requirements
        2. Software requirements
        3. Software code
      4. Detecting smoke
        1. Software code
      5. Building an alarm system using the Raspberry Pi Zero
        1. Motion sensor with Raspberry Pi Zero
        2. Software code
        3. The alarm module
        4. Software code
        5. Central interface
        6. Graphical interface
      6. Monitoring the climate from a remote dashboard
        1. Exploring the sensor test
        2. Configuring the remote dashboard (Dweet.io)
      7. Summary
    14. 8. Monitoring and Controlling Your Devices from a Smart Phone
      1. Controlling a relay from a smart phone using APP Inventor
        1. Hardware requirements
        2. Software requirements
      2. Creating our first application
        1. Designing the interface
        2. Communicating APP Inventor with Arduino ethernet shield
        3. Code for APP Inventor
      3. Reading JSON response in Android Studio using ethernet shield
      4. Android application
        1. Java class
        2. Permission of the application
      5. Controlling a DC motor using  an Android Application
        1. Hardware requirements
      6. Controlling outputs from android using your Raspberry Pi Zero
      7. Controlling outputs with Raspberry Pi via Bluetooth
        1. Controlling lights from an Android Application
      8. Summary
    15. 9. Putting It All Together
      1. Integrating the system - development projects
        1. Getting into the details of light sensor
        2. Motion sensor
        3. Automatic light controller
      2. Solar power monitor circuit
      3. Automatic irrigation system with a soil sensor
      4. Arduino water-level controller
      5. Bluetooth based home automation
      6. Controlling access with a matrix keyboard
        1. The keypad
        2. Connecting an LCD screen to display the code
      7. Controlling the door lock with a keypad
        1.  Code to access using the keypad
      8. Integrating the system control with relays and devices
        1. Controlling multiple appliances
        2. The complete system
      9. How to set up the power supplies
        1. Power supply for AC loads
        2. Connecting a relay of 24 DC volts to the Arduino board
      10. Summary