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
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
$9.99 $29.99
eBook 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
$9.99 $29.99
eBook 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 eBook?

Product feature icon Instant access to your Digital eBook purchase
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

Billing Address

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

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 : 9781788997065
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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

Billing Address

Product Details

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

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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.