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 temperature, humidity, and light using Node.js with Arduino Ethernet


In the preceding section, we showed how to monitor our Arduino via Wi-Fi using the CC3000 module; now we will use another important module: Ethernet Shield. The hardware connection of the part is similar to the following image:

Code for the application of the Arduino Ethernet shield

You can now either copy the code inside a file called Monitor_Ethernet.ino, or just get the complete code from the folder for this project; you need to use the Arduino  IDE.

The following are the libraries included in the program:

#include <SPI.h> 
#include <Ethernet.h> 
#include <aREST.h> 
#include <avr/wdt.h> 

Include the library for the DHT11 sensor:

#include "DHT.h" 

We define the pins for the temperature and humidity sensor:

#define DHTPIN 7  
#define DHTTYPE DHT11 

We have the instance of the sensor:

DHT dht(DHTPIN, DHTTYPE); 

We register the MAC address for the device...