Creating Local Blynk Servers For Noobs

Hi! I have been working on a project that involves setting up a local Blynk server using a raspberry pi. I’ve been working on it for some time and can’t figure out what iP addresses to use within the mobile app, and the Arduino sketch… It could be the iPs but it also could be that the phone isn’t able to connect to the Arduino. Any help that you can give would be great, thanks!

In the mobile app you must connect in the login screen with the ip address of raspberry pi.

Here is the answer (answer 8 of @Dmitriy, You have to press on that icon :…):

http://community.blynk.cc/t/how-to-configure-blynk-server/859/8

It depends on what you want to achieve. In case you want to be in local network of your wi-fi router you need to provide rasp local IP (you can find it by typing “ifconfig” in command line of rasp). If you want your rasp to be accessible from outside the local network you need to put public IP of your router and do port forwarding for local rasp ip.

Thanks so much for rapid replies!

Hmm. I’m still getting an error: “Server cannot talk right now” on the mobile app when trying to connect, still pretty confused. Here’s some more details on what I’m trying to achieve and my setup. I hope this can help us understand exactly what’s going on.

End-goal
In the end, I want to control an Arduino-based robot from my iPhone in a place without a public internet connection. My understanding is that the local server (run by a raspberry pi and router) would let the iPhone connect to the robot without relying on public internet connections.

Hardware connections
So I purchased a dlink router, a Pi (successfully followed these steps), and an ethernet shield for my arduino. Currently, I have my Pi connected to the router’s LAN 2 ethernet jack, and the Arduino+shield connected to LAN 3.

Arduino sketch + Blynk app
Okay, so that’s all the hardware connections. Next comes software. So I booted up Arduino IDE, opened Blynk’s Arduino_Ethernet example sketch. I uncommented the line
Blynk.begin(auth, IPAddress(xxx,xxx,xxx,xxx), xxxx);

So now it’s time to fill in the blanks. I jump over to my Raspberry Pi to find its IP. So I jump in Terminal and type sudo ifconfig (I also found a command, hostname - I that returns just the IP). But a funny thing happened, the IP changed (See included images below). The first time the IP was 169.254.198.26 then the second time it changed to 192.168.0.100. Which one do I use?


So, I try both in the arduino sketch to no avail. In the Serial Monitor, is just keeps spitting out [timestamp] Connecting to ###.###.###.###: #### where timestamp and the # symbols are actual numbers.

Hm.

Simultaneously, I’ve been punching in the custom server information on the iPhone Blynk app. I’ve tried the Pi’s IP address and it keeps telling me “Server cannot talk right now. Try again later.” This is with the phone’s wifi connected to my d-link’s wifi signal (this is required to function, yes?).

Conclusion
I’d absolutely love some step-by-steps and some explanation on what’s going on here.

Again, thank you so much for helping me and the community! (Happy belated thanksgiving)

Hi, I use a setup pretty similar to you with a pi server etc.
So you know where you are, (there’s plenty of other issues to deal with!), I would first set the d-link up with an ip address base that you know. ie 192.168.x.x . From that you will be sure of any ip range that will be issued by it.
I would then configure the pi to use a static address say 192.168.x.199.
You do this in the pi /etc/network/interfaces file.( text editable) …
mine is …

auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.162
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
( comment out any previous lines so that you can return safely to the original config using #)

(The static wlan address is for the pi standalone wireless access point use.)
Now you have a known and static ip address for the Blynk server that will not change.

Monitoring the pi, type in the command to get the Blynk server running to make sure all is well.
From here you know the ip address of the server, and that it is actually running.
You should be able to connect your phone to the server now.

Run your sketch with serial monitor output to make sure that it also connects with the server, using the correct ip address auth code etc.

 bool result = Blynk.connected();
  Serial.print(result);
  if (!result){digitalWrite(2,LOW);

I use an led port to indicate a connection.

I hope that helps a bit.

1 Like

Hello! I’m working with sigilwig33 on our Blynk server. Great news! Roffey’s comment really helped us nail the issue! The local server works beautifully, just as I had imagined.

You’re right, there were a lot of variables to tweak. Here’s what we did, from beginning to end, so fellow noobs looking to set up a local Blynk server with a raspberry pi can succeed! Community, please Use and edit what I say here for increased accuracy!


  1. purchase raspberry pi and an SD card for it. Use standard setup procedure for the rpi, formatting the card, installing raspbian, etc…

  2. obtain other equipment: microcontroller (arduino uno, in my case), router (we bought a cheap D-Link WBR-1310), an Ethernet shield for arduino to connect to the router (wifi shields also work, I believe), and 2 short Ethernet cables.

2.1) make the electrical connections. Give the router, microcontroller, and rpi power. The router will be our “bridge” because it facilitates the conversations the microcontroller, Pi (server), and Blynk app have with each other. So, the microcontroller has to talk with the router: either connect a wifi shield to the router’s wifi, or plug in an Ethernet cable. The same story with the Rpi, connect it to the router over either Ethernet or wireless. Lastly, your Blynk app needs to be a part of the conversation, so connect the smartphone/tablet to the wireless network (or be that one guy who hacked an Ethernet jack into a smartphone).

  1. follow the Blynk instructions for setting up a server on rpi (included below, layman’s terms overlayed) https://github.com/blynkkk/blynk-server

3.1) Login to Raspberry Pi (we plugged the pi into an old monitor and used keyboard and mouse)

3.2) Install java 8 by launching the Terminal and typing:
sudo apt-get install oracle-java8-jdk

3.3) Ensure sure you are using Java 8 by typing:
java -version
And the Output should contain: java version "1.8.0_40"

3.4) Download Blynk server jar file in the Terminal (or manually copy it to raspberry via ssh and scp command) :
wget "https://github.com/blynkkk/blynk-server/releases/download/v0.11.4/server-0.11.4.jar"

3.5) Run the server! Type java -jar server-0.11.4.jar -dataFolder /home/pi/Blynk
As output you will see something like that :
Blynk Server successfully started. All server output is stored in current folder in 'logs/blynk.log' file.
The server will run on the defaults ‘hardware port 8442’ and ‘application port 8443’ (SSL port). We’ll be using the hardware port in the microcontroller code, and the application port in the Blynk mobile app. These port values can be changed by following the Advanced Local Server Setup instructions here https://github.com/blynkkk/blynk-server

3.6) Optionally enable server start when the rpi boots up.
find and open the file entitled “rc.local” within /home/pi/etc/init.d/
Then add the linejava -jar /home/pi/server-0.11.4.jar -dataFolder /home/pi/Blynk &
(Or in case above approach doesn’t work for you, executecrontab -e add the following line @reboot java -jar /home/pi/server-0.11.4.jar -dataFolder /home/pi/Blynk &)
Save and close the file.

To test if the server successfully turns on upon boot up, I restarted the Pi (Terminal: sudo reboot") and in theory the Pi should launch the server automatically. To test, I tried enabling the server manually with code ``. If it was already running, it would return an error because it is already running. If it enables without question, the server was not likely successfully enabled by the Pi automatically.

  1. Give the Pi a static IP. Every computer equipped with dynamic Internet Protocol addresses (basically an ID badge to show to other computers on the network). For security, the Pi is equipped with a Dynamic IP, meaning it changes every time you restart the Pi. This isn’t good because if the IP keeps changing, we’ll have to keep both our Blynk app and microcontroller program up to date with the latest IP. That means reprogramming the robot every time you start it up. Not fun! But that is why there are Static IPs. These don’t change when the Pi reboots, so we only have to program it in once and we’ll be done.

4.1) follow this beautiful tutorial! http://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address

NOTE: to test my pi’s gateway, I had to use the sudo command sudo ping xxx.xxx.xxx.xxx Sudo, essentially, just says to the Pi “do this command and don’t ask any questions because I’m not giving you any other choice”

4.2) Time to test the IP. First, take note of the IP Address as-is. 192.168.xxx.xxx. You can use the shortcut hostname -I (note, the “I” must be capitalized) to view the IP. Then reboot the Pi, and check the IP again. Hopefully the IP will stay the same.

NOTE: if you found that your IP still doesn’t work even after following the tutorial completely, try doing this. Re-add iface eth0 inet dhcp totes Interfaces file right next to iface eth0 inet static. Test again.

  1. The moment of truth. Time to test connecting your Blynk app to the server. Firstly, connect your smartphone to your server’s router. On the log-in page, hit the server button below the big green log in button. Knock the switch toward “custom.” Enter in your Rpi’s IP Address we determined from the Pi Terminal code hostname -I (note, the “I” must be capitalized). Use the Server’s application port (see step 3.5). Hit OK, then enter in your log in information, and log in! There you go!

  2. Your phone and server are talking now! That lets us move on: let’s add the microcontroller to the conversation. Since we have our smartphone connected to the server, we now can generate Auth Codes for our Blynk project boards. Go ahead and create a new project board, and send yourself the Auth Code.

6.1) I’m sure the process varies from board-to-board. With my arduino uno with Ethernet shield, all I had to do was open the Blynk example Sketch, plug in the Raspberry Pi’s IP, hardware port (See step 3.5), and project Auth Code. If those numbers are right, and all the electrical connections are there (see step 2.1), you should have blynking lights!

–Troubleshooting–
So, it’s not working yet, eh?

If you get a “Server can’t talk now” error trying to log into the Blynk app, try these out:

A) Quadruple check that your Pi IP doesn’t change when you reboot.
NOTE: In my experience, even a static IP varies between routers. So make sure you are using the IP address associated with the router you are using. //Can someone in the community help explain this?

B) Ensure the smartphone is connected to the correct wifi network associated with the Pi. Try again now.

C) Let it cook: a watched pot never boils. It seems that the server needs some time to collect its thoughts before it’s ready to connect to your phone. So power up the machine, stand up, stretch, walk out of the room, grab a snack, call your mom, then try logging in.

If you get an error associated with incorrect email/password, give these a shot:

D) in the current time, there seems to be some silliness with some of our Blynk accounts. When you use a local server instead of the Blynk cloud, it may not recognize your previous Blynk account. So, simply, try creating a new account. You may be surprised as we were, because ours connected to our server and arduino right away with our new account.

BE AWARE: But the funny thing is that I have at least 2 distinct Blynk accounts. When I log into my account though the Blynk Cloud, I see my old projects. When I log into my local server, I see my new projects (I used the same username and password for both). Maybe I have an account for each Blynk server IPs or something. Hopefully this can be resolved by the omnipotent Blynkineers.


I really hope this helps clear up some of the confusion for newcomers like me. Thanks so much Roffey, Dmitriy, and shining01!

Happy Blynking!

-djearle98

(on the bright side, I know like 7 Rpi Terminal codes now)

(fine, I know 6)

6 Likes

Great stuff… I am sure this will be a very useful reference.

Relating to the two sets of projects… Connection to the server first relies on creating an account with that server.
The cloud server and the local server are two separate entities. It might be thought that the projects are saved in the app, but they appear to be saved on the server.
In the Blynk directory of the local server will exist a user file. If you have set up an account using an email address, it will be identified by this name. It can be viewed / edited and contains the builds of the project. Having said that, the auth token appears to be stored in the app, so best not to play too much with that.
I have found it useful for copy / paste etc auth tokens into sketches, and viewing how share adds auth tokens and relates them to ‘dashboard’ references.
It can also be useful to back this file up, just in case.

2 Likes

Hi @Dmitriy, have you got some tutorial showing how to put public IP on a raspberry PI?

@anlpereira Hello. I think best way would be to use google. There are a lot of topics about that. This is not Blynk specific.

If you are behind a NAT router (which you probably are), you need to setup a port forwarding rule (or two, depending on what you want to achieve).