Hi my script works fine (js using node.js), for about 1 day, and then I randomly stops, and quits. (see code output below)
I am using raspberry Pi model 3 b+
all libraries are up-to-date as of 3sept2022@15:04pm AEST time.
any help would be greatly appreciated
Connecting to TCP: blynk.cloud 80
Connected
Authorized
node:events:518
throw err; // Unhandled 'error' event
^
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('ECONNRESET')
at new NodeError (node:internal/errors:372:5)
at Blynk.emit (node:events:516:17)
at Blynk.error (/home/doorpi/myapp/node_modules/blynk-library/blynk.js:649:8)
at exports.TcpClient.<anonymous> (/home/doorpi/myapp/node_modules/blynk-library/blynk.js:612:48)
at exports.TcpClient.emit (node:events:527:28)
at Socket.<anonymous> (/home/doorpi/myapp/node_modules/blynk-library/blynk-node.js:59:14)
at Socket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ERR_UNHANDLED_ERROR',
context: 'ECONNRESET'
}
I would have thought that it would make more sense to raise the issue against the Blynk node.js library on GitHub rather than the C++ library. Posting your full script would also a sensible move.
I will raise thy issue on blynk node.js library now sir
below is my js script:
#!/usr/bin/env node
var BLYNK_TEMPLATE_ID = '*hidden for security*'
var BLYNK_DEVICE_NAME = 'Door1'
var BLYNK_AUTH_TOKEN = '*hidden for security*'
var SERVER_ADDR = 'https://sgp1.blynk.cloud/'
var unlockedState = 800; // was 1000
var lockedState = 1800; // was 2200
// difference of 800 is approx. 90 deg
disconnect = function (reconnect) {
console.log('Disconnect blynk');
if (typeof reconnect === 'undefined') {
reconnect = true;
}
var self = this;
this.conn.disconnect();
if (this.timerHb) {
clearInterval(this.timerHb);
this.timerHb = null;
}
this.emit('disconnect');
//cleanup to avoid multiplying listeners
this.conn.removeAllListeners();
//starting reconnect procedure if not already in connecting loop and reconnect is true
if (reconnect && !self.timerConn) {
console.log("REARMING DISCONNECT");
setTimeout(function () { self.connect() }, 5000);
}
}
var motorPin = 14;
var buttonPin = 4
var ledPinGreen = 17
var ledPinRed = 11
var blynkToken = '*hidden for security*';
// *** Start code *** //
var locked = true
//Setup servo
var Gpio = require('pigpio').Gpio,
motor = new Gpio(motorPin, {mode: Gpio.OUTPUT}),
button = new Gpio(buttonPin, {
mode: Gpio.INPUT,
pullUpDown: Gpio.PUD_DOWN,
edge: Gpio.FALLING_EDGE
}),
ledGreen = new Gpio(ledPinGreen, {mode: Gpio.OUTPUT});
ledRed = new Gpio(ledPinRed, {mode: Gpio.OUTPUT});
//Setup blynk
var Blynk = require('blynk-library');
var blynk = new Blynk.Blynk(blynkToken, options = {
connector : new Blynk.TcpClient()
});
var v0 = new blynk.VirtualPin(0);
console.log("locking door")
lockDoor()
button.on('interrupt', function (level) {
console.log("level: " + level + " locked: " + locked)
if (level == 0) {
if (locked) {
unlockDoor()
} else {
lockDoor()
}
}
});
v0.on('write', function(param) {
console.log('V0:', param);
if (param[0] === '0') { //unlocked
unlockDoor()
console.log("Door is unlocking...") // the web app will display unlocked
} else if (param[0] === '1') { //locked
lockDoor()
console.log("Door is locking...") // the web app will display locked
} else {
blynk.notify("Door lock button was pressed with unknown parameter");
}
});
//blynk.on('connect', function() { console.log("Blynk ready?"); });
//blynk.on('disconnect', function() { console.log("DISCONNECT"); });
function lockDoor() {
motor.servoWrite(lockedState);
ledRed.digitalWrite(0);
ledGreen.digitalWrite(1);
locked = true
//notify
blynk.notify("Door has been locked!");
//After 1.5 seconds, the door lock servo turns off to avoid stall current
setTimeout(function(){motor.servoWrite(0)}, 1500)
}
function unlockDoor() {
motor.servoWrite(unlockedState);
ledGreen.digitalWrite(0);
ledRed.digitalWrite(1);
locked = false
//notify
blynk.notify("Door has been unlocked!");
//After 1.5 seconds, the door lock servo turns off to avoid stall current
setTimeout(function(){motor.servoWrite(0)}, 1500)
}