What is Blynk?

Blynk is a platform with iOS and Android apps to control Arduino, ESP8266, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your projects by simply dragging and dropping widgets. If you need more information, please follow these links:

Dashboard settings Widgets Box Dashboard Dashboard2

Content

GETTING STARTED

Blynk server

Blynk Server is an Open-Source Netty based Java server, responsible for forwarding messages between Blynk mobile application and various microcontroller boards and SBCs (i.e. Arduino, Raspberry Pi. etc).

Download latest server build here.

GitHub version GitHub download Build Status

Requirements

Ubuntu java installation instruction.

For Windows download Java here and install.

Quick local server setup

That's it!

NOTE: /path should be real existing path to folder where you want to store all your data.

Enabling mail on Local server

To enable mail notifications on Local server you need to provide your own mail credentials. Create file mail.properties within same folder where server.jar is. Mail properties:

    mail.smtp.auth=true
    mail.smtp.starttls.enable=true
    mail.smtp.host=smtp.gmail.com
    mail.smtp.port=587
    mail.smtp.username=YOUR_EMAIL_HERE
    mail.smtp.password=YOUR_EMAIL_PASS_HERE

Find example here.

WARNING : only gmail accounts are allowed.

NOTE : you'll need to setup Gmail to allow less secured applications. Go here and then click "Allow less secure apps".

Quick local server setup on Raspberry PI

That's it!

Docker container setup

Quick Launch

Quick Launch on Raspberry Pi

Full customisation

Enabling server auto restart on unix-like systems

add the following line

    @reboot java -jar /home/pi/server-0.41.13-java8.jar -dataFolder /home/pi/Blynk &

save and exit.

Enabling server auto restart on Windows

You can also use this script to run server.

Update instruction for unix-like systems

IMPORTANT Server should be always updated before you update Blynk App. To update your server to a newer version you would need to kill old process and start a new one.

10539 - blynk server process id from command output above.

After this steps you can update Blynk app. Server version downgrade is not supported.

WARNING! Please do not revert your server to lower versions. You may loose all of your data.

Update instruction for Windows

App and sketch changes

Custom server icon Server properties menu

IMPORTANT Blynk is being constantly developed. Mobile apps and server are updated often. To avoid problems during updates either turn off auto-update for Blynk app, or update both local server and blynk app at same time to avoid possible migration issues.

IMPORTANT Blynk local server is different from Blynk Cloud server. They are not related at all. You have to create new account when using Blynk local server.

Advanced local server setup

For more flexibility you can extend server with more options by creating server.properties file in same folder as server.jar. Example could be found here. You could also specify any path to server.properties file via command line argument -serverConfig. You can do the same with mail.properties via -mailConfig and sms.properties via -smsConfig.

For example:

java -jar server-0.41.13-java8.jar -dataFolder /home/pi/Blynk -serverConfig /home/pi/someFolder/server.properties

Available server options:

Administration UI

Blynk server provides administration panel where you can monitor your server. It is accessible at this URL:

    https://your_ip:9443/admin

Administration UI

WARNING Please change default admin password and name right after login to admin page. THIS IS SECURITY MEASURE.

WARNING Default allowed.administrator.ips setting allows access for everyone. In other words, administration page available from any other computer. Please restrict access to it via property allowed.administrator.ips.

Turn off chrome https warning on localhost

HTTP/S RESTful

Blynk HTTP/S RESTful API allows to easily read and write values to/from Pins in Blynk apps and Hardware. Http API description could be found here.

Enabling sms on local server

To enable SMS notifications on Local Server you need to provide credentials for SMS gateway (currently Blynk server supports only 1 provider - Nexmo. You need to create file sms.properties within same folder where server.jar is.

    nexmo.api.key=
    nexmo.api.secret=

And fill in the above properties with the credentials you'll get from Nexmo. (Account -> Settings -> API settings). You can also send SMS over email if your cell provider supports that. See discussion for more details.

Enabling raw data storage

By default raw data storage is disabled (as it consumes disk space a lot). When you enable it, every Blynk.virtualWrite command will be saved to DB. You will need to install PostgreSQL Database (minimum required version is 9.5) to enable this functionality:

1. Enabling raw data on server

Enable raw data in server.properties :

    enable.db=true
    enable.raw.db.data.store=true

2. Install PostgreSQL. Option A

    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
    wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

    sudo apt-get update
    sudo apt-get install postgresql postgresql-contrib

2. Install PostgreSQL. Option B

    sudo apt-get update
    apt-get --no-install-recommends install postgresql-9.6 postgresql-contrib-9.6

3. Download Blynk DB script

    wget https://raw.githubusercontent.com/blynkkk/blynk-server/master/server/core/src/main/resources/create_schema.sql
    wget https://raw.githubusercontent.com/blynkkk/blynk-server/master/server/core/src/main/resources/reporting_schema.sql

4. Move create_schema.sql and reporting_schema.sql to temp folder (to avoid permission problems)

    mv create_schema.sql /tmp
    mv reporting_schema.sql /tmp

Result:

    /tmp/create_schema.sql
    /tmp/reporting_schema.sql

Copy it to clipboard from your console.

5. Connect to PostgreSQL

    sudo su - postgres
    psql

6. Create Blynk DB and Reporting DB, test user and tables

    \i /tmp/create_schema.sql
    \i /tmp/reporting_schema.sql

/tmp/create_schema.sql - is path from step 4.

You should see next output:

    postgres=# \i /tmp/create_schema.sql
    CREATE DATABASE
    You are now connected to database "blynk" as user "postgres".
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE TABLE
    CREATE ROLE
    GRANT
    GRANT

Quit

    \q

Now start your server and you should see next text in postgres.log file :

    2017-03-02 16:17:18.367 - DB url : jdbc:postgresql://localhost:5432/blynk?tcpKeepAlive=true&socketTimeout=150
    2017-03-02 16:17:18.367 - DB user : test
    2017-03-02 16:17:18.367 - Connecting to DB...
    2017-03-02 16:17:18.455 - Connected to database successfully.

WARNING: Raw data may consume your disk space very quickly!

CSV data format

Data format is:

    value,timestamp,deviceId

For example:

    10,1438022081332,0

Where 10 - value of pin. 1438022081332 - the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. To display the date/time in excel you may use formula:

    =((COLUMN/(60*60*24)/1000+25569))

0 - device id

Automatic Let's Encrypt certificates generation

Latest Blynk server has super cool feature - automatic Let's Encrypt certificates generation. However, it has few requirements:

IP is not supported, this is the limitation of Let's Encrypt. Also have in mind that myhost.com should be resolved by public DNS severs.

That's it! Run server as regular and certificates will be generated automatically.

Manual Let's Encrypt SSL/TLS Certificates

For example

    ./certbot-auto certonly --agree-tos --email [email protected] --standalone -d blynk.cc

Generate own SSL certificates

If you connect hardware with USB script you have to provide an option '-s' pointing to "common name" (hostname) you did specified during certificate generation.

As an output you'll retrieve server.crt and server.pem files that you need to provide for server.ssl properties.

Install java for Ubuntu

    sudo add-apt-repository ppa:openjdk-r/ppa \
    && sudo apt-get update -q \
    && sudo apt install -y openjdk-11-jdk

or if above doesn't work:

    sudo apt-add-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java8-installer

Port forwarding for HTTP/S API

    sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
    sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 9443

Enabling QR generation on server

    sudo apt-get install libxrender1

Behind wifi router

If you want to run Blynk server behind WiFi-router and want it to be accessible from the Internet, you have to add port-forwarding rule on your router. This is required in order to forward all of the requests that come to the router within the local network to Blynk server.

How to build

Blynk has a bunch of integration tests that require DB, so you have to skip tests during build.

    mvn clean install -Dmaven.test.skip=true

How Blynk Works?

When hardware connects to Blynk cloud it opens either keep-alive ssl/tls connection on port 443 (9443 for local servers) or keep-alive plain tcp/ip connection on port 8080. Blynk app opens mutual ssl/tls connection to Blynk Cloud on port 443 (9443 for local servers). Blynk Cloud is responsible for forwarding messages between hardware and app. In both (app and hardware) connections Blynk uses own binary protocol described below.

Blynk protocol

Hardware side protocol

Blynk transfers binary messages between the server and the hardware with the following structure:

Command Message Id Length/Status Body
1 byte 2 bytes 2 bytes Variable

Command and Status definitions: BlynkProtocolDefs.h

Mobile app side protocol

Blynk transfers binary messages between the server and mobile app with the following structure:

Command Message Id Length/Status Body
1 byte 2 bytes 4 bytes Variable

Websockets web side protocol

Blynk transfers binary messages between the server and websockets (for web) with the following structure:

Websocket header Command Message Id Body
1 byte 2 bytes Variable

When command code == 0, than message structure is next:

Websocket header Command Message Id Response code
1 byte 2 bytes 4 bytes

Possible response codes. Possible command codes

Message Id and Length are big endian. Body has a command-specific format.

Licensing

GNU GPL license