Skip to content

Instantly share code, notes, and snippets.

Last active April 28, 2021 19:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
IOTstack - Blynk setup

(Maintained by 877dev)

First setup:

Run ./ and select Blynk to add it to the stack, as with any other container.

Before you "up" the stack, Blynk server requires two configuration files before it can run. Templates are automatically created on first install in ~/IOTstack/volumes/blynk_server/data/config.

Configuring for first run

Go to ~/IOTstack/volumes/blynk_server/data/config and edit the two files as you would with a normal local Blynk server.

The configs created with the install script will work "out of the box", you just need to edit and add your gmail details as per these requirements. Note - if you don't have 2FA enabled, then "allow less secure apps" in gmail settings, if you do have 2FA you can create an "App password".

Example files are found on Blynk github here:

Now you can "up" the stack and the check it's working.

Optional configuration

Custom or 'boilerplate' message with the emailed token
Create a file called single_token_mail_body.txt and place it in the config directory (same as the .properties files). A template can be found here , credit to DefPlayr on the Blynk forum for this information.

Enable local data storage for Superchart widgets
This is not tested fully and may be subject to change. Supercharts widgets needs local storage to retain the historic data, if you edit the and set it saves data to /home/pi/IOTstack/volumes/blynk_server/data/data/<user>. These files could become very large over time, a USB/SSD drive is recommended. On my setup I have enable.db=false and it still seems to work. More info here and here.

Updating the container to the latest Blynk server version (or changing to any version)

Make sure your project is up to date, details on the main IOTstack page. I would also advise reading the info on updating containers to make sure you understand what to do here.

However the quick and dirty guide that worked for me is:

Run '' and select Blynk server, and pull from template. Alternatively you can manually edit Dockerfile in ~/IOTstack/services/blynk_server. Here is where you can change the version to any one you want.

As this container uses a Dockerfile, the command to update is slightly different to a non-Dockerfile container:
docker-compose up --build -d blynk_server

As the container builds, you will see the version number in the terminal at step 3/11.

To tidy up run docker system prune.

Quickstart Blynk guide

Admin interface

Log into admin panel at https://youripaddress:9443/admin (Use your Pi's IP address, and ignore Chrome warning).

Default credentials:
pass: admin

You can create a new account in the app, see "iOS/Android app setup" section.

Change username and password: Click on Users > "email address" and edit email, name and password.
Save changes
Restarting the container using Portainer may be required to take effect.


iOS/Android app setup

Login the app as per the photos HERE
You can also "Create New Account" here if you want to, make sure to choose custom server.
Press "New Project".
Give it a name, choose device "Raspberry Pi 3 B" so you have plenty of virtual pins available, and lastly select WiFi.
Create project and the auth token will be emailed to you (if emails configured). You can also find the token in app under the phone app settings, or in the admin web interface by clicking Users>"email address" and scroll down to token.

Quick usage guide for app:

Press on the empty page, the widgets will appear from the right.
Select your widget, let's say a button.
It appears on the page, press on it to configure.
Give it a name and colour if you want.
Press on PIN, and select virtual. Choose any pin i.e. V0
Press ok.
To start the project running, press top right Play button.
You will get an offline message, because no devices are connected to your project via the token.
Enter node red.....

Node red:

Install node-red-contrib-blynk-ws from palette manager
Drag a "write event" node into your flow, and connect to a debug node
Configure the Blynk node for the first time:
URL: wss://youripaddress:9443/websockets more info HERE
Note for non-SSL you need to use port 8180 instead of 8080. Why?
Enter your auth token from before and save/exit.
When you deploy the flow, notice the app shows connected message, as does the Blynk node.
Press the button on the app, you will notice the payload is sent to the debug node.

Further reading

Further information and advanced setup:

Check the documentation:

Visit the community forum pages:

Interesting post on MQTT/Node Red flows:

Some Blynk flow examples:

Useful terminal commands

Stop the container docker-compose -f ~/IOTstack/docker-compose.yml stop blynk_server

Delete the container (use with caution) docker-compose -f ~/IOTstack/docker-compose.yml rm -f blynk_server

