Last week we took a look at Blynk which is an extremely easy to use IoT platform. We
used that to control a GPIO on a WeMos D1 Mini that was also scheduled to turn ON and
OFF at certain times. By default, the app uses the Blynk server which makes things extremely
simple, however the biggest issue is perhaps latency as data has to travel from your phone,
to the Blynk server and then to the device being controlled.
One way to solve this problem is by using a local server and in this video, we will
configure a Raspberry Pi to act as a local Blynk server which will eliminate the latency
issue. Also, by using a local server, you have unlimited energy which means that you
can create several complex projects which is a bonus.
I will be using a Pi Zero W, though you can also use any other Raspberry Pi variant that
you have. For the operating system I will be using the desktop version and you can also
use the lite version and do everything with the terminal. You will need a suitable microSD
card and I'm using this 32GB card that I have though a 16GB version should be just fine. Once
you’ve downloaded the image, you would need to use etcher to flash it to the card.
At this stage, you have two options, you can insert the card connect a display, keyboard
and mouse to get started. But for the Pi Zero, you would need an HDMI adaptor like this one
along with a USB adaptor and hub to connect a keyboard and mouse. Instead of doing all
of this, you could also access the raspberry Pi remotely and that is what I would like
to do. We have covered this in detail in a previous video so do take a look at that if
you are not familiar with the process.
Either way, you will end up with a screen like this and you can connect to a WiFi network
using this icon here.
Now that we have the Pi setup, we need to install the Blynk server.
There are instructions on the Github page for you to do this so you can use that as
a reference. First, we need to install Java so open up a terminal window and type in the
command shown here. Confirm the installation by typing in Y and then wait for it to complete.
Next, type this command to obtain the JAR file. The final step is running the server
and you could use this command to run it manually but you would have to do this every time the
pi boots. I would like to configure it such that it automatically starts on boot.
To do that simply type in the command shown here and then type in the number corresponding
to the nano text editor option. It will open up a new file and you need to scroll down
to the bottom. Then, type in the command shown on screen which will cause the server to run
on boot. Hit CTRL+X, then Y, then ENTER to save the file.
The server sends you an authentication token for each project and this makes it easier
for you to configure the hardware. In order for this feature to work, we need to configure
the email settings.
So type in the following command to create a new text file in the same folder as the
JAR file. You will need to type in everything that you see on the installation page and
save the file by typing CTRL+X, then Y, then ENTER. Once this is done, you simply need
to reboot the raspberry pi and the server will run automatically.
I would recommend creating a new email address for this and as of now, only gmail accounts
work with the system. You would also need to enable less secure apps and you can do
that by clicking this link here and enabling the option.
Give the board a couple of minutes to boot and then open up a web browser and type in
the following address. Be sure to use the IP address of your board. You will get a warming
message as seen here and that’s because we have not installed an SSL certificate on
the server. So go ahead and add an exception to proceed. The default username is admin@blynk.cc
while the password is admin. This will get you into the admin page where you will be
able to view all the users and other information. We haven’t configured any users yet so let’s
fix that.
Download the Blynk app or log out if you already have it. Click the option to create a new
account and then tap this icon here. Select the custom option and enter the IP address
of your board. Leave the port number to the default value which is 9443 for me. Then,
enter an email address along with a password. You need to have access to this email address
as the token will be sent to it. Hit the sign-up button and you should then be able to create
new projects like before.
I’m going to create a simple demo project for the WeMos D1 mini board to show you the
remaining steps. If you open up the widget drawer then you will see that our energy is
at 100,000 and as you will see later, we can update this further. I am going to add a button
to control pin D1 and I will change its mode to act like a SWITCH as seen here and that’s
all we need to do.
You should have received an email with the token by now so copy that and then open up
the Arduino IDE. Make sure you have installed the Bynk library and then open up the example
sketch for your board. Add the token, your wifi network details along with the server details before you upload it to
the board. Once done, connect an LED to the board so that we can view its status. All
we need to do now is open up the APP, start the project and then press the button to control
the GPIO pin. As you can see, we can control the board using our local server.
Now, if you log in to the server then you will be able to view the users, along with
their projects and you can even view all the details related to it. If you want, you can
even increase the energy levels as required.
And that is how you can create a local blynk server for you to use with your projects.
If you are only interested in controlling devices from your home network then this is
definitely a recommended way to proceed as you not only get the benefit of additional privacy
but also unlimited energy. You can control your devices remotely over the internet
but to do this, you need to forward some ports on your home router. I will not be covering
this as if you could create a security risk if you do it incorrectly. It is also more
of a network configuration thing so do check out any of the available guides that will
help you do this.
I do hope this has been of some use to use. Don’t forget to like, share and subscribe
if you haven’t already. Thank you for watching and I will see you in the next one.