Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created August 7, 2013 08:17
Show Gist options
  • Select an option

  • Save TheSkorm/6172209 to your computer and use it in GitHub Desktop.

Select an option

Save TheSkorm/6172209 to your computer and use it in GitHub Desktop.
get voltage from mikrotik and post to pvoutput
//requires npm install snmp-native moment
var snmp = require('snmp-native');
var session = new snmp.Session({ host: '10.0.0.254', port: 161, community: 'public' });
var http = require('http');
function postData(volts){
var options = {
host: 'pvoutput.org',
port: 80,
path: '/service/r2/addstatus.jsp?d='+moment().format("YYYYMMDD")+'&t='+moment().format("HH:mm")+'&v6='+volts+'&v4=1',
method: 'GET',
headers: {'X-Pvoutput-Apikey': '', 'X-Pvoutput-SystemId':''}
};
http.get(options, function(resp){
console.log('STATUS: ' + resp.statusCode);
console.log('HEADERS: ' + JSON.stringify(resp.headers));
resp.setEncoding('utf8');
resp.on('data', function(chunk){
console.log(chunk);
});
}).on("error", function(e){
console.log("Got error: " + e.message);
});
}
function checkVolts(){
session.get({ oid: [1,3,6,1,4,1,14988,1,1,3,8,0] }, function (error, varbind) {
if (error) {
console.log('Fail :(');
} else {
postData(varbind[0].value/10);
}
});
}
setInterval(checkVolts, 300000 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment