Ras Pi 2 DISCONNECT & REARMING DISCONNECT

Dear experts. Your help is very necessary.

My configuration:

Raspberry Pi 2

pi@raspberrypi:~ $ node --version
v6.9.5
pi@raspberrypi:~ $ npm -v
3.10.10

My problem is that any running script will lose connection after a while.
This script loses connection in 5-10 minutes.

var Blynk = require('blynk-library');
var W1Temp = require('w1temp');
var AUTH = '';
var blynk = new Blynk.Blynk(AUTH, 
	options = { connector : new Blynk.TcpClient(options = {port:80})});
blynk.on('connect', function() { console.log("Blynk ready."); });
blynk.on('disconnect', function() { console.log("DISCONNECT"); });
blynk.on('error', (err) => {
  console.error('whoops! there was an error');
});

// Automatically update sensors
W1Temp.getSensor('28-000006bed75e').then(function (sensor) {
  sensor.on('change', function (temp) {
    var temp = sensor.getTemperature();
    console.log('Temp changed:', temp,'°C');
pi@raspberrypi:~/project $ node t1.js 
OnOff mode
Connecting to TCP: blynk-cloud.com 80
Temp1 changed: 25.312 °C
Temp1 changed: 25.375 °C
Connecting to TCP: blynk-cloud.com 80
Temp1 changed: 25.437 °C
Connecting to TCP: blynk-cloud.com 80
Temp1 changed: 25.437 °C
Temp1 changed: 25.437 °C
Connected
Authorized
Blynk ready.
Temp1 changed: 25.437 °C
Temp1 changed: 25.437 °C

And the other script works longer without breaks - 30 minutes.

var Blynk = require('blynk-library');
var Gpio = require('onoff').Gpio;
var AUTH = '';
var blynk = new Blynk.Blynk(AUTH,
	options = { connector : new Blynk.TcpClient(options = {port:80})});
blynk.on('connect', function() { console.log("Blynk ready."); });
blynk.on('disconnect', function() { console.log("DISCONNECT"); });
blynk.on('error', (err) => {
  console.error('whoops! there was an error');
});

pwr_sw1 = new Gpio(25, 'out');
reset1 = new Gpio(23, 'out');
pwr_led1 = new Gpio(13, 'in', 'both');

pwr_sw2 = new Gpio(24, 'out');
reset2 = new Gpio(18, 'out');
pwr_led2 = new Gpio(22, 'in', 'both');

door1 = new Gpio(16, 'in', 'both');
door2 = new Gpio(19, 'in', 'both');

var v1 = new blynk.VirtualPin(1);
var v2 = new blynk.VirtualPin(2);

pwr_led1.watch(function (err, value) {  // Watches for button press and assigns 0/1 to value
  if (err) {
    throw err;
  }
if (value  == 0) {
        blynk.virtualWrite(1, 255);  // V1 Widget LED on
    } else if (value == 1) {
                blynk.virtualWrite(1, 0);  // V1 Widget LED off
        }
});

pwr_led2.watch(function (err, value) {  // Watches for button press and assigns 0/1 to value
  if (err) {
    throw err;
  }
if (value  == 0) {
        blynk.virtualWrite(2, 255);  // V2 Widget LED on
    } else if (value == 1) {
                blynk.virtualWrite(2, 0);  // V2 Widget LED off
        }
});

door1.watch(function (err, value) {  // Watches for button press and assigns 0/1 to value
  if (err) {
    throw err;
  }
if (value  == 0) {
        blynk.virtualWrite(3, 255);  // V3 Widget LED on
    } else if (value == 1) {
                blynk.virtualWrite(3, 0);  // V3 Widget LED off
        }
});

door2.watch(function (err, value) {  // Watches for button press and assigns 0/1 to value
  if (err) {
    throw err;
  }
if (value  == 0) {
        blynk.virtualWrite(4, 255);  // V4 Widget LED on
    } else if (value == 1) {
                blynk.virtualWrite(4, 0);  // V4 Widget LED off
        }
});
pi@raspberrypi:~/project $ node index.js 
OnOff mode
Connecting to TCP: blynk-cloud.com 80
Connected
Authorized
Blynk ready.
Disconnect blynk
DISCONNECT
REARMING DISCONNECT
Connecting to TCP: blynk-cloud.com 80
Connected
Authorized

The longer the scripts work, the more often a message appears about the loss of communication.
And in the end, she can not connect at all. The mobile application does not see the device in the Blink application.
I have already reinstalled the OS and modules and libraries several times. But the result is always the same.

What am I doing wrong? What could be the problem?

If there is no solution to this question, can I make it so that the script will be restarted completely if the connection is lost?

I am an absolute noob in the Linux system and therefore I will be glad to any help.

Thank you in advance.

And now your actual question … :wink: