Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Hands-On Internet of Things with Blynk
Hands-On Internet of Things with Blynk

Hands-On Internet of Things with Blynk: Build on the power of Blynk to configure smart devices and build exciting IoT projects

Arrow left icon
Profile Icon Seneviratne
Arrow right icon
$38.99
Paperback May 2018 271 pages 1st Edition
eBook
$9.99 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Seneviratne
Arrow right icon
$38.99
Paperback May 2018 271 pages 1st Edition
eBook
$9.99 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
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
OR
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

Hands-On Internet of Things with Blynk

Building Your First Blynk Application

Now you know how to connect your Raspberry Pi to the Blynk cloud with a simple C++ application running on itself. You also know how to create a project with Blynk app builder running on your smartphone or tablet to connect with your Raspberry Pi through the Blynk cloud.

In this chapter, we will cover the following:

  • Attaching an LED to the Raspberry Pi
  • Building an application with Blynk app builder
  • Using GPIO_BCM pins with the Button widget
  • Using virtual pins with the Button widget
  • Writing C++ code with nano editor
  • Editing the build.sh file
  • Controlling the LED on the Pi by running the Blynk application (the C++ project and the Blynk app)

Controlling an LED

You are now ready to build your first Blynk application that can be used to control an LED attached to the Raspberry Pi from your smartphone or tablet. The application consists of the following components:

  • Blynk app running on your smartphone or tablet
  • C++ project running on Raspberry Pi
  • Blynk cloud

Things you need

Building...

Building the Blynk app

In this example, you will learn how to build a Blynk application to turn an LED on and off.

To start building a project, tap Create New Project in the center of the screen. This will bring you to the Create New Project wizard. You will walk through this wizard step by step.

Follow these steps to complete the Create New Project:

  1. Tap New Project:
Creating a New Project
  1. On the Create New Project page, type LED Controller in the Project Name textbox:
Providing a Project Name
  1. Tap CHOOSE DEVICE to get the available hardware models and tap Raspberry Pi 3 B from the list. After choosing the hardware model, tap OK.
If you have a previous version of Raspberry Pi board, choose the following:
Raspberry Pi 2: Raspberry Pi 2/A+/B+
Raspberry Pi 1 (Rev 1): Raspberry Pi B (Rev 1)
Raspberry Pi 1 (Rev 2): Raspberry Pi A/B (Rev 2)
Selecting the hardware model
  1. Tap...

Adding a Button widget

These steps will show you how to add a Button widget to your project, which is a controller widget that can be used to turn an LED on and off.

The working area of the app builder is referred to as a canvas and has a dotted background with horizontal and vertical guides that allow you to easily arrange and align different types of widgets:

Canvas
  1. Tap anywhere on the canvas or the plus icon on the toolbar to get the Widget Box. The Widget Box lists all the widgets available under different categories to build the application.
  2. On the Widget Box, tap Button under CONTROLLERS:
Button widget under CONTROLLERS
  1. A Button widget will be added onto the canvas:
Button widget
  1. Tap the Button widget to open the Button Settings page.
  2. Tap PIN under OUTPUT and choose Digital followed by GP18 PWM from the list (this is the physical Pin 10/BCM Pin 18/GPIO Pin 18 in...

Running the project

Now, you're ready to run your first Blynk project:

  1. Log in to your Raspberry Pi using the SSH protocol with PuTTY (see Chapter 1, Setting Up a Development Environment, for information on logging in to your Raspberry Pi with PuTTY).
  2. Change to the blynk-library/linux directory by issuing this command:
pi@raspberrypi:~ $cd blynk-library/linux
  1. Run the following command with the auth token associated with your project:
pi@raspberrypi:~/blynk-library/linux $ sudo ./blynk --token=ca7bed1c92214503a65de8e20164994f
  1. The terminal will show an output similar to this:
[0]

___ __ __

/ _ )/ /_ _____ / /__

/ _ / / // / _ / '_/

/____/_/_, /_//_/_/_

/___/ v0.5.0 on Linux

[1] Connecting to blynk-cloud.com:8442

[3490] Ready (ping71ms).

Playing the app

Now, your Raspberry Pi is successfully connected with the Blynk cloud at https://www.blynk.cc/. The following steps show you how to use the app to control the LED attached to GPIO pin 18:

  1. Tap the Play button on the toolbar:
Tapping Play button on the toolbar
  1. This will switch you from edit mode to play mode, where you can interact with the hardware. The play button is replaced with a Stop button that allows you to go back to edit mode:
Application in play mode
  1. You can tap the chip icon (the icon like a microprocessor) to see the device status, whether it is online or offline. The following screenshot show that the Raspberry Pi is online:
Checking device status: Raspberry Pi is online
  1. If your Raspberry Pi is offline, the notification looks as shown in the following screenshot. There are several reasons it can go offline. Some of them are:
    • Lost internet...

Using virtual pins

Now you know how to write the current state of the Button widget to a GPIO pin.

With virtual pins, you can send or receive any type of data between the microcontroller (Raspberry Pi) and the Blynk app. The Blynk app builder provides 128 virtual pins for working with Raspberry Pi. They allow you to interface with sensors, actuators, and libraries. These pins have no physical properties. Some Blynk widgets support virtual pins, some do not.

As an example, you can write the current state of the Button widget to the virtual pin V1 as shown here. Then, you can assign the incoming value from the virtual pin to a variable for further processing:

BLYNK_WRITE(V1)

{

intpinValue = param.asInt(); // assigning value on Virtual Pin (V1) to a variable

// process received value

}

Configuring Button widget with virtual pin

