Run ./menu.sh
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
.
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 mail.properties 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: server.properties mail.properties
Now you can "up" the stack and the check it's working.
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 server.properties
and set enable.raw.db.data.store=true
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.
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 'menu.sh' 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
.
Log into admin panel at https://youripaddress:9443/admin (Use your Pi's IP address, and ignore Chrome warning).
Default credentials:
user: [email protected]
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.
NOTE IGNORE THE CONFIG SECTION, DOES NOT CURRENTLY WORK AND CHANGES ARE NOT SAVED info
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.
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.....
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 information and advanced setup: https://github.com/blynkkk/blynk-server
Check the documentation: https://docs.blynk.cc/
Visit the community forum pages: https://community.blynk.cc/
Interesting post on MQTT/Node Red flows: https://community.blynk.cc/t/my-home-automation-projects-built-with-mqtt-and-node-red/29045
Some Blynk flow examples: https://github.com/877dev/Node-Red-flow-examples
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 server.properties (requires nano editor)
sudo nano ~/IOTstack/volumes/blynk_server/data/config/server.properties
Edit mail.properties (requires nano editor)
sudo nano ~/IOTstack/volumes/blynk_server/data/config/mail.properties
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 ./menu.sh
and make sure Blynk selected, then choose "Pull full service from template". This ensures the directoryfix.sh 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.
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.
- Stop the container
docker-compose -f ~/IOTstack/docker-compose.yml stop blynk_server
- Delete the container
docker-compose -f ~/IOTstack/docker-compose.yml rm -f blynk_server
- Delete all old data
sudo rm -rf ~/IOTstack/volumes/blynk_server
- In Portainer, go to images and delete the old Blynk image (may not need to do this, but just in case)
- 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?). - Any issues with config files not getting created, see Troubleshooting section.
Dockerfile, service.yml and directoryfix.sh.
- Fine tune the server.properties file
- Add instructions for certificates
- Dockerfile links to "latest" version of server, rather than having to edit it manually. Issue created on github here
- The dockerfile attempts to create a server.properties file, but it does not persist. Possible issue caused with creating of VOLUME in build process. See mistake no 9 here
- 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.
- 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.
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 server.properties | 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.
Edit the 'server.properties' 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.
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.
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.