Nodejs and notification

Hi friends. I write a sketch for UPS battery monitoring and I want when the battery capacitor charged to 99% send me a notification. in this nodejs code I can read the battery charge status but when adding code for notification the nodejs not working and can’t connecting.
if v16 == 1 and battcaph == 99 then sending the notification ???

the sketch:

setTimeout(function(){
const Blynk = require('blynk-library');
sys = require('util'),
exec = require('child_process').exec;

const AUTH = 'XOD0yfBURcfpU4YF0mk1pzLlHLpRFRXO';

// Setup Blynk
const blynk = new Blynk.Blynk(AUTH, options = {
	 connector : new Blynk.TcpClient( options = { addr: "172.16.20.254", port: 8080 } )  // This takes all the info and directs the connection to you Local Server.
	 });

var v16 = new blynk.VirtualPin(16);  // Alarm button

notify();
function notify() {
blynk.notify('Alert!');
}

blynk.on('connect', function() {
  blynk.syncVirtual(16);
});

setInterval(function() {
    child = exec("snmpget -O qv -c public -v 2c 192.168.0.100 1.3.6.1.4.1.935.1.1.1.8.1.2.0", function (error, stdout, stderr) {
    if (error !== null) {
        console.log('exec error: ' + error);
    } else {
        var battcaph = parseFloat(stdout);
        blynk.virtualWrite(0, battcaph);
    }
        v16.on('write', function(param) 
         if ((battcaph == 99) && (param == 1)) {
        notify();
    }
  }
   
});}, 5000);

}, 60000);

thanks.

Any help ? :upside_down_face:

@PeteKnight Hi can you help me ? :slight_smile:

Not many Blynk NodeJS users out there…

I would start with the usual troubleshooting suggestion… put in “print” statements to follow the flow of your code to see where it works and where it stops.

Plus… why all this…

…when this would do the same thing

if ((battcaph == 99) && (param == 1)) { 
blynk.notify('Alert!'); 
}
1 Like

I don’t really do NodeJS I’m afraid.

Pete.

1 Like

Thanks for reply. I test it and share the result.

@Gunner I add this code to my nodejs but not working:

v20.on('write', function(param);

setInterval(function() {
    child = exec("snmpget -O qv -c public -v 2c 192.168.0.100 1.3.6.1.4.1.935.1.1.1.8.1.2.0", function (error, stdout, stderr) {
    if (error !== null) {
        console.log('exec error: ' + error);
    } else {
        var battcap = parseFloat(stdout);
        blynk.virtualWrite(1, battcap);
        if ((battcap == 99) && (param == 1)) { 
        blynk.notify('Alert!'); 
}

});}, 5000);

I hate having to keep asking these questions… perhaps it is time to stay away from the forum again :thinking:

But for now… please define “not working”… We KNOW it isn’t working, else you wouldn’t be posting :man_facepalming: What we need are DETAILS… E.G. listed errors and/or references to disconnections (Serial printouts and Blynk Debug anyone?). Explain your comparative testing (perhaps a simple test sketch with single notification command?) and their differing results: rapid beeping, dead silence, smoke, fire…