Start the container (rebuild if deleted) docker-compose -f ~/IOTstack/docker-compose.yml up --build -d blynk_server

Edit (requires nano editor) sudo nano ~/IOTstack/volumes/blynk_server/data/config/

Edit (requires nano editor) sudo nano ~/IOTstack/volumes/blynk_server/data/config/


Check you have actually started the stack (see useful commands section).

Portainer is recommended, where you can check if the container is running. Click on the Blynk container, and under "quick actions" select "Logs" to see useful messages.

Additionally check the Blynk logs at ~/IOTstack/volumes/blynk_server/data/logs

Config files not being created - run ./ and make sure Blynk selected, then choose "Pull full service from template". This ensures the script is run and the sample config files are created in the correct location.

If you want to delete and start over, or have an existing older Blynk container, follow the "Nuclear option" section.

Nuclear option

Only use this if you messed up, have an existing container, or just want a fresh start. You will lose all data! Backup you config files if needed!

Make sure that IOTstack is up to date, so you get the latest Dockerfile, service.yml and script files.

  1. Stop the container docker-compose -f ~/IOTstack/docker-compose.yml stop blynk_server
  2. Delete the container docker-compose -f ~/IOTstack/docker-compose.yml rm -f blynk_server
  3. Delete all old data sudo rm -rf ~/IOTstack/volumes/blynk_server
  4. In Portainer, go to images and delete the old Blynk image (may not need to do this, but just in case)
  5. Rebuild the container and start docker-compose -f ~/IOTstack/docker-compose.yml up --build -d blynk_server Note this will recreate standard config files, as you deleted them in step 3. You will need to edit them again as per the "Configuring for first run" section, or restore from your backup (you did backup right?).
  6. Any issues with config files not getting created, see Troubleshooting section.

Developer information

Included files:

Dockerfile, service.yml and

Possible future improvements

  1. Fine tune the file
  2. Add instructions for certificates
  3. Dockerfile links to "latest" version of server, rather than having to edit it manually. Issue created on github here

General issues & thoughts

  1. The dockerfile attempts to create a file, but it does not persist. Possible issue caused with creating of VOLUME in build process. See mistake no 9 here
  2. The 'normal' way of running the Blynk server is to call a script from the dockerfile, which creates the *.properties files and runs the container. But i think this would overwrite the *.properties files each time the container is run. I also had issues getting the script to be copied over and executed, possibly a lack of knowledge.
  3. Currently the server version has to be defined in the dockerfile via ENV BLYNK_SERVER_VERSION 0.41.14. Possibly there is some way to just use the latest version.
# Create config files for Blynk custom server
#current user
#Check if the config directory already exists:
if [ ! -d ./volumes/blynk_server/data/config ]; then
#Create the config directory
sudo mkdir -p ./volumes/blynk_server/data/config
#Create the properties files:
#cd ~/IOTstack/volumes/blynk_server/data/config
sudo touch ./volumes/blynk_server/data/config/
sudo touch ./volumes/blynk_server/data/config/
#Give permissions:
sudo chown -R $u:$u ./volumes/blynk_server/data/config
#Populate the file:
sudo echo "hardware.mqtt.port=8440
" > ./volumes/blynk_server/data/config/
#Populate the file:
sudo echo "mail.smtp.auth=true
" > ./volumes/blynk_server/data/config/
#Information messages:
echo "Sample properties files created in ~/IOTstack/volumes/blynk_server/data/config"
echo "Make sure you edit the files with your details, and restart the container to take effect."
FROM adoptopenjdk/openjdk14
MAINTAINER 877dev <>
#RUN apt-get update
#RUN apt-get install -y apt-utils
#RUN apt-get install -y default-jdk curl
RUN mkdir /blynk
RUN curl -L${BLYNK_SERVER_VERSION}/server-${BLYNK_SERVER_VERSION}.jar > /blynk/server.jar
# Create data folder. To persist data, map a volume to /data
RUN mkdir /data
# Create configuration folder. To persist data, map a file to /config/
RUN mkdir /config && touch /config/
VOLUME ["/config", "/data/backup"]
# IP port listing:
# 8080: Hardware without ssl/tls support
# 9443: Blynk app, https, web sockets, admin port
EXPOSE 8080 9443
ENTRYPOINT ["java", "-jar", "/blynk/server.jar", "-dataFolder", "/data", "-serverConfig", "/config/", "-mailConfig", "/config/"]
build: ./services/blynk_server/.
container_name: blynk_server
restart: unless-stopped
- "8180:8080"
- "8441:8441"
- "9443:9443"
- ./volumes/blynk_server/data:/data
- ./volumes/blynk_server/data/config:/config
Copy link

