Http-Docs Blynk CC PDF
Http-Docs Blynk CC PDF
Blynk
INTRO
How Blynk Works
Features
What do I need to Blynk?
DOWNLOADS Intro
Blynk Apps for iOS or Android
Blynk Library This guide will help you understand how to get started using Blynk and give a comprehensive overview of all the
features.
GETTING STARTED
Getting Started With The Blynk App If you want to jump straight into playing with Blynk, check out Getting Started.
Raspberry Pi
Blynk App - allows to you create amazing interfaces for your projects using various widgets we provide.
ESP8266 Standalone
NodeMCU Blynk Server - responsible for all the communications between the smartphone and hardware. You can use
Arduino + ESP8266 WiFi with AT commands our Blynk Cloud or run your private Blynk server locally.
It’s open-source, could easily handle thousands of
Particle devices and can even be launched on a Raspberry Pi.
Blynk Libraries - for all the popular hardware platforms - enable communication with the server and process
BLYNK MAIN OPERATIONS all the incoming and outcoming commands.
Virtual Pins
Send data from app to hardware
Now imagine: every time you press a Button in the Blynk app, the message travels to space the Blynk Cloud,
Sending array from Widget
where it magically finds its way to your hardware. It works the same in the opposite direction and everything
Get data from hardware
happens in a blynk of an eye.
Perform requess by Widget
Pushing data from hardware
State syncing
For hardware
For app
Control of multiple devices
You can find example sketches covering basic Blynk Features. They are included in the library. All the sketches
are designed to be easily combined with each other.
At this point you might be thinking: “Ok, I want it. What do I need to get started?” – Just a couple of things,
really:
1. Hardware.
Blynk works over the Internet. This means that the hardware you choose should be able to connect to the
internet. Some of the boards, like Arduino Uno will need an Ethernet or Wi-Fi Shield to communicate, others are
already Internet-enabled: like the ESP8266, Raspberri Pi with WiFi dongle, Particle Photon or SparkFun Blynk
2. A Smartphone.
The Blynk App is a well designed interface builder. It works on both iOS and Android, so no holywars here, ok?
Downloads
Blynk Library
In case you forgot, or don’t know how to install Arduino libraries click here.
Getting Started
Let’s get you started in 5 minutes (reading doesn’t count!). We will switch on an LED connected to your Arduino
using the Blynk App on your smartphone.
We recommend using a real email address because it will simplify things later.
An account is needed to save your projects and have access to them from multiple devices from anywhere. It’s also
a security measure.
You can always set up your own Private Blynk Server and have full control.
After you’ve successfully logged into your account, start by creating a new project.
Select the hardware model you will use. Check out the list of supported hardware!
4. Auth Token
Auth Token is a unique identifier which is needed to connect your hardware to your smartphone. Every new
project you create will have its own Auth Token. You’ll get Auth Token automatically on your email after project
creation. You can also copy it manually. Click on devices section and selected required device :
It’s very convenient to send it over e-mail. Press the e-mail button and the token will be sent to the e-mail address
you used for registration. You can also tap on the Token line and it will be copied to the clipboard.
5. Add a Widget
Your project canvas is empty, let’s add a button to control our LED.
Tap anywhere on the canvas to open the widget box. All the available widgets are located here. Now pick a button.
Widget Box
Widget Settings - Each Widget has it’s own settings. Tap on the widget to get to them.
The most important parameter to set is PIN . The list of pins reflects physical pins defined by your hardware. If
your LED is connected to Digital Pin 8 - then select D8 (D - stands for Digital).
You will get a message saying “Arduino UNO is offline”. We’ll deal with that in the next section.
You should by now have the Blynk Library installed on your computer. If not - click here.
Example sketches will help you get your hardware online quickly and major Blynk features.
Open the example sketch according to the hardware model or shield you are using.
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
}
Auth Token
Upload the sketch to the board and open Serial Terminal. Wait until you see something like this:
Blynk v.X.X.X
Your IP is 192.168.0.11
Connecting...
Blynk connected!
Congrats! You are all set! Now your hardware is connected to the Blynk Cloud!
Blynking
Go back to the Blynk App, push the button and turn the LED on and off! It should be Blynking.
Feel free to experiment and combine different examples together to create your own amazing projects.
For example, to attach an LED to a PWM-enabled Pin on your Arduino, set the slider widget to control the
brightness of an LED. Just use the same steps described above.
Hardware set-ups
If you don’t have any shield and your hardware doesn’t have any connectivity, you can still use Blynk – directly
over USB :
// You could use a spare Hardware Serial on boards that have it (like
Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
void setup()
{
// Debug console
DebugSerial.begin(9600);
void loop()
{
Blynk.run();
Windows: My Documents\Arduino\libraries\Blynk\scripts
Mac User$/Documents/Arduino/libraries/Blynk/scripts
On Windows:
Open cmd.exe
cd C:\blynk-library-0.3.1\blynk-library-0.3.1\scripts
Run blynk-ser.bat file. For example : blynk-ser.bat -c COM4 (where COM4 is port with your
Arduino)
cd User$/Documents/Arduino/libraries/Blynk/scripts
This is what you’ll see in Terminal app on Mac (usbmodem address can be different):
After you press Enter, you should see an output similar to this:
NOTE: Arduino IDE may complain with “programmer is not responding”. You need to terminate script before
uploading new sketch.
Additional materials:
Tutorial: Control Arduino over USB with Blynk app. No shield required. Mac OS)
How to control arduino (Wirelessly) with blynk via USB. Windows
Instructables: Control Arduino with Blynk over USB
Raspberry Pi
blynk-client 715f8cafe95f4a91bae319d0376caa8c
6. To enable Blynk auto restart for Pi, find /etc/rc.local file and add there:
Additional materials:
Instructables: Blynk on Javascript for Raspberry Pi, Intel Edison and others
Instructables: Use DHT11/DHT12 sensors with Raspberry Pi and Blynk
Note: Instead of using Node.js, you can also build a C++ libarry version (same as Arduino, WiringPi-based)
installation:
- Library README for Linux
- Blynk Community Topic: How-To Raspberry Pi
- Video tutorial -
Setting up Blynk and Raspberry Pi:
ESP8266 Standalone
Additional materials:
NodeMCU
Particle
Blynk works with the whole family of Particle products: Core, Photon and Electron
You can scan this QR code from the Blynk App and you’ll get a ready-to-test project for Particle Photon. Just put
your Auth Token into the 01_PARTICLE.INO example.
Additional materials:
Virtual Pins
Blynk can control Digital and Analog I/O Pins on you hardware directly. You don’t even need to write code for it.
It’s great for blinking LEDs, but often it’s just not enough…
We designed Virtual Pins to send any data from your microcontroller to the Blynk App and back.
Virtual Pins can be used to interface with external libraries (Servo, LCD and others) and implement custom
functionality.
Hardware may send data to the Widgets over the Virtual Pin like this:
Blynk.virtualWrite(pin, "abc");
Blynk.virtualWrite(pin, 123);
Blynk.virtualWrite(pin, 12.34);
Blynk.virtualWrite(pin, "hello", 123, 12.34);
You can send any data from Widgets in the app to your hardware.
All Controller Widgets can send data to Virtual Pins on your hardware.
For example, code below shows how to get
values from the Button Widget in the App
When you press a Button, Blynk App sends 1 On the second click - it sends 0
This output can be written to Virtual Pin as an array of values. On the hardware side - you can get any element of
the array [0,1,2…] by using:
Sketch: JoystickTwoAxis
There are two ways of pushing data from your hardware to the Widgets in the app over Virtual Pins.
Using Blynk built-in reading frequency while App is active by setting ‘Reading Frequency’ parameter
to some interval:
BLYNK_READ(V5) // Widget in the app READs Virtal Pin V5 with the certain
frequency
{
// This command writes Arduino's uptime in seconds to Virtual Pin V5
Blynk.virtualWrite(5, millis() / 1000);
}
Sketch: PushDataOnRequest
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
void sendUptime()
{
// This function sends Arduino up time every 1 second to Virtual Pin (V5)
// In the app, Widget's reading frequency should be set to PUSH
// You can send anything with any interval using this construction
// Don't send more that 10 values per second
void loop()
{
Blynk.run(); // all the Blynk magic happens here
timer.run(); // BlynkTimer is working...
}
Sketch: PushData
State syncing
For hardware
If your hardware looses Internet connection or resets, you can restore all the values from Widgets in the Blynk app.
BLYNK_CONNECTED() {
Blynk.syncAll();
}
The Blynk.syncAll() command restores all the Widget’s values based on the last saved values on the
server. All analog and digital pin states will be restored. Every Virtual Pin will perform BLYNK_WRITE event.
WARNING: if pin is empty and wasn’t initialized - hardware will not get any response for those pin during sync.
You can also update a single Virtual Pin value by calling Blynk.syncVirtual(V0) or you can update
several pins with Blynk.syncVirtual(V0, V1, V2, ...) .
For app
If you need to keep your hardware in sync with Widgets’ state even if app is offline use
Blynk.virtualWrite .
Imagine you have a LED Widget connected to the Virtual Pin V1 in the app, and a physical button attached to your
hardware. When you press a physical button, you would expect to see updated state of the LED Widget in the app.
To achieve that you need to send Blynk.virtualWrite(V1, 255) when a physical button gets pressed.
Blynk app has support of multiple devices. That means you can assign any widget to specific device with own auth
token. For example - you may have button on V1 that controls wi-fi bulb A and another button on V1 that controls
wi-fi bulb B. In order to do this you need more than 1 device within your project. To achieve this please go to
project settings and click on “Devices” section :
After above steps, every widget will have one more field “Target” :
Now you need to assign widget to device and after that widget will control only this specific device.
Tags
Tags feature allows you to group multiple devices. Tags are very useful in case you want to control few devices
with 1 widget. For example, imagine a case when you have 3 smart bulbs and you want to turn on all those bulbs
with one single click. You need to assign 3 devices to 1 tag and assign tag to button. That’s it.
Tag widgets also support state syncing. So you can get state of widget from your hardware. However you can’t
update state of such widgets from hardware.
Blynk app has support for online statuses for multiple devices.
In ideal world when device closes tcp connection with some connection.close() - connected server will
get notification regarding closed connection. So you can get instant status update on UI. However in real world
this mostly exceptional situation. In majority of cases there is no easy and instant way to find out that connection
is not active anymore.
That’s why Blynk uses HEARTBEAT mechanism. With this approach hardware periodically sends ping
command with predefined interval (10 seconds by default, BLYNK_HEARTBEAT property). In case hardware
don’t send anything within 10 seconds server waits additional 5 seconds and after that connection assumed to be
broken and closed by server. So on UI you’ll see connection status update only after 15 seconds when it is
actually happened.
You can also change HEARTBEAT interval from hardware side via Blynk.config . In that case
newHeartbeatInterval * 2.3 formula will be applied. So in case you you decided to set
HEARTBEAT interval to 5 seconds. You’ll get notification regarding connection with 11 sec delay in worst
case.
Project Settings
Theme - switch between the Light and Black Blynk Theme (Business accounts have wider choice);
Keep screen always on - allows you to use the Blynk app without going to the sleep mode (usually all
mobile devices do that);
Changing some of the widget properties from hardware side is also supported.
For example, you can change the color of LED widget based on a condition:
NOTE : Changing these parameters work only for widgets attached to Virtual pins (analog/digital pins won’t
work).
Four widget properties are supported - color , label , min , max for all widgets :
color is string in HEX format (in the form: #RRGGBB, where RR (red), GG (green) and BB (blue) are
hexadecimal values between 00 and FF). For example :
min , max - minimum and maximum values for the widget (for example range for the Slider).
This numbers
may be float.
On firmware side, widget objects also support setLabel() and setColor() functions.
Button
Styled Button
onColor / offColor is string in HEX format for ON/OFF colors of the button;
Music Player
Menu
Video Streaming
Step
Don’t put Blynk.virtualWrite and any other Blynk.* command inside void loop() - it
will cause lot’s of outgoing messages to our server and your connection will be terminated;
Avoid using long delays with delay() – it may cause connection breaks;
If you send more than 100 values per second - you may cause Flood Error and your hardware will be
automatically disconnected from the server;
Be careful sending a lot of Blynk.virtualWrite commands as most hardware is not very powerful (like
ESP8266) so it may not handle many requests.
Widgets
Widgets are interface modules. Each of them performs a specific input/ output function when communicating with
the hardware.
Each Widget has it’s own settings. Some of the Widgets (e.g. Bridge) just enable functionality and they don’t have
Pin Selector
This is one of the main parameters you need to set. It defines which pin to control or to read from.
Digital Pins - represent physical Digital IO pins on your hardware. PWM-enabled pins are marked with the ~
symbol
Virtual Pins - have no physical representation. They are used to transfer any data between Blynk App and your
hardware.
Read more about Virtual Pins here.
Data Mapping
In case you want to map incoming values to specific range you may use mapping button:
SPLIT/MERGE
Some of the Widgets can send more than one value. And with this switch you can control how to send them.
SPLIT:
Each of the parameters is sent directly to the Pin on your hardware (e.g D7). You don’t need to write
any code.
NOTE: In this mode you send multiple commands from one widget, which can reduce performance of your
hardware.
Example: If you have a Joystick Widget and it’s set to D3 and D4, it will send 2 commands over the Internet:
digitalWrite(3, value);
digitalWrite(4, value);
MERGE:
When MERGE mode is selected, you are sending just 1 message, consisting of array of values. But
you’ll need to parse it on the hardware.
Example: Add a zeRGBa Widget and set it to MERGE mode. Choose Virtual Pin V1
Decimals
Defines how many decimals you would like to see when moving a Slider.
When “No Fraction” is chosen, slider
will only send integer values with no decimals.
“1 digit” means that values will look like 1.1, 1.2, …, 2.0, etc.
Send On Release
For example, when you move joystick widget, commands are streamed to the hardware, during a single joystick
move you can send dozens of commands. There are use-cases where it’s needed, however creating such a load
may lead to hardware overload and reset. Send On Release is a recommended setting for majority of applications.
This is also a default setting.
Write interval
Similar to “Send on Release” option. However, it allows you to stream values to your hardware within certain
interval. For example, setting write interval to 100 ms means that while you move the slider, only 1 value will be
sent to hardware within 100 ms period.
This option is also used to optimize data traffic flow to your hardware.
Color gradient
When you choose gradient, it affects the color of widget elements based on invoming values. For example: You set
Controllers
Button
Works in push or switch modes. Allows to send ON and OFF (LOW/HIGH) values. Button sends 1 (HIGH) on
press and sends 0 (LOW) on release.
Sketch: BlynkBlink
Slider
Timer
Timer triggers actions at a specified time. Even if smartphone and app is offline. Start time sends 1 (HIGH). Stop
time sends 0 (LOW).
Recent Android version also has improved Timer within Eventor widget.
With Eventor Time Event you can assign
multiple timers on same pin, send any string/value, select days and timezone. It is recommended to use Eventor
over Timer widget.
However Timer widget is still suitable for simple timer events.
NOTE: The timer widget rely on the server time and not your phone time. Sometimes the phone time may not
match the server time.
Sketch: Timer
Settings:
Rotate on Tilt
When it’s ON, Joystck will automatically rotate if you use your smartphone in landscape orientation
- Auto-Return
- When it’s OFF, Joystick handle will not return back to center position. It will stay where you left
it.
Sketch: JoystickTwoAxis
zeRGBa
Settings:
SPLIT:
Each of the parameters is sent directly to the Pin on your hardware (e.g D7). You don’t need
to write any code.
NOTE: In this mode you send multiple commands from one widget, which can reduce performance of your
hardware.
Example: If you have a zeRGBa Widget and it’s set to D1, D2, D3 it will send 3 commands over the Internet:
digitalWrite(1, r);
digitalWrite(2, g);
digitalWrite(3, b);
MERGE:
When MERGE mode is selected, you send 1 message with an array of values inside. You
would need to parse the message on the hardware.
Example: Add a zeRGBa Widget and set it to MERGE mode. Choose Virtual Pin V1.
Step Control
Step Control is used to set granular values with a given step
2 buttons are assigned to 1 pin. One button increments the value, another one decrements it.
Send Step option allows you to send step value to hardware instead of actual value of step widget.
Loop value
option allows you to reset step widget to start value when maximum value is reached.
Displays
Value Display
Displays incoming data.
Sketch: BlynkBlink
Displays incoming data in a formatted wayt. It is a better version of ‘Value Display’ where you can add suffixes
and prefixes on the app side, with no coding on the hardware.
Sketch: BlynkBlink
Formatting options
A simple LED for indication. You need to send 0 in order to turn LED off. And 255 in order to turn LED on. Or
just use
Blynk API as described below:
WidgetLED led2(V2);
led2.setValue(127); //set brightness of LED to 50%.
Sketch: LED
Gauge
Visual display of numeric values.
Sketch: BlynkBlink
Formatting options
LCD
This is a regular 16x2 LCD display made in our secret facility in China.
Commands
lcd.clear();
Formatting options
To use SuperChart widget you would need to push the data from the hardware with the desired interval by using
timers.
Here is a basic example for data pushing.
Interactions:
Tap time ranges at the bottom of the widget to change time ranges
Simply rotate the phone back to portrait mode. Chart should rotate automagically. In full screen view you will see
X (time) and multiple Y scales. Full Screen Mode can be disabled from widget Settings.
Menu Button
Menu button will open additional functions:
Export to CSV
Erase Data on the server
SuperChart Settings:
Chart Title
Datasream Settings
Widget supports up to 4 Datastreams. Press Datastream Settings Icon to open Datastream Settings.
Design:
Choose available types of Chart:
Line
Area
Bar
Binary (anchor LINK to binary)
Color:
Choose solid colors or gradients
1. Virtual Pin
Choose the desired Device and Virtual Pin to read the data from.
2. Tags
SuperChart can aggregate data from multiple devices using built-in aggregation functions. For example, if
you have 10 Temperature sensors sending temperature with the given period, you can plot average value from 10
sensors on the widget.
To use Tags:
Functions available:
SUM, will summarize all incoming values to the specified Virtual Pin across all devices tagged with
the chosen tag
AVG, will plot average value
MED, will find a median value
MIN, will plot minimum value
MAX will plot minimum value
1. Device Selector
If you add Device Selector Widget to your project, you can use it as a source for
SuperChart. In this case, when you change the device in Device Selector, chart will be updated
accordingly
Y-Axis Settings
1. Auto
Data will be auto-scaled based on min and max values of the given time period. This is nice option to start
with.
2. Values
When this mode is selected, Y scale will be set to the values you choose. For example, if your hardware sends
data with values varying from -100 to 100, you can set the chart to this values and data will be rendered
correctly.
You may also want to visualize the data within some specific range. Let’s say incoming data has values in the
range of 0-55, but you would like to see only values in the range 30-50. You can set it up and if values are out of
Y scale you configured, chart will be cropped
1. % of Height
This option allows you to auto-scale incoming data on the widget and position it the way you want.
In this mode, you set up the percentage of widget height on the screen, from 0% to 100%.
If you set it to 0-25%, then this chart will only be rendered on 1/4 of the widget height:
This setting is very valuable for Binary Chart or for visualizing a few datastreams on the same chart in a different
way.
1. Delta
While data stays within the given Delta value, chart will be auto-scaled within this range.
If delta
exceeds the range, chart will be auto-scaled to min/max values of the given period.
Suffix:
Here you can specify a suffix that will be shown during the Tap’n’hold
Decimals
Defines the formatting of the graph value when you Tap’n’hold the graph. Possible options are: #, #.#, #.##, etc.
If it’s set to OFF, then you will see gaps in case there was no data.
You need to specify a FLIP point, which is the point where incoming data will be turned into TRUE or FALSE
state.
For example, you send the data in the range of 0 to 1023 . If you set 512 as a FLIP point, then
everything above 512 (excluding 512) will be recorded as TRUE , any value below 512 (including 512)
will be FALSE .
Another example, if you send 0 and 1 and set 0 as a FLIP point, then 1 will be TRUE , 0 will
be FALSE
State Labels:
Here you can specify how TRUE/FALSE should be shown in Tap’n’Hold mode.
For example, you can set to TRUE to “Equipment ON” label, FALSE to “Equipment OFF”.
Minute granularity - 1h , 6h , 1d ;
Hour granularity - 1w , 1m , 3m ;
This means that minimum chart update interval is 1 minute for 1h , 6h , 1d periods. 1 hour for 1w ,
1m and 3m periods.
As Blynk Cloud is free to use we have a limit on how many data you can store. At the
moment Blynk Cloud accepts 1 message per minute per pin. In case you send your data more frequently your
values will be averaged. For example, in case you send value 10 at 12:12:05 and than again 12 at 12:12:45
as result in chart you’ll see
value 11 for 12:12.
In order to see data in chart you need to use either widgets with “Frequency reading” interval (in that case your app
Terminal
Displays data from your hardware. Allows to send any string to your hardware. Terminal always stores last 25
messages
your hardware had send to Blynk Cloud. This limit may be increased on Local Server with
terminal.strings.pool.size property.
Sketch: Terminal
Video Streaming
Simple widget that allows you to display any live stream. Widget supports RTSP (RP, SDP), HTTP/S progressive
streaming, HTTP/S live streaming. For more info please follow official Android documentation.
At the moment Blynk doesn’t provide streaming servers. So you can either stream directly from camera, use 3-d
party services or host streaming server on own server (on raspberry for example).
Level Display
Blynk.virtualWrite(V1, val);
Every message that hardware sends to server is stored automatically on server. PUSH mode doesn’t require
application to be online or opened.
Notifcations
Twitter widget connects your Twitter account to Blynk and allows you to send Tweets from your hardware.
Example code:
Limitations:
you cant’ send 2 tweets with same message (it’s Twitter policy)
only 1 tweet per 5 seconds is allowed
Sketch: Twitter
Email widget allows you to send email from your hardware to any address.
Example code:
It also contains to field. With this field you may define receiver of email in the app. You may skip to field
when you want to send email to your Blynk app login email:
You can send either text/html or text/plain (some clients don’t support text/html ) email.
You
can change this content type of email in the Mail widget settings.
Maximum allowed email + subject + message length is 120 symbols. However you can increase this
limit if necessary by adding #define BLYNK_MAX_SENDBYTES XXX to you sketch. Where XXX
is desired max length of your email. For example for ESP you can set this to 1200 max length
#define BLYNK_MAX_SENDBYTES 1200 . The #define BLYNK_MAX_SENDBYTES 1200 must
be included before any of the Blynk includes.
Only 1 email per 5 seconds is allowed
In case you are using gmail on the Local Server you are limited with 500 mails per day (by google).
Other providers may have similar
limitations, so please be careful.
User is limited with 100 messages per day in the Blynk Cloud;
Sketch: Email
Push Notifcations
Push Notification widget allows you to send push notification from your hardware to your device. Currently it also
contains 2 additional options:
Notify when hardware offline - you will get push notification in case your hardware went offline.
Offline Ignore Period - defines how long hardware could be offline (after it went offline) before
sending notification. In case period is exceeded - “hardware offline” notification will be send. You will
get no notification in case hardware was reconnected within specified period.
Priority high priority gives more chances that your message will be delivered without any delays.
See detailed explanation here.
WARNING: high priority contributes more to battery drain compared to normal priority messages.
Example code:
You can also use placeholder for device name, that will be replaced on the server with your device name:
Limitations:
Sketch: PushNotification
The library handles all strings as UTF8 Unicode. If you’re facing problems, try to print your message to the Serial
You can increase maximum message length by putting on the top of your sketch (before Blynk includes):
Interface
Tabs
The only purpose of Tabs widget is to extend your project space. You can have up to 4 tabs. Also you can drag
widgets between tabs. Just drag widget on the label of required tab of tabs widget.
Menu
Menu widget allows you to send command to your hardware based on selection you made on UI. Menu
sends
index of element you selected and not label string. Sending index is starts from 1.
It works same way as usual
ComboBox element. You can also set Menu items from hardware side.
switch (param.asInt())
{
case 1: { // Item 1
Serial.println("Item 1 selected");
break;
}
case 2: { // Item 2
Serial.println("Item 2 selected");
break;
}
}
Sketch: Menu
Time Input
Time input widget allows you to select start/stop time, day of week, timezone, sunrise/sunset formatted values
and
send them to your hardware. Supported formats for time now are HH:MM and HH:MM AM/PM .
Hardware will get selected on UI time as seconds of day ( 3600 * hours + 60 * minutes ) for start/stop
time.
Time that widget sends to hardware is user local time.
Selected days indexes:
Monday - 1
Tuesday - 2
...
Saturday - 6
Sundays - 7
You can also change state of widget on UI. See below sketches.
Map
Map widget allows you set points/pins on map from hardware side. This is very useful widget in case you have
You can send a point to map with regular virtual wrtei command:
WidgetMap myMap(V1);
...
int index = 1;
float lat = 51.5074;
float lon = 0.1278;
myMap.location(index, lat, lon, "value");
Table
Table widget comes handy when you need to structure similar data within 1 graphical element. It works as a usual
table.
To select/deselect (make icon green/grey) item in a table by using it’s row id in a table:
Blynk.virtualWrite(V1, "clr");
You can also handle other actions coming from table. For example, use row as a switch button.
BLYNK_WRITE(V1) {
String cmd = param[0].asStr();
if (cmd == "select") {
//row in table was selected.
int rowId = param[1].asInt();
}
if (cmd == "deselect") {
Note: Max number of rows in the table is 100. When you reach the limit, table will work as FIFO (First In First
Out) list.
This limit can be changed by configuring table.rows.pool.size property for Local Server.
Device Selector
Device selector is a powerful widget which allows you to update widgets based on one active device. This widget
is particlularly helpful when you have a fleet of devices with similar functionality.
Imagine you have 4 devices and every device has a Temperature & Humidity sensor connected to it. To display the
data for all 4 devices you would need to add 8 widgets.
With Device Selector, you can use only 2 Widgets which will display Temperature and Humidity based on the
active device chosen in Device Selector.
Now you can change the active device in Device Selector and you will see that Temperature and Humidity values
are reflecting the data updates for the device you just picked.
NOTE: Webhook Widget will not work with Device Selector (yet).
Device Tiles
Device tiles is a powerful widget and very similar to the device selector widget, but with UI.
It allows you to
display 1 pin per device per tile. This widget is particularly helpful when you have a fleet of devices with similar
functionality. So you can group similar devices within one layout (template).
Sensors
Accelerometer
Accelerometer is kind of motion sensors that allows you to detect motion of your smartphone. Useful for
monitoring device movement, such as tilt, shake, rotation, or swing. Conceptually, an acceleration sensor
determines the acceleration that is applied to a device by measuring the forces that are applied to the sensor.
Measured in m/s^2 applied to x , y , z axis.
Barometer/pressure
Barometer/pressure is kind of environment sensors that allows you to measure the ambient air pressure.
BLYNK_WRITE(V1) {
//pressure in mbar
int pressure = param[0].asInt();
}
Gravity
Gravity is kind of motion sensors that allows you to detect motion of your smartphone. Useful for monitoring
device movement, such as tilt, shake, rotation, or swing.
The gravity sensor provides a three dimensional vector indicating the direction and magnitude of gravity.
Measured in m/s^2 of gravity force applied to x , y , z axis.
BLYNK_WRITE(V1) {
//force of gravity applied to axis x
int x = param[0].asFloat();
//force of gravity applied to axis y
int y = param[1].asFloat();
//force of gravity applied to axis y
int z = param[2].asFloat();
}
Humidity
Humidity is kind of environment sensors that allows you to measure ambient relative humidity.
BLYNK_WRITE(V1) {
// humidity in %
int humidity = param.asInt();
}
Light
Light is kind of environment sensors that allows you to measure level of light (measures the ambient light level
(illumination) in lx).
In phones it is used to control screen brightness.
BLYNK_WRITE(V1) {
//light value
int lx = param.asInt();
}
Proximity
Proximity is kind of position sensors that allows you to determine how close the face of a smartphone is to an
object.
Measured in cm - distance from phone face to object. However most of this sensors returns only FAR /
NEAR information.
So return value will be 0/1 . Where 0/LOW is FAR and 1/HIGH is NEAR .
BLYNK_WRITE(V1) {
// distance to object
int proximity = param.asInt();
if (proximity) {
//NEAR
} else {
//FAR
}
}
Temperature
Temperature is kind of environment sensors that allows you to measure ambient air temperature.
Measured in
°C - celcius.
BLYNK_WRITE(V1) {
// temperature in celcius
int celcius = param.asInt();
}
GPS Trigger
GPS trigger widget allows easily trigger events when you arrive to or leave from some destination. This widget
will work in background and periodically will check your coordinates. In case your location is within/out required
BLYNK_WRITE(V1) {
int state = param.asInt();
if (state) {
//You enter destination
} else {
//You leave destination
}
}
More details on how GPS widget works you can read here.
GPS Streaming
Useful for monitoring smartphone location data such as latitude, longitude, altitude and speed (speed could be
often 0
in case smartphone doesn’t support it).
BLYNK_WRITE(V1) {
float latitude = param[0].asFloat();
float longitude = param[1].asFloat();
float altitude = param[2].asFloat();
float speed = param[3].asFloat();
}
BLYNK_WRITE(V1) {
GpsParam gps(param);
// Print 6 decimal places for Lat
Serial.println(gps.getLat(), 7);
Serial.println(gps.getLon(), 7);
Serial.println(gps.getAltitude(), 2);
Serial.println(gps.getSpeed(), 2);
}
Other
Bridge
Bridge can be used for Device-to-Device communication (no app. involved). You can send digital/analog/virtual
write commands from one device to another, knowing it’s auth token.
At the moment Bridge widget is not
required on application side (it is mostly used for indication that we have such feature).
You can use multiple bridges to control multiple devices.
BLYNK_CONNECTED() {
bridge1.setAuthToken("OtherAuthToken"); // Token of the hardware B
}
IMPORTANT: when performing virtualWrite() with Bridge Widget, Device B would need to process
the incoming data from Device A. For example, if you are sending value from Device A to Device B using
bridge.virtualWrite(V5) you would need to use this handler on Device B:
BLYNK_WRITE(V5){
int pinData = param.asInt(); //pinData variable will store value that
came via Bridge
}
Keep in mind that bridge.virtualWrite doesn’t send any value to mobile app. You need to call
Blynk.virtualWrite for that.
Sketch: Bridge
Eventor
Eventor widget allows you to create simple behaviour rules or events. Let’s look at a typical use case: read
temperature from DHT sensor and send push notification when the temperature is over a certain limit:
float t = dht.readTemperature();
if (isnan(t)) {
return;
}
if (t > 40) {
Blynk.notify(String("Temperature is too high: ") + t);
}
With Eventor you don’t need to write this code. All you need is to send the value from the sensor to the server:
float t = dht.readTemperature();
Blynk.virtualWrite(V0, t);
Eventor comes handy when you need to change conditions on the fly without re-uploading new sketch on the
hardware. You can create as many events as you need.
Eventor also could be triggered from the application side.
You just need to assign the widget to the same pin as your Event within Eventor.
Eventor doesn’t constantly sends
events. Let’s consider simple event as above if (temperature > 40) send notification .
When
temperature goes beyond 40 threshold - notification action is triggered. If temperature continues to stay above the
40 threshold no actions will be triggered. But if temperature goes below threshold and then passes it again -
notification will be sent again (there is no 5 sec limit on Eventor notifications).
Eventor also supports Timer events. For example, you can set a pin V1 ON/HIGH at 21:00:00 every Friday.
With Eventor Time Event you can assign multiple timers on same pin, send any string/number, select days and
timezone.
In order to remove created event please use swipe. You can also swipe out last element in the Event itself.
NOTE: The timer widget rely on the server time and not your phone time. Sometimes the phone time may not
match the server time. NOTE: Events are triggered only once when the condition is met. That’s mean chaining of
events is not possible (however, could be enabled for commercials).
NOTE:: Events are triggered only once when the condition is met. Exception:
Let’s consider simple event as
above if (temperature > 40) send notification .
When temperature goes beyond 40 threshold -
notification action is triggered. If temperature continues to stay above the 40 threshold no actions will be
triggered. But if temperature goes below threshold and then passes it again -
notification will be sent again
(there is no 5 sec limit on Eventor notifications).
RTC
Real-time clock allows you to get time from server. You can preselect any timezone on UI to get time on hardware
in required locale. No pin required for RTC widget.
Sketch: RTC
BLE
Widget to enable Bluetooth Low Energy support. At the moment BLE widget requires internet connection in order
to login and load your profile. However this will be fixed soon. Also some Blynk widgets are not supported within
the BLE connection.
Blynk currently supports a handful of different BLE modules. Please check sketches below.
Sketches: BLE
Bluetooth
Widget to enable Bluetooth support. At the moment Bluetooth widget is supported only on Android and requires
internet connection to login and to load your profile. This will be fixed soon. Alsom some Blynk widgets do not
work within the Bluetooth connection.
Blynk currently supports bunch of different modules. Please check sketches below.
Sketches: Bluetooth
Music Player
You can change widget state within the app from hardware side with next commands:
Blynk.virtualWrite(Vx, “play”);
Blynk.virtualWrite(Vx, “stop”);
You can also change widget play/stop state with next code (equivalent to above commands):
Webhook
Webhook is a widget designed to communicate with 3rd party services. With Webhook widget you can send
HTTP(S) requests to any 3rd party service or device that has HTTP(S) API (e.g. Philips Hue bulb). You can
trigger 3-d party service with a single click of a button.
Any write operation from hardware side will trigger Webhook Widget. You can also trigger webhook from
Blynk app when a app widget is assigned to the same pin as Webhook.
For example, when you need to send data from your hardware not only to Blynk, but also to Thingspeak, you
would need to write a long http request code like this (this is just an example, not a full sketch):
WiFiClient client;
if (client.connect("api.thingspeak.com", 80)) {
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKeyThingspeak1 + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
Instead, with Webhook widget you would only need to fill in these fields:
Use standard Blynk placeholders for Pin Value in the body or URL, for example:
https://api.thingspeak.com/update?api_key=xxxxxx&field1=/pin/
["/pin/"]
When you need to send an array of values, you can refer to a specific index of the array value. Blynk Pin can hold
an array of max 10 values:
You can also make GET requests from Blynk Server and get responses directly to your hardware.
For example, to get current weather from a 3rd party Weather service that uses an URL similar to this:
http://api.sunrise-sunset.org/json?lat=33.3823&lng=35.1856&date=2016-10-01 , you
would need to put this URL in Webhook widget and assign it to V0 pin.
BLYNK_WRITE(V0){
String webhookdata = param.asStr();
Serial.println(webhookdata);
}
Now, every time there is a “write” command to V0 pin (e.g. with Blynk.virtualWrite(V0, 1) from
hardware or from app widget assigned to V0 ), BLYNK_WRITE(V0) construction will be triggered and
processed.
NOTE: Usually, 3rd party servers return long responses. You have to increase the maximum allowed message size
your hardware can process. Modify this line in your firmware code:
NOTE: Blynk Cloud has limitation for Webhook Widget - you can only send 1 request per second. This can be
changed on a Local Server by changing webhooks.frequency.user.quota.limit . Be careful with
Webhooks, as many 3rd party services can’t handle 1 req/sec, and you can be banned on some of them. For
example, Thingspeak allows only 1 request per 15 seconds.
NOTE: To avoid spamming, Blynk Webhook feature has another limitation - if your Webhook requests fail 10
times in a row, Webhook Widget will be stopped. To resume it, you would need to open Widget Settings and re-
save it. Failed request is a request that doesn’t return 200 or 302 .
NOTE: Webhook widget may affect Blynk.syncAll() function when a returned response is large.
Reports Widget
Function of Reports is to configure and customize data reports in CSV format. You can choose between one-time
or continuous scheduled reports.
Also, within the Reports you can clear all the data collected by your devices.
In edit mode (when your project is stopped) you define the Datastreams you would like to later be included in
reports.
Reports widget is designed to work with the Device Tiles widget. If you don’t use Device Tiles you can
still select a single device or a group of devices as a source of data for reports.
You have to choose either Device Tiles or single / group of the devices for the report. You can’t combine these 2
options.
Play mode.
After you added source devices and their Datastreams click Play button and click on the Reports button.
Cusomizing Reports.
Data source - select the Datastreams you would like to be included in reports.
Report Frequency - Defines how often reports will be sent. They can be one-time and scheduled.
one-
time - will instantly generate report and send it to the email addresses specified. Click on the right icon to send
it.
At Time will set up a time of the day the report will be sent.
Start / End specifies start and end date
the reports will continue to be sent.
For Weekly Report you can select a day of the week when report should be sent.
For Monthly report you can
choose whether to send report on the first or last day of the month.
Data resolution defines granularity of your reports. Supported granularities are: minute , hourly
and daily .
For example, when you generate daily report with 1 minute granularity you’ll get 24 * 60 *
60
points in your daily report for every selected Datastream.
Group data in reports by - specify the output format of the CSV file(s).
Device you will get 1 CSV file per each device. Each file will contain all of the included Datastreams.
Report you will get 1 CSV file for all your devices and all your Datastreams.
Timezone correction - specify the time zone adjustment if you need to get report date and time adjusted
to a specific time zone
Date and time format - defines the format of the timestamp field of your data. You can select 2018-
06-21 20:16:48 ,
2018-06-21T20:16:48+03:00 or other supported formats.
There is one specific Timestamp format - which reflects the difference between the current time and
midnight, January 1, 1970 UTC measured in milliseconds.
After the report is set up - click on “OK” button at the right upper corner. Your report is ready.
After the report was sent at least once, you can see when the Last report was sent.
Reports will be generated even if your project is not in active (Play) mode. However, inactive projects don’t
generate any data.
NOTE: all reports are encoded in UTF-16. Please, make sure you selected UTF-16 as required “Character set” for
your csv reader.
Sharing
Blynk offers two types of sharing your projects with other people:
Share access to your hardware. Think about giving someone an App for your Project. They can’t modify, but
can control and see what’s there.
Share your Project configuration. Others will get a clone of your project by scanning a given QR link, but
they won’t be able to control your hardware. It’s great for tutorials, instructables, etc.
people you’ve shared your project with can’t modify anything. They can only use it
you can update your app, change the layout, add widgets and it’s immediately synced to everyone
you can revoke access at any moment
How it works:
- you send the QR code to your users (you can email, print, post to social media, do whatever you
want)
- others download Blynk app, scan the QR code and your app opens for them ready to use. They don’t even
need to login or create an account.
That’s it! Now Exit the settings and press PLAY button.
NOTE: Your Project should be active, don’t forget to press Play button.
WARNING: Sharing costs 1000 energy and this energy is not recoverable even you didn’t use sharing at all.
In case you want to share your Project’s set up without giving access to your hardware (for example to make a
tutorial or instructable)- follow the steps:
After the scan, a new Project will be created, all the widgets, settings, layout will be cloned. Another person would
need enough Energy Balance to clone your Project.
Auth Token will be different!. Nobody will get access to your hardware. They just get a copy of the layout and
settings.
Supported Hardware
Platforms
Arduino (https://github.com/blynkkk/blynk-library)
Arduino-like
Blynk Board
ESP8266 (Generic, NodeMCU, Witty Cloud, Huzzah, WeMos D1, Seeed Wio Link, etc.)
ESP32 (WiFi, BLE)
Nordic nRF51/nRF52 - based boards
Teensy 3.2/3.1
Blue Pill (STM32F103C)
Realtek RTL8710 / Ameba via RTLduino
BBC micro:bit
LightBlue Bean , soon
DFRobot Bluno
RedBear Duo (WiFi, BLE)
RedBearLab Blend Micro
RedBearLab BLE Nano (v1 and v2)
Seeed Tiny BLE
Simblee BLE
RFduino BLE
The AirBoard (BLE-Link, RN-XV)
Feather M0 WiFi
Feather 32u4 BLE
Intel Edison
Intel Galileo
Fishino Guppy, Uno, Mega
TinyCircuits TinyDuino (CC3000)
Microduino/mCookie Core, Core+, CoreUSB
Wicked WildFire V2, V3, V4
Digistump Oak
chipKIT Uno32
Alorium XLR8 (FPGA)
LinkIt ONE (WiFi only)
Energia
Texas Instruments
CC3220SF-LaunchXL
CC3200-LaunchXL
Tiva C Connected LaunchPad
Stellaris LM4F120 LaunchPad
MSP430F5529 + CC3100
LaunchPad MSP432
Particle https://github.com/vshymanskyy/blynk-library-spark)
Core
Photon
Electron
RPi
SparkFun RedBoard
RedBear Duo (WiFi & BLE)
Python (https://github.com/vshymanskyy/blynk-library-python)
MicroPython
Python 2
Python 3
Lua (https://github.com/blezek/blynk-esp)
NodeMCU
Ethernet:
WiFi:
HM-10, HC-08
DFRobot BLE-Link module
Microduino/mCookie BLE
RedBearLab BLE Mini
nRF8001-based boards (Adafruit Bluefruit LE, etc.)
HC-05, HC-06, …
GSM/3G:
Made by Community
Problematic Boards
These boards are not supported and do not work out of the box:
- Arduino Tian
Troubleshooting
Connection
1. Check that your hardware, wires, cables and power supply are good quality, not harmed or
damaged, etc.
Use high power USB cables and USB ports.
2. Check your wiring using the examples (TCP/HTTP Client or similar) provided with your shield and
hardware.
Once you understand how to manage connection, it’s much easier to use Blynk.
3. Try running command telnet blynk-cloud.com 80 from your PC, connected to the same network as
your hardware.
You should see something like: Connected to blynk-cloud.com. .
Double-check that you have selected the right example for your connection type and hardware
model.
Our examples come with comments and explanations. Read them carefully.
Check that your Auth Token is valid (copied from the App and doesn’t contain spaces, etc.)
If it doesn’t work, try looking into serial debug prints.
Note: when you have multiple devices connected to your network, they should all have different MAC and IP
addresses. For example, when using 2 Arduino UNO with Ethernet shields, flashing default example to both of
them will cause connection problems. You should use manual ethernet configuration example.
You’re trying to connect to “WPA & WPA2 Enterprise” network (often used in offices), and your
shield does not support this security method
Your WiFi network has a login page that requests entering an access token (often used in
restaurants)
Your WiFi network security disallows connecting alien devices completely (MAC filtering, etc)
There is a firewall running. Default port for hardware connections is 80 (8080 on the Local Server).
Make sure it’s open.
Delay
If you use long delay() or send your hardware to sleep inside of the loop() expect connection drops
and downgraded performance.
DON’T DO THAT:
void loop()
{
...
delay(1000); // this is long delay, that should be avoided
other_long_operation();
...
Blynk.run();
}
SOLUTION:
If you need to perform actions in time intervals - use timers, for example BlynkTimer.
Flood Error
If your code frequently sends a lot of requests to our server, your hardware will be disconnected. Blynk App may
show “Your hardware is offline”
When Blynk.virtualWrite is in the void loop , it generates hundreds of “writes” per second
void loop()
{
SOLUTION:
If you need to perform actions in time intervals - use timers, for example BlynkTimer.
Using delay() will not solve the problem either. It may cause another issue. Use timers!
If sending hundreds of requests is what you need for your product you may increase flood limit on local server and
within Blynk library.
For local server you need to change user.message.quota.limit property within
server.properties file :
For library you need to change BLYNK_MSG_LIMIT property within BlynkConfig.h file :
Enable debug
To enable debug prints on the default Serial, add this on the top of your sketch (it should be the first line
in your
sketch):
Serial.begin(9600);
You can also use spare Hardware serial ports or SoftwareSerial for debug output (you will need an adapter to
connect to it with your PC).
Note: enabling debug mode will slow down your hardware processing speed up to 10 times.
Reset password
On login screen click on “Forgot password?” label and than type your email and Send button.
You’ll get
instruction on your email.
Hardware may select to connect to 443 (9443) or 80 (8080), depending on it’s capabilities.
Connection between
the app and the server is always is done through SSL/TLS, so it is always secured.
Connection between the
hardware and server depends on your hardware capabilities. With the Local Blynk server
connection type between
the hardware and server is not that important for the security as the Local server is
usually placed within the local
network, so attacker can’t intercept traffic between hardware and the server.
In order to gain maximum security you could install Blynk server locally and
restrict access to your network, so
nobody except you could access it. In this case all data is stored locally within
your network and not send via
Internet.
In case of Local Blynk Server there is also no need to protect connection between your hardware and Local Blynk
Server.
This is true for Ethernet connection and partially true for Wi-Fi connection. In case of Wi-Fi you have to
use at least WPA, WPA2 (Wi-Fi Protected Access) Wi-Fi type in order to protect wireless traffic.
WPA and WPA2 offer a very robust encryption that is likely to protect all data travelling over the air—given that a
strong enough password is used. Even if your data is plain TCP/IP, another user won’t be able to decipher
captured packets. Still, make sure that your password is strong enough, otherwise the only limiting factor for an
attacker is time.
Most platforms are not capable to handle SSL, so they connect to 80.
However, our gateway script can be used to
add SSL security layer to communication.
This will forward all hardware connections from 9443 port to the server via SSL gateway.
You can run this script
on your Raspberry Pi, desktop computer, or even directly on your router!
Note: when using your own server, you should overwrite the bundled server.crt certificate, or specify it to the
script using --cert switch:
Flag -f SSL is enabled by default for USB communication so you don’t have to explicit declare it.
If you want to skip SSL, and connect to TCP, you can also do that:
./blynk-ser.sh -t TCP
OTA
Blynk also supports over the air updates for - ESP8266, NodeMCU and SparkFun Blynk boards. OTA supported
only for the private servers and for the paid customers for now.
Flow
BLYNK_WRITE(InternalPinOTA) {
//url to get firmware from. This is HTTP url
//http://localhost:8080/static/ota/FUp_2441873656843727242_upload.bin
overTheAirURL = param.asString();
...
}
Update for all devices will be triggered only when they are connected to the cloud. You need to remove the token
part for that.
In that case, OTA will be triggered right after device connected to the server. In case device is online firmware
update will be initiated only when device will be connected again.
In that case firmware update will be triggered for all devices of specified user.
In that case firmware update will be triggered for all devices of specified user within specified project.
Stop OTA
In order to make firmware in Arduino IDE - go to menu: Sketch -> Export compiled Binary.
NOTE: ESP8266 right now takes firmware only via HTTP. And not HTTPS.
Better security. You are the only one who knows about the server. You can setup security policies
tied to your specific needs (MAC, IPs, login names, etc). You can also make it accessible only within
your private network.
Better stability. No need to rely on 3rd party Cloud solution. You have the full control.
Lower latency. Server is as close to you as it could be.
Maximum privacy. All data is stored locally and is not shared with anyone.
Blynk Firmware
Confguration
Blynk.begin()
Blynk.begin(auth, ...);
It has multiple parameters for different hardware models and it also depends on the type of connection. Follow the
example sketches for your specific hardware model.
If your shield/connection type is not supported yet - you can implement it by yourself. Here are some examples.
config() allows you to manage network connection. You can set up your connection type (WiFi, Ethernet,
…) by yourself, and then call:
or just
Blynk.config(auth);
NOTE: After Blynk.config(...) is called, your hardware is not yet connected to the server. It will try
to connect while until it hits first instance of Blynk.run() or Blynk.connect() routine.
To skip connecting to the server or to disconnect manually, call Blynk.disconnect() after configuration.
Blynk.connectWiFi(ssid, pass);
Connection management
Blynk.connect()
This functions will continue trying to connect to Blynk server. Returns true when connected, false if
timeout have been reached.
Default timeout is 30 seconds.
Blynk.disconnect()
Disconnects hardware from Blynk server:
Blynk.disconnect();
Blynk.connected()
Returns true when hardware is connected to Blynk Server, false if there is no active connection to
Blynk server.
Blynk.run()
This function should be called frequently to process incoming commands and perform housekeeping of Blynk
This command can be initiated it in other places of your code unless you run out of heap memory (in the cascaded
functions with local memory).
For example, it is not recommended to call Blynk.run() inside of the BLYNK_READ and
BLYNK_WRITE functions on low-RAM devices.
digitalRead
digitalWrite
analogRead
analogWrite (PWM or Analog signal depending on the platform)
No need to write code for simple things like LED, Relay control and analog sensors. Just choose a corresponding
Pin in Blynk app and control it directly with no additional code
Virtual Pins is a way to exchange any data between your hardware and Blynk app. Think about Virtual Pins as
channels for sending any data. Make sure you differentiate Virtual Pins from physical GPIO
pins on your
hardware. Virtual Pins have no physical representation.
Virtual Pins are commonly used to interface with other libraries (Servo, LCD and others) and implement custom
logic. The device can send data to the App using Blynk.virtualWrite(pin, value) and receive data
from the App using BLYNK_WRITE(vPIN) . Read below
All Virtual Pin values are always sent as Strings and there are no practical limits on the data that can be sent.
However, there are certian limitations on the hardware side when dealing with numbers. For example, the integer
on Arduino is 16-bit, allowing range -32768 to 32767.
param.asInt();
param.asFloat();
param.asDouble();
param.asStr();
You can also get the RAW data from the param buffer:
param.getBuffer()
param.getLength()
Blynk.virtualWrite(vPin, value)
NOTE: Use BlynkTimer when you use this command to send data. Otherwise your hardware will be
disconnected from the server
// Send integer
Blynk.virtualWrite(pin, 123);
// Send float
Blynk.virtualWrite(pin, 12.34);
Note: For virtual pins with numbers > 127, the V128 syntax is not available.
Please use plain virtual pin number, for example:
Blynk.virtualWrite(128, "abc");
BlynkTimer
It’s important to send data in intervals and keep the void loop() as clean as possible.
BlynkTimer allows you to send data periodically with given intervals not interfering with Blynk library
routines Blynk Timer inherits SimpleTimer Library, a well known and widely used library to time multiple
events on hardware.
BlynkTimer is included in Blynk library by default and there is no need to install
SimpleTimer separately or include SimpleTimer.h
Please also remember that a single BlynkTimer can schedule many timers, so most probably you need only
one instance of BlynkTimer in your sketch.
BLYNK_WRITE(vPIN)
BLYNK_WRITE is a function called every time device gets an update of Virtual Pin value from the server (or
app):
BLYNK_WRITE(V0)
{
int value = param.asInt(); // Get value as integer
Note: For virtual pins with numbers > 127, please use BLYNK_WRITE_DEFAULT() API
BLYNK_READ(vPIN)
BLYNK_READ is function called when device is requested to send it’s current value of Virtual Pin to the server.
Normally, this function should contain Blynk.virtualWrite call(s).
BLYNK_READ(V0)
{
Blynk.virtualWrite(V0, newValue);
}
Note: For virtual pins with numbers > 127, please use BLYNK_READ_DEFAULT() API
BLYNK_WRITE_DEFAULT()
Redefines the handler for all pins that are not covered by custom BLYNK_WRITE functions.
BLYNK_WRITE_DEFAULT()
{
int pin = request.pin; // Which exactly pin is handled?
int value = param.asInt(); // Use param as usual.
}
BLYNK_READ_DEFAULT()
Redefines the handler for all pins that are not covered by custom BLYNK_READ functions.
BLYNK_READ_DEFAULT()
{
int pin = request.pin; // Which exactly pin is handled?
Blynk.virtualWrite(pin, newValue);
}
BLYNK_CONNECTED()
Use this function when you need to run certain routine when hardware connects to Blynk Cloud or private server.
It’s common to call sync functions inside of this function.
BLYNK_CONNECTED() {
// Your code here
}
BLYNK_APP_CONNECTED()
This function is called every time Blynk app client connects to Blynk server.
BLYNK_APP_CONNECTED() {
// Your code goes here
}
Example
BLYNK_APP_DISCONNECTED()
This function is called every time the Blynk app disconnects from Blynk Cloud or private server.
BLYNK_APP_DISCONNECTED() {
// Your code here
}
Example
Blynk.syncAll()
Requests all stored on the server latest values for all widgets. All analog/digital/virtual pin values and states will be
set to the latest stored value. Every virtual pin will generate BLYNK_WRITE() event.
Blynk.syncVirtual(vPin)
This command updates individual Virtual Pin to the latest stored value on the server. When it’s used, a
corresponding BLYNK_WRITE handler is called.
Blynk.syncVirtual(V0);
Debugging
#defne BLYNK_PRINT
#defne BLYNK_DEBUG
To enable debug prints on the default Serial port add on the top of your sketch IMPORTANT: This should be
the first line in your code:
#define BLYNK_PRINT Serial // Defines the object that is used for printing
#define BLYNK_DEBUG // Optional, this enables more detailed prints
Serial.begin(9600);
You can also use spare Hardware serial ports or SoftwareSerial for debug output (you will need an adapter to
connect to it with your PC).
WARNING: Enabling BLYNK_DEBUG will slowdown your hardware processing speed up to 10 times!
BLYNK_LOG()
When BLYNK_PRINT is defined, you can use BLYNK_LOG to print your logs. The usage is similar to
printf :
Minimizing footprint
To minimize the program Flash/RAM, you can disable some of the built-in functionality:
Porting, hacking
If you want to dive into crafting/hacking/porting Blynk library implementation, please also check this
documentation.
FAQ
I backed Blynk on Kickstarter. Where are my widgets and why the app is free?
App is free because otherwise you would have to pay to download it. This is how AppStore and Google Play
works.
Current Blynk release has a limited amount of widgets. We decided to make them free for everyone
until we implement store. After that, every widget will be paid. However every backer will get them for free
(according to their pledge).
Blynk Cloud is a open-source software written on Java using plain TCP/IP and secured TCP/IP (for hardware
that supports it) sockets and running on our server. Blynk iOS and Android apps connect to Blynk Cloud by
default. Access is free for every Blynk user. We also provide a Private Server distribution for those who want
to install it locally.
Yes. Those of you, who want extra security or don’t have internet connection, can install Local Blynk Server
and run it in your own local network. Blynk Server is Open-Source and it takes less than few seconds to
deploy. All the instructions and files are here.
To run Private Blynk Server, all you need is Java Runtime Environment.
Yes, all of them. See full list of supported hardware and shields.
Yes, you can use Blynk just with a USB cable. There is a step-by-step instruction on how to do it.
Does Blynk server store sensor data when app goes offline?
Yes, every command that hardware sends to server is stored. You could use History Graph widget in order to
view it.
It depends mostly on your hardware. Low-end hardware may use up to 32 Virtual Pins. More powerful (like
ESP8266) can use up to 128 but it requires also BLYNK_USE_128_VPINS property in your sketch. Example.
http://help.blynk.cc/faq/blynk-android-permissions-explained
Links
Blynk site
Blynk community
Facebook
Twitter
Blynk Library
Blynk Examples
Blynk Server
Kickstarter campaign
License
This project is released under The MIT License (MIT)