Pi Local Server Questions

Well, if you change your mind… a little light reading of the procedure…

I use a combination of VNC for the graphical GUI into Raspbian (which I believe is based on Debian) and PUTTY / SSH for quick terminal commands like updating Blynk server etc.

Meanwhile, once server is running, you shouldn’t really need to log into the RPi for anything.

You did say you could get to the Admin page, but just needed the default credentials… I understood that you did that from your PC. So that shows the server is at least running.

1 Like

It’s still running, but I will need to power it down to get the micro SD card out to be put into the Pi Zero W. Once in the ZeroW, I will have no way to visually interface with that device directly. Becuase of this reason, I’ll need to preconfigure it all to autoboot and install updates when needed. Even if I could SSH in, I would still need the server to launch itself after booting the device.

VNC is your best bet then for easier remote access, even when you transfer the CD card over, as long as you know the IP address, you will be able to log into it. Also read up on the these things on the https://www.raspberrypi.org site and forum.

And adding the line into /etc/rc.local method I mentioned above will auto start the server. But you have to set that up from the RPi as those files are not accessible on the boot partition of the CD card (in a PC).

Also, activate SSH as you did for the VNC. In a pinch you can use PUTTY to get CLI control of the RPi and do things like edit the rc.local file and start/stop the server, etc.

1 Like

I have putty installed and was able to connect. Do you know the commands I’d need to send to edit the rc.local file? If no, can you point me in the right direction to learn how?

I found how to save edits to the rc.local file via console.

sudo nano /etc/rc.local

to get in, then pasted

 java -jar /home/pi/server-0.31.1.jar -dataFolder /home/pi/Blynk &

line just above exit0, then press Ctrl/X, then Y, then enter. Now it seems I need to change the default pi login and password in order for the server to launch, but I’m too tired and will resume the battle in the morning.

May I make a suggestion regarding Blynk logins? Since a gmail account is needed to login to at least the local server, consider adding a Google+ login feature to the home screen? As of now, the 3 options are Facebook, Twitter and Yahoo. It makes little sense (to me) why gmail isn’t an option as well due to a gmail account being a prerequisite for the server. FWIW, I was able to login to gmail, but still am unable to login here to blynk.cc.

1 Like

A few more kinks to work through.

  1. setting a static IP. @Costas linked me to a tutorial for setting the static IP to the Pi itself. Last night I found something that had me change the Administrator IP inside the server.properties file. Should I revert the adminIP back to 0.0.0.0/0 and pursue a static IP for the Pi itself? I don’t understand the differences, but on the surface, I had the impression that I wanted to apply the static IP to the server not the machine.

  2. I’m having difficulty logging into the Blynk app. I don’t believe it’s an IP/port issue, but my log in credentials aren’t being recognized. My app is current with updates, so too is my library and server and it is this “skybound” account I’m trying to login to. I’ve changed the Pi’s language to United States English, yet the @ and " are switched.

This means allow any IP address to access the admin panel and should be used as the default position.

I don’t know if you have done any port forwarding to access your Pi externally but if you haven’t you are safe with allowing all IP addresses to access the admin panel.

You set a static IP for the Pi to ensure you have a fixed address from your router for PUTTY. VNC, WinSCP and Blynk etc

The account for this forum is absolutely nothing to do with “Blynk servers”, local or cloud. They are separate accounts. At worse create a new account on your local server from the app.

There are 2 settings for most Unix style systems, general language and keyboard settings.

1 Like

It’s easiest to use Putty to configure and control your Pi. Learning the command line is a bit hard now, but it will give you an advantage when you start scripting later on. Also, the GUI on the Pi below Pi2 can be quite slow.

This is my startup script:

#!/bin/bash
#

BASE=/tmp
PID=$BASE/blynk.pid
LOG=$BASE/blynk.log
ERROR=$BASE/blynk-error.log

COMMAND="/storage/java/jre/bin/java -jar /storage/blynk/server.jar"

status() {
        echo
        echo "==== Status"

        if [ -f $PID ]
        then
                echo
                echo "Pid file: $( cat $PID ) [$PID]"
                echo
                ps -ef | grep -v grep | grep $( cat $PID )
        else
                echo
                echo "No Pid file"
        fi
}

start() {
        if [ -f $PID ]
        then
                echo
                echo "Already started. PID: [$( cat $PID )]"
        else
                echo "==== Starting"
                touch $PID
                if nohup $COMMAND >>$LOG 2>&1 &
                then
                        echo $! >$PID
                        echo "Done"
                        echo "$(date '+%Y-%m-%d %X'): START" >>$LOG
                else
                        echo "Error"
                        /bin/rm $PID
                fi
        fi
}

kill_cmd() {
        SIGNAL=""; MSG="Killing "
        while true
        do
                LIST=`ps -ef | grep -v grep | grep server.jar | awk '{print$1}'`
                if [ "$LIST" ]
                then
                        echo; echo " $MSG $LIST" ; echo
                        echo $LIST | xargs kill $SIGNAL
                        sleep 2
                        SIGNAL="-9" ; MSG="Killing $SIGNAL"
                        if [ -f $PID ]
                        then
                                /bin/rm $PID
                        fi
                else
                        echo; echo "All killed" ; echo
                        break
                fi
        done
}

stop() {
    echo "==== Stop"

    if [ -f $PID ]
    then
        if kill $( cat $PID )
        then echo "Done."
             echo "$(date '+%Y-%m-%d %X'): STOP" >>$LOG
        fi
        /bin/rm $PID
        kill_cmd
    else
        echo "No pid file. Already stopped?"
    fi
}

case "$1" in
    'start')
            start
            ;;
    'stop')
            stop
            ;;
    'restart')
            stop ; echo "Sleeping..."; sleep 1 ;
            start
            ;;
    'status')
            status
            ;;
    *)
            echo
            echo "Usage: $0 { start | stop | restart | status }"
            echo
            exit 1
            ;;
esac

exit 0

Paste this in a file called “blynk.sh” in the same location as server.jar file.

Very important: when you did that, the Linux system needs to know it is a script, so do this:

OpenELEC:~/blynk # chmod +x blynk.sh
OpenELEC:~/blynk #

This will indicate to the system you can execute it, like so:

OpenELEC:~/blynk # ./blynk.sh start
==== Starting
Done
OpenELEC:~/blynk #

Or stop the server:

OpenELEC:~/blynk # ./blynk.sh stop
==== Stop
Done.

 Killing  569


All killed

OpenELEC:~/blynk #

Or use the option restart to, well, you guessed it, restart your server. You could add this script to /etc/init.d folder and make it run at start up (https://gist.github.com/naholyr/4275302 see this for example).

I’ve also created an update script:

#!/bin/bash
#
# Update script for Blynk Server on Linux-like systems.
# This script relies on the use of curl for fetching Blynk.jar file
# It also has a reference to "blynk.sh", which is my start script.
#
# My blynk.sh script refers to "server.jar" which is a symbolic link
# to the actual server.jar file. That way it's easy to use in startup
# routines etc.
#
# You can change the variables to your local situation (mine is a Raspberry
# Pi with OpenELEC, hence the Storage path).
#
# This is a really dirty script, it doesn't do RegEx, but just assumes
# that the URL for GitHub will always be the same length (which it
# probably will).

#----------------------------------------------------------
# BEGIN User variables, change these to your situation
#----------------------------------------------------------

# Base path to your Blynk server.jar file
BASE=/storage/blynk

# Startup script name (full path)
STARTUP="$BASE/blynk.sh"

# The symlink used in blynk.sh startup file (full path)
SYMLINK="$BASE/server.jar"

#----------------------------------------------------------
# END USER VARIABLES, change below only if you are sure
# about it ;-)
#----------------------------------------------------------

URL=https://github.com/blynkkk/blynk-server/releases/latest
REDIRECT=`curl $URL`
LATESTVERSION=${REDIRECT:89:6}
DOWNLOAD="http://github.com/blynkkk/blynk-server/releases/download/v$LATESTVERSION/server-$LATESTVERSION-java8.jar"

CURRENT=`readlink $SYMLINK`
CURRENTVERSION=${CURRENT:7:6}

echo "### Current version from Symlink ###"
echo $CURRENTVERSION

echo "### New Version ###"
echo $LATESTVERSION

if [ $CURRENTVERSION = $LATESTVERSION ] ; then
        echo "You are up to date"
        exit 0
else
        echo "New version available, downloading"
        wget $DOWNLOAD
fi

echo "Removing old Symlink and making new one"
rm $SYMLINK
ln -s server-$LATESTVERSION-java8.jar server.jar

# Call the other startup script here
echo "Restarting Blynk server"
/bin/bash $BASE/blynk.sh restart
echo "All done!"

Same thing applies, put this in a file called “update.sh” and also chmod +x that file. The update.sh assumes there is a Blynk installation in /storage/blynk (so, adapt this variable in the script to where your server.jar file is!!). It also makes use of the forementioned blynk.sh script to restart the server if a new version is downloaded.

2 Likes

The past 5 or so days trying to figure the various Pi issues out was definitely not fun. It seems the new Raspbian Stretch has some bugs. It’s also not easy finding older distros. I tried to burns NOOBS, but that was unsuccessful. I was unable to create a blank ssh file and wpa_supplicant.conf file. Another approach was to configure a static IP through ssh, also unsuccessful. So far, the only thing I am able to accomplish was to etch the Raspbian image (not the lite version), enable ssh in Preferences/RaspPi, and also login to wifi via the Pi desktop. I will be away for the rest of the day, but tomorrow I will try once again to give the Pi a static IP and download and configure the Blynk server. I still don’t know if I’ll be able to use the Pi Zero W, or if I’ll need to stick with the Pi 3b.

Setting a static IP, you need to edit /etc/dhcpcd.conf and add the IP there (not in interfaces file!):

interface wlan0
        static ip_address=192.168.178.103
        static routers=192.168.178.1
        static domain_name_servers=8.8.8.8 8.8.4.4

Yes, that’s how I had to do it because I wasn’t able to add a wpa_supplicant file. So now that my server is broadcasting, should I be able to see it in the list of WiFi networks in my cell phone?

No, your Pi is part of the local network and it connects to that, just like a client.

If you have it on the network the next step is running the Local Blynk server and connecting to there wit the Blynk App on your phone.

My current problems are as follows;

  1. The Pi is running the server and the static IP is showing in my router’s UI, but I am unable to connect my phone/app to the server. Which email address do I need to connect the app to the server, the admin@blynk.cc, or the email address I created for this project?

  2. I assume that because it’s a server, it will broadcast a wifi signal for my hardware to connect to? If no, how is the hardware supposed to link up to the server?

  3. The majority of my lacking is due to ports. I’ve seen mention of the following ports in no such order. 80, 443, 7443, 8440, 8441, 8442, 8080 and 9443. Which is to be used, and do I need to set up port forwarding in my home network’s UI? If yes, the fields are “Start Port” and “End Port”. Should I then make multiple instances of the known static IP to encapsulate all of these ports for Blynk Server, or should I just set the start port to the lowest number and the end port to the highest number?

I’m trying my very best to rely on archived posts, instructbles and original instructions to figure my way through this process and I am still getting so much wrong, or not able to produce the same exact results for reasons I don’t understand. Setting up Raspbian with a Static IP was nothing like the commonly used approach of others and I had to find info in the rPi forums to get through to the point I’m at now. I had to change the IP via Console and/or SSH, and there was a lot of switching my mouse/keyboard plus HDMI over to the Pi3 just to use the Pi’s desktop to get a lot of it done which now makes me think of another hurdle I’m struggling with.

  1. I’m not able to execute a server start script. I’ve tried to save all of the various scripts into the root directory when the SD was connected to my Windows machine, but when I “Eject” the card, those files are lost and when I issue the Console commands for restarting in the Unix environment, the command doesn’t execute. I need it to execute so that I can power off the Pi and put that configured SD into a Pi Zero W as that is where I want the Blynk Server to host from, but in a headless environment. SSH is functional now and the card is still in the Pi3 so I can use the desktop if need be.
java -jar /home/pi/server-0.32.0.jar -dataFolder /home/pi/Blynk &

or

crontab -e

1 You need to enter the credentials you created for this project. Did you create a login via the App on your local server? You can check this by looking for this files:

pi@raspberrypi3:~/blynk/data $ ls
<usrname>@emailaddress.com.Blynk.user
pi@raspberrypi3:~/blynk/data $

The User file contains the login information etc. If this exists (but with your chosen username), you registered an account on the server which you have to use to login (the login Screen at Blynk App needs to point to the server. Connect your phone to the local network and enter the IP for the server instead of cloud.blynk.cc)

2 No, the only thing you need to connect to, is the IP of the server via the hardware using a sketch. E.g.

//#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

const char* ssid = "<ssid here>";
const char* password = "<wifi password here>";

char auth[] = "<token for project here>";   // token for blynk esp-12-tree, raspi, iphone

void setup()
{
  Serial.begin(115200);

  Blynk.begin(auth, ssid, password, "<enter IP address of Pi here>", 8442);

  while (Blynk.connect() == false) { }
}

void loop()
{
  Blynk.run();
}

3 Forget the port forwarding for now. Make sure everything works as intended on your LOCAL network fires.

4 You cannot put Linux files on the SD with a Windows machine. It needs to be done on the Pi. Windows cannot read or write to that file system. It’ll end up in the boot partition and you don’t want to do that.

1 Like

Screenshot shows OP was trying to create a new account when it failed.

That’s what WinSCP is for.

WinSCP or FileZilla is fine for transfer of files, but you cannot put a Linux SD in a Windows machine and put files on it that way :wink:

I’m not seeing any SS from BlynkApp connecting in this topic though…

Sorry you are right it’s the other really long thread on the same subject.

Maybe I should read the thread more closely but WinSCP does but “put Linux files on to the SD” and that is for the visible and normally hidden partition. Maybe it would be more correct to say you can’t install linux files on the SD with Windows but that’s not technically correct either as this is what putty does.

As suggested in other tutorials or threads, I tried (but failed) to add the Start, Stop and Restart scripts. Also tried to make the blank SSH file to add to the root directory with simple drag and drop, but failed with that as well. Following Gunner’s advice, I went into the Pi’s desktop to enable SSH manually which worked thankfully. Lichtsignaal, I tried to SSH the scripts you shared above but the Pi returned No Such File or Directory. Do I need to shut the Pi down and put the SD back into my laptop and manually look through the files? I’m near certain that my login info isn’t in the Pi files because that info was added to the server.properties file which I am still unable to install to the SD card with my Windows machine. Will I be able to install or copy all of the various files I need to get onto the Pi with the app Costas suggested WinSCP? I downloaded it and will install it while waiting for a reply to these questions. Also, when connecting my phone app, which port should be listed after the static IP address?

pi@raspberrypi3:~/blynk/data $ ls

or

pi@raspberrypi3:~/blynk/data $

Leave the port as it is, 9443 with latest app :slight_smile:

1 Like

Will WinSCP allow me to put the properties files and start scripts into the root directory?