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
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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
$19.99 per month
Paperback May 2018 271 pages 1st Edition
eBook
$20.98 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Seneviratne
Arrow right icon
$19.99 per month
Paperback May 2018 271 pages 1st Edition
eBook
$20.98 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$20.98 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788995061
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

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
Hands-On Internet of Things with Blynk
$38.99
Internet of Things Programming Projects
$43.99
Industrial Internet Application Development
$54.99
Total $ 137.97 Stars icon

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 included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.