Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Internet of Things Programming with JavaScript
Internet of Things Programming with JavaScript

Internet of Things Programming with JavaScript: Get the best out of Arduino and Raspberry Pi Zero to develop Internet of Things projects using JavaScript

Arrow left icon
Profile Icon Ruben Oliva Ramos
Arrow right icon
S$59.99
Paperback Feb 2017 298 pages 1st Edition
eBook
S$43.19 S$47.99
Paperback
S$59.99
Subscription
Free Trial
Arrow left icon
Profile Icon Ruben Oliva Ramos
Arrow right icon
S$59.99
Paperback Feb 2017 298 pages 1st Edition
eBook
S$43.19 S$47.99
Paperback
S$59.99
Subscription
Free Trial
eBook
S$43.19 S$47.99
Paperback
S$59.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Internet of Things Programming with JavaScript

Chapter 1. Getting Started with Raspberry Pi Zero

Before building several projects for a home security system and the control of domestic appliances by electronically controlled systems, in this chapter, we're going to go into an initial configuration and prepare our Raspberry Pi Zero to work in a network, so you can use it for all the projects we will see in this book.

Before we go through the projects, build our network with the devices, and connect our sensor to the boards, it's important to understand the configuration of the Raspberry Pi. The main idea of this chapter is to explain how to set up your Raspberry Pi Zero; we will cover the following topics:

  • Setting up Raspberry Pi Zero
  • Preparing the SD card
  • Installing the Raspbian operating system
  • Configuring your Raspberry Pi Zero with a serial console cable
  • Accessing the network remotely
  • Accessing via remote desktop
  • Configuring a web server

Setting up Raspberry Pi Zero