Migrating data from existing Blynk Local Server

These steps assume local data storage and does not cover if data is stored in a separate database.
[Old_Blynk] commands were executed in the root of the data.folder.

[Old Blynk Server]
Stop the old Blynk server. Assuming you have a Linux box e.g.: killall java
Remove every startup script on your old box that is related to the old Blynk.

[Docker Host]
Stop container if it is running. docker stop blynk_server

1, SSL certs related steps
[Old Blynk]
Check whether you are using any custom certificates? cat | grep ssl

If the 'server.ssl.cert' and 'server.ssl.key' are set, copy these files to the new Blynk.
Also note down the value of 'server.ssl.key.pass'.

[Old Blynk]
By default 'root' ssh access is not allowed on Raspbian. You have to login with 'pi' and use an intermediate folder.
Use scp, e.g.: scp server.* pi@IP_OF_DOCKER_HOST:/tmp/

[Docker Host]
Move the certificates to a folder that is mapped to a Volume. I suggest the 'config' folder. Make 'root' the owner.

sudo mkdir ~/IOTstack/volumes/blynk_server/data/config/ssl
sudo mv /tmp/server.* ~/IOTstack/volumes/blynk_server/data/config/ssl/
sudo chown root:root ~/IOTstack/volumes/blynk_server/data/config/ssl/*

Edit the '' file to read your certificates. e.g.:


2, Data related steps

Users and their projects are stored in separate files inside the root of the 'data.folder' in format 'LOGON_EMAIL.Blynk.user'.
Copy these files to the new machine as seen in the previous step.

[Old Blynk]
scp *.Blynk.user pi@IP_OF_DOCKER_HOST:/tmp/

[Docker Host]
Move the user files to the 'data.folder', and make 'root' the owner.

sudo mv /tmp/*.Blynk.user ~/IOTstack/volumes/blynk_server/data/
sudo chown root:root ~/IOTstack/volumes/blynk_server/data/*Blynk.user

Historical data is stored inside 'data.folder' within a folder called 'data'.
If 'data.folder=/data' then this folder is '/data/data' inside the container.
On the docker host it is '~/IOTstack/volumes/blynk_server/data/data/'

[Old Blynk]
scp -r data pi@IP_OF_DOCKER_HOST:/tmp/

[Docker Host]
Move the data inside the 'data.folder' and change ownership.

sudo mv /tmp/data ~/IOTstack/volumes/blynk_server/data/
sudo chown -R root:root ~/IOTstack/volumes/blynk_server/data/data/

3, Port forward (if any)
Please do not forget to adapt the port forwards rules in your Rooter from the [Old_Blynk_Server] to the [Docker_Host].
This could mean the port 8080 and/or 9443.

4, Restart container and check
Start your container.

[Docker Host]
docker start blynk_server

Logon to the admin panel (see: Quick start Blynk guide chapter) using your migrated user.
You should be able to see your projects/devices.
The Blynk Android application should be able to connect without changing anything.

Copy link

877dev commented Oct 14, 2020

3, Port forward (if any)
Please do not forget to adapt the port forwards rules in your Rooter from the [Old_Blynk_Server] to the [Docker_Host].
This could mean the port 8080 and/or 9443.

Remember IOTstack Blynk uses port 8180 to avoid conflicts, check the service.yml.
Otherwise it looks good but I cannot test it myself :)

Copy link

Possible future improvements
Add instructions for certificates

Suggestion: Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment