[SOLVED] Blynk (Local Server) disconnects after my internet goes down

@Aymeen the OP is using an RPi… not too sure if that will work for him, but even if so, probably not in that syntax form.

1 Like

How did the ping thing work out ?

OUT=$(pgrep node)
if [[ “$OUT” = “” ]]; then
echo “Starting the blynk script”
/usr/bin/node /opt/blynk/index.js MYTOKEN &
else
echo “Blynk script is already started”
fi

I just made this script, and run it as a cron job every 5 minutes. thanks for the help

2 Likes

I am quite new to linux and node js but this works for me.

In the blynkclient node js script, add:

//existing code
     var blynk = new Blynk.Blynk(AUTH, options = {
        connector : new Blynk.TcpClient(options = { addr:blynkserver, port:blynkport } )
    });

//add below
setInterval(testInternet,10000); //check every 10seconds
var connected = true; //boolean to detect changes
function testInternet()
{

    require('dns').resolve('www.google.com', function(err) {
    if (err) 
    {
        console.log("No internet connection");
        connected = false;
    }
    else 
    {
        if(connected == false)
        {
        console.log("Internet access is back again.");
        connected = true;

            //reconnect blynk
            blynk = new Blynk.Blynk(AUTH, options = {
            connector : new Blynk.TcpClient(options = { addr:blynkserver, port:blynkport } )
            });
        }
    }
    });
}

How can you execute the script below. I installed the pgrep with install pgrep --save but i get the error on pgrep?

OUT=$(pgrep node)
if [[ “$OUT” = “” ]]; then
echo “Starting the blynk script”
/usr/bin/node /opt/blynk/index.js MYTOKEN &
else
echo “Blynk script is already started”OUT=$(pgrep node)
if

@mat_pav this topic is over a year old, the OP hasn’t been seen back in the forum since posting, and your question is probably Linux related. But you can try creating your own topic and supplying proper details on what you are trying to do, and what exactly is the error, etc.