The Raspberry Pi is a low-cost board dedicated to purpose projects. Here, we will use a Raspberry Pi Zero board. Take a look at the following link:  https://www.raspberrypi.org/downloads/raspbian/ 

  • Next, insert the micro SD card into your computer using an adapter. (An adapter is usually given with the SD card.)
  • Then download Win32DiskImager from https://www.adafruit.com/products/954:

    Debugging your Raspberry Pi Zero with a serial console cable
  • Testing and accessing the serial COM interface

    Once the driver is installed, we have here the Port COM, which is already installed:

    Tip

    This configuration is for Windows installation; if you have different operating system, you need to do different steps.

    How get the Device Manager screen: On your windows PC, click on the Start icon, go to Control Panel, select System, and then click on Device Manager.

    In the following screenshot, you can see the device manager of the USB serial port:

    Testing and accessing the serial COM interface
  • The default username for the Raspberry Pi Zero is pi, and the password is raspberry:
    Testing and accessing the serial COM interface
  • Connecting to the home network and accessing remotely

    Our Raspberry Pi will be working in a real network, so it needs to be set up to work with all the devices that will be together. For this reason, we need to configure our home network. We will show you how to use the Ethernet adapter and the Wi-Fi plug that can be used in the Raspberry Pi Zero.

    Connecting with an Ethernet adapter

    If you want to connect our Raspberry Pi Zero to the local network, you need to use a USB OTG Host Cable - MicroB OTG male to female from Adafruit. You can find it here: https://www.adafruit.com/products/2992m. This is a hub and can be connected to the Ethernet cable or USB devices.

  • Verify the router configuration, and after both LEDs start blinking, you can see the IP address in your configuration. The DHCP server assigns the IP address to the Raspberry Pi.
  • This is what you will see as your router configuration on your hostname raspberrypi:

    Accessing the Raspberry Pi Zero via SSH

    Use the following command:

    sudo ifconfig -a
    

    We can now see the information about the configuration of the Ethernet controller adapter. Eth0 is the Ethernet adapter:

    Connecting to the Wi-Fi network

    How to install the wireless tools

    Use the following command to configure the wireless network:

    sudo apt-get install wireless-tools
    

    In the following screenshot, we can see the result of the ifconfig command:

    How to install the wireless tools

    Configuring IP address and wireless network

    To have a networking configuration, we need to assign an IP address to our device in order to be involved in the network.

    Enter the following command:

    sudo nano etc/network/interfaces
    
    Configuring IP address and wireless network

    In the following configuration file, called interface, we explain what we need to add to the file so that we can connect our Raspberry Pi Zero to the Wi-Fi network for the Wlan0 connection.

    We start the file configuration; it means the beginning of the file:

    auto lo 
    

    We configure the Ethernet device loopback for the local host and start up the DHCP server:

    iface lo inet loopback 
    iface eth0 inet dhcp 
    

    Allow the configuration of the wlan0 for Wi-Fi connection:

    allow-hotplug wlan0 
    auto wlan0

    We start up the DHCP server for the Wi-Fi connection and input the name of your ssid and the password. We need to type ssid and password parameters of your Wi-Fi network:

    iface wlan0 inet dhcp 
            wpa-ssid "ssid" 
            wpa-psk "password" 
    

    Testing the communication

    We need to test whether the device is responding to the other host. Now, if everything is configured well, we can see the following IP address in the Wi-Fi connection:

    Ping from a computer

    Updating the package repository

    This will upgrade your Pi board by downloading all the latest packages from the official Raspberry Pi repository, so it's a great way to make sure that your board is connected to the Internet. Then, from your computer, type the following: 

    sudo apt-get update
    

    The following screenshot show the Raspberry Pi collecting the packages data:

    Updating the package repository

    Remote Desktop

    In this section, we need the RDP package with the Raspbian Operating System. To do that, first we need to execute the following command:

    sudo apt-get install xrdp 
    

    This command executes and installs the RDP process and updates the package:

    Remote Desktop with Windows

    This is the main window of the Operating System; you have correctly accessed your Raspberry Pi Remote Access with Remote Desktop:

    Remote Desktop with Windows

    Configuring a web server

    There are several web servers available that we can install on your Raspberry Pi. We're going to install the lighttpd web server. Also, we need to install PHP support, which will help us run a website into our Raspberry Pi and have dynamic web pages.

    To install and configure, log in to the Raspberry Pi via the terminal console of PuTTY:

    1. Update the package installer:
              sudo apt-get update
      
    2. Install the lighttpd web server:
              sudo apt-get install lighttpd
      

    Once installed, it will automatically start up as a background service; it will do so each time the Raspberry Pi starts up:

    1. To set up our PHP 5 interface for programming with PHP 5, we need to install the PHP5 module support with the following command; this is necessary to have our server, and it can execute PHP files so that we can make our website:
              sudo apt-get install php5-cgi
      
    2. Now we need to enable the PHP FastCGI module on our web server:
              sudo lighty-enable-mod fastcgi-php
      
    3. For the last step, we have to restart the server with the following command:
              sudo /etc/init.d/lighttpd
      

    In the following screenshot, we show the content of the page that will to appear when we configure the web server and the PHP 5 interface. The web server installs a test placeholder page in the location /var/www. Type the IP address of your Raspberry Pi in the browser, for example, http://192.168.1.105/, and the following screen appears, opening the active page of the configured server:

    Configuring a web server

    Testing the PHP installation

    At this point, we need to test our website with PHP. This can be done by writing a simple PHP script page. If PHP is installed correctly, it will return information about its environment and configuration.

    1. Go to the next folder, where it's the root document:
              cd /var/www/html 
      
      
    2. Create a file called phpinfo.php.

      We use the word nano so that we can get into the file of the system with the privileges and execute the following command:

                  sudo nano phpinfo.php
      
    3. After creating the file, as given in the following screenshot, press CTRL-X, and then save the file:
      Testing the PHP installation

    Summary

    In the first chapter of this book, we looked at how to configure our Raspberry Pi Zero board so we can use it in later chapters. We looked at what components were needed for the Pi, and how to install Raspbian so we can run the software on our board.

    We also installed a web server, which we will be using in some projects of the book. In the following chapter, we are going to dive into how to connect devices to your Raspberry Pi and Arduino boards. We'll also look at the various things we can connect to the Raspberry Pi using GPIO.

    Left arrow icon Right arrow icon
    Download code icon Download Code

    Key benefits

    • • 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

    Description

    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.

    Who is this book 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

    • With this book, you?ll learn about: ? Setting up a centralized web server to connect IoT devices ? Connecting sensors and actuators to devices ? Sending data to web server connected devices ? Understanding Internet of Things using web services and database ? Configuring dashboards using HTML5 and JavaScript ? Controlling and monitoring devices connected from dashboards ? Building apps for smartphones to control different devices
    Estimated delivery fee Deliver to Singapore

    Standard delivery 10 - 13 business days

    S$11.95

    Premium delivery 5 - 8 business days

    S$54.95
    (Includes tracking information)

    Product Details

    Country selected
    Publication date, Length, Edition, Language, ISBN-13
    Publication date : Feb 17, 2017
    Length: 298 pages
    Edition : 1st
    Language : English
    ISBN-13 : 9781785888564
    Category :
    Languages :
    Tools :

    What do you get with Print?

    Product feature icon Instant access to your digital copy whilst your Print order is Shipped
    Product feature icon Paperback book shipped to your preferred address
    Product feature icon Redeem a companion digital copy on all Print orders
    Product feature icon Access this title in our online reader with advanced features
    Product feature icon DRM FREE - Read whenever, wherever and however you want
    Modal Close icon
    Payment Processing...
    tick Completed

    Shipping Address

    Billing Address

    Shipping Methods
    Estimated delivery fee Deliver to Singapore

    Standard delivery 10 - 13 business days

    S$11.95

    Premium delivery 5 - 8 business days

    S$54.95
    (Includes tracking information)

    Product Details

    Publication date : Feb 17, 2017
    Length: 298 pages
    Edition : 1st
    Language : English
    ISBN-13 : 9781785888564
    Category :
    Languages :
    Tools :

    Packt Subscriptions

    See our plans and pricing
    Modal Close icon
    $19.99 billed monthly
    Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
    Feature tick icon Constantly refreshed with 50+ new titles a month
    Feature tick icon Exclusive Early access to books as they're written
    Feature tick icon Solve problems while you work with advanced search and reference features
    Feature tick icon Offline reading on the mobile app
    Feature tick icon Simple pricing, no contract
    $199.99 billed annually
    Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
    Feature tick icon Constantly refreshed with 50+ new titles a month
    Feature tick icon Exclusive Early access to books as they're written
    Feature tick icon Solve problems while you work with advanced search and reference features
    Feature tick icon Offline reading on the mobile app
    Feature tick icon Choose a DRM-free eBook or Video every month to keep
    Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
    Feature tick icon Exclusive print discounts
    $279.99 billed in 18 months
    Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
    Feature tick icon Constantly refreshed with 50+ new titles a month
    Feature tick icon Exclusive Early access to books as they're written
    Feature tick icon Solve problems while you work with advanced search and reference features
    Feature tick icon Offline reading on the mobile app
    Feature tick icon Choose a DRM-free eBook or Video every month to keep
    Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
    Feature tick icon Exclusive print discounts

    Frequently bought together


    Stars icon
    Total S$ 144.97
    Smart Internet of Things Projects
    S$40.99
    Practical Internet of Things with JavaScript
    S$43.99
    Internet of Things Programming with JavaScript
    S$59.99
    Total S$ 144.97 Stars icon

    Table of Contents

    9 Chapters
    1. Getting Started with Raspberry Pi Zero Chevron down icon Chevron up icon
    2. Connecting Things to the Raspberry Pi Zero Chevron down icon Chevron up icon
    3. Connecting Sensors - Measure the Real Things Chevron down icon Chevron up icon
    4. Control-Connected Devices Chevron down icon Chevron up icon
    5. Adding a Webcam to Monitor Your Security System Chevron down icon Chevron up icon
    6. Building a Web Monitor and Controlling Devices from a Dashboard Chevron down icon Chevron up icon
    7. Building a Spy Police with the Internet of Things Dashboard Chevron down icon Chevron up icon
    8. Monitoring and Controlling Your Devices from a Smart Phone Chevron down icon Chevron up icon
    9. Putting It All Together Chevron down icon Chevron up icon
    Get free access to Packt library with over 7500+ books and video courses for 7 days!
    Start Free Trial

    FAQs

    What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

    When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

    What is the delivery time and cost of print book? Chevron down icon Chevron up icon

    Shipping Details

    USA:

    '

    Economy: Delivery to most addresses in the US within 10-15 business days

    Premium: Trackable Delivery to most addresses in the US within 3-8 business days

    UK:

    Economy: Delivery to most addresses in the U.K. within 7-9 business days.
    Shipments are not trackable

    Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
    Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

    EU:

    Premium: Trackable delivery to most EU destinations within 4-9 business days.

    Australia:

    Economy: Can deliver to P. O. Boxes and private residences.
    Trackable service with delivery to addresses in Australia only.
    Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
    Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

    Premium: Delivery to addresses in Australia only
    Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

    India:

    Premium: Delivery to most Indian addresses within 5-6 business days

    Rest of the World:

    Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

    Asia:

    Premium: Delivery to most Asian addresses within 5-9 business days

    Disclaimer:
    All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


    Unfortunately, due to several restrictions, we are unable to ship to the following countries:

    1. Afghanistan
    2. American Samoa
    3. Belarus
    4. Brunei Darussalam
    5. Central African Republic
    6. The Democratic Republic of Congo
    7. Eritrea
    8. Guinea-bissau
    9. Iran
    10. Lebanon
    11. Libiya Arab Jamahriya
    12. Somalia
    13. Sudan
    14. Russian Federation
    15. Syrian Arab Republic
    16. Ukraine
    17. Venezuela
    What is custom duty/charge? Chevron down icon Chevron up icon

    Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

    Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

    The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

    List of EU27 countries: www.gov.uk/eu-eea:

    A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

    How do I know my custom duty charges? Chevron down icon Chevron up icon

    The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

    For example:

    • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
    • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
    How can I cancel my order? Chevron down icon Chevron up icon

    Cancellation Policy for Published Printed Books:

    You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

    Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

    What is your returns and refunds policy? Chevron down icon Chevron up icon

    Return Policy:

    We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

    1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
    2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
    3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
    4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
    5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
    6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

    On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

    What tax is charged? Chevron down icon Chevron up icon

    Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

    What payment methods can I use? Chevron down icon Chevron up icon

    You can pay with the following card types:

    1. Visa Debit
    2. Visa Credit
    3. MasterCard
    4. PayPal
    What is the delivery time and cost of print books? Chevron down icon Chevron up icon

    Shipping Details

    USA:

    '

    Economy: Delivery to most addresses in the US within 10-15 business days

    Premium: Trackable Delivery to most addresses in the US within 3-8 business days

    UK:

    Economy: Delivery to most addresses in the U.K. within 7-9 business days.
    Shipments are not trackable

    Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
    Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

    EU:

    Premium: Trackable delivery to most EU destinations within 4-9 business days.

    Australia:

    Economy: Can deliver to P. O. Boxes and private residences.
    Trackable service with delivery to addresses in Australia only.
    Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
    Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

    Premium: Delivery to addresses in Australia only
    Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

    India:

    Premium: Delivery to most Indian addresses within 5-6 business days

    Rest of the World:

    Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

    Asia:

    Premium: Delivery to most Asian addresses within 5-9 business days

    Disclaimer:
    All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


    Unfortunately, due to several restrictions, we are unable to ship to the following countries:

    1. Afghanistan
    2. American Samoa
    3. Belarus
    4. Brunei Darussalam
    5. Central African Republic
    6. The Democratic Republic of Congo
    7. Eritrea
    8. Guinea-bissau
    9. Iran
    10. Lebanon
    11. Libiya Arab Jamahriya
    12. Somalia
    13. Sudan
    14. Russian Federation
    15. Syrian Arab Republic
    16. Ukraine
    17. Venezuela
    Modal Close icon
    Modal Close icon

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant