Introduction: Creating a Local Blynk Server
In this post, we learn how to create a local Blynk server which will greatly reduce the overall latency that is sometimes present when using the default, remote server. We set it up using a Pi Zero W and we also create a demo project to make sure it is all working correctly.
Step 1: Watch the Video
The video above goes through all the details that you need to know to set up the server. Please watch that first for an overview to understand how everything comes together.
Step 2: Configure the Pi
I decided to use the desktop version of Raspbian though you could also use the Lite version and do everything using the terminal. You can use the following link for the official installation instructions but I have covered the important steps below:
Once you have the Raspberry PI setup, run the following commands to install Java and then download the server file:
- sudo apt install openjdk-8-jdk openjdk-8-jre
- wget "https://github.com/blynkkk/blynk-server/releases/download/v0.41.12/server-0.41.12-java8.jar"
Once that is done, all we need to do is use crontab to automate the server at boot. That can be done by running the following command to open up crontab:
- crontab -e
- @reboot java -jar /home/pi/server-0.41.12-java8.jar -dataFolder /home/pi/Blynk &
- sudo nano mail.properties
We need to add the email settings in this file along with the details of an email account. Please use the GitHub link to obtain the lines that need to be added or refer to the video for more details.
The final step is rebooting the board which can be done by running the following command:
- sudo reboot
Step 3: Configure the App
Download the Blynk app or logout if you already have it. Click the option to create a new account and then click the icon at the bottom of the screen to enter the server details. Click the custom option and enter the IP address of your raspberry Pi. Then, provide a valid email address and enter a password to create an account on your local server.
You can now use Blynk normally but as a test, create a demo project to toggle pin D1 on the WeMos D1 mini board. That's all you need to do here.
Step 4: Configure the Board
You will receive an email with the authentication token for your project. Open up the Arduino IDE, make sure you have installed the Blynk library using the library manager and then open the nodemcu example sketch.
Add your authentication token, WiFi network details, and then be sure to comment out the default server connection line as we need to add the local server IP address as shown in the image/video. Then, upload the sketch to the board and open the serial monitor to view the output. It should first successfully connect to your WiFi network and it will then connect to the server and if successful, it will give you the "Ready" message.
Step 5: Test the Setup
Open the app and click the run button. Now, you will be able to control the GPIO state using the button.