In this section, you will modify the Blynk app, LED Controller, by configuring a virtual pin:

  1. Go to edit mode by tapping the stop icon if you're already in play mode.
  2. Tap the Button widget.
  3. On the Button Settings page, tap GP 18 under OUTPUT. Scroll down and choose Virtual from the left-hand part of the list. Then, scroll down and choose V1 from the right-hand part of the list under PIN. Blynk provides 128 virtual pins for working with Raspberry Pi. Finally, tap OK.

  1. Now, your Button Settings page should look like this:
Button settings for virtual pin
  1. Tap the LEFT arrow on the toolbar. You will see the new button configured with the virtual pin V1:
Button configured with virtual pin V1

Now, you've successfully modified the Button widget, so it can write values to the virtual pin V1.

...

Modifying the main.cpp file

To complete your application, the main.cpp file should also be modified to process the data on the virtual pin. These steps show you how to modify it with the nano editor:

  1. Open the main.cpp file with nano by issuing the following command:
pi@raspberrypi:~/blynk-library/linux $ sudonanomain.cpp
main.cpp opened with nano editor
  1. Before using the WiringPi GPIO library, you need to include its header file in your program as follows:
#include <wiringPi.h>
  1. Scroll down to the file with the arrow keys on your keyboard and add the following code to the setup() function:
void setup()
{
Blynk.begin(auth, serv, port);
pinMode(1, OUTPUT);
}

The pinMode() function allows you to set the mode of a pin to either INPUT, OUTPUT, or PWM_OUTPUT. Note that only WiringPi pin 1 (BCM_GPIO 18) supports PWM output.

  1. Then, add the following lines to the BLYNK_WRITE(V1...

Running the project

Let's see how to run the project:

  1. After building the project, run it with this command:
pi@raspberrypi:~/blynk-library/linux $sudo ./blynk --token=ca7bed1c92214503a65de8e20164994f
  1. You should get an output that looks like this:
Output on console when running the project
  1. Tap the Play button on the toolbar. Now, you can turn on and off the LED by tapping the button. When you tap the button, the console will output the current value on the virtual pin V1.
  2. The following screenshot shows the console output when you tap the Button widget:
Console output while tapping Button widget

Summary

You have learned a lot and built your very first complete Blynk application, which consists of a Blynk hardware and a Blynk app to control an LED attached to the Raspberry Pi over Wi-Fi from a smartphone or a tablet. Now you know how to add the Button widget and configure it to work with the physical pins of the hardware, as well as with virtual pins. You also know how to write code in C++ to process the values on the virtual pin for the Button widget.

In Chapter 3, Using Controller Widgets, you will learn in detail about all the available controller widgets that can be found in the Blynk app builder.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Use Blynk cloud and Blynk server to connect devices
  • Build IoT applications on Android and iOS platforms
  • A practical guide that will show how to connect devices using Blynk and Raspberry Pi 3

Description

Blynk, known as the most user-friendly IoT platform, provides a way to build mobile applications in minutes. With the Blynk drag-n-drop mobile app builder, anyone can build amazing IoT applications with minimal resources and effort, on hardware ranging from prototyping platforms such as Arduino and Raspberry Pi 3 to industrial-grade ESP8266, Intel, Sierra Wireless, Particle, Texas Instruments, and a few others. This book uses Raspberry Pi as the main hardware platform and C/C++ to write sketches to build projects. The first part of this book shows how to set up a development environment with various hardware combinations and required software. Then you will build your first IoT application with Blynk using various hardware combinations and connectivity types such as Ethernet and Wi-Fi. Then you'll use and configure various widgets (control, display, notification, interface, time input, and some advanced widgets) with Blynk App Builder to build applications. Towards the end, you will learn how to connect with and use built-in sensors on Android and iOS mobile devices. Finally you will learn how to build a robot that can be controlled with a Blynk app through the Blynk cloud and personal server. By the end of this book, you will have hands-on experience building IoT applications using Blynk.

Who is this book for?

This book is targeted at any stakeholder working in the IoT sector who wants to understand how Blynk works and build exciting IoT projects. Prior understanding of Raspberry Pi, C/C++, and electronics is a must.

What you will learn

  • • Build devices using Raspberry Pi and various sensors and actuators
  • • Use Blynk cloud to connect and control devices through the Blynk app builder
  • • Connect devices to Blynk cloud and server through Ethernet and Wi-Fi
  • • Make applications using Blynk app builder on Android and iOS platforms
  • • Run Blynk personal server on the Windows, MAC, and Raspberry Pi platforms
Estimated delivery fee Deliver to South Korea

Standard delivery 10 - 13 business days

$12.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 28, 2018
Length: 271 pages
Edition : 1st
Language : English
ISBN-13 : 9781788995061
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
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
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to South Korea

Standard delivery 10 - 13 business days

$12.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

Product Details

Publication date : May 28, 2018
Length: 271 pages
Edition : 1st
Language : English
ISBN-13 : 9781788995061
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 $5 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 $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 137.97
Internet of Things Programming Projects
$43.99
Industrial Internet Application Development
$54.99
Hands-On Internet of Things with Blynk
$38.99
Total $ 137.97 Stars icon
Banner background image

Table of Contents

9 Chapters
Setting Up a Development Environment Chevron down icon Chevron up icon
Building Your First Blynk Application Chevron down icon Chevron up icon
Using Controller Widgets Chevron down icon Chevron up icon
Using Display Widgets Chevron down icon Chevron up icon
Using Notification Widgets Chevron down icon Chevron up icon
Connecting with Sensors on Your Mobile Device Chevron down icon Chevron up icon
Setting Up a Personal Blynk Server Chevron down icon Chevron up icon
Controlling a Robot with Blynk Chevron down icon Chevron up icon
Other Books You May Enjoy 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 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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 customercare@packt.com 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