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

Datalogger with MySQL


In the following section, we will build a Datalogger that will record the data temperature and humidity in the server so that we can get data whenever we want and display it in a web page.

Programming the script software

In the following code, we have a script that will communicate with the Arduino board, and it is installed in the server.

You can now either copy the code inside a file called datalogger1.php, or just get the complete code from the folder for this project: 

<?php 
if (isset($_GET["temp"]) && isset($_GET["hum"])) { 
$temperature = intval($_GET["temp"]); 
$humidity = intval($_GET["hum"]); 
$con=mysql_connect("localhost","root","ruben","arduinobd"); 
mysql_select_db('arduinobd',$con); 
      if(mysql_query("INSERT INTO measurements (temperature, humidity) VALUES ('$temperature', '$humidity');")){ 
        echo "Data were saved"; 
      } 
      else { 
      echo "Fail the recorded data"; 
 ...