Commit 2dedf68c authored by PD0ZRY Rudy's avatar PD0ZRY Rudy
Browse files

Initial commit

parents
Pipeline #52 skipped
{
"mqttHostname": "mqtt://localhost",
"timeout" : 20,
"defaultReflector": 4327,
"per_repeater":{
"123456":4001,
"123457":true,
"123458":false
}
}
{ "name" : "Brandmeister-ReflectorResetter"
, "version" : "1.0.0"
, "dependencies" : {
"request": ""
, "path": ""
, "mqtt": ""
, "node-gyp": ""
, "shelljs": ""
}
}
var mqtt = require('mqtt');
var path = require('path');
require('shelljs/global');
//Init everything
var config = require(path.resolve(__dirname, 'config.json'));
var mqttClient = mqtt.connect(config.mqttHostname)
var db = {};
var per_repeater={};
var timeout = config.timeout * 60;
var default_ref = config.defaultReflector;
var per_repeater = config.per_repeater;
//Setup MQTT
mqttClient.on('connect', function(){
mqttClient.subscribe("Master/+/Repeater");
mqttClient.subscribe("Master/+/Session");
})
mqttClient.on('message', function(source, payload)
{
if(source.search(/Session/i) != -1)
{
ProcessSession(source, payload);
}
else
{
var data = JSON.parse(payload);
if (per_repeater[data['RepeaterID']])
reset_repeater(data['RepeaterID'],per_repeater[data['RepeaterID']]);
else
reset_repeater(data['RepeaterID'],default_ref);
console.log('Setting reflector on connect for : '+data['RepeaterID']);
}
});
function ProcessSession(source, payload)
{
var values = JSON.parse(payload);
if (values['ContextID'] != undefined
&& values['LinkName'] != "LoopBack"
&& values['LinkName'] != "AutoPatch"
&& values['LinkName'] != "FastForward"
&& values['LinkName'] != "DV4mini"
&& values['DestinationID'] == 9
&& values['Slot'] == 2
&& values['Master'] == master
)
{
db[values['ContextID']]={'last': Math.floor(new Date() / 1000), 'ref': values['ReflectorID']};
console.log('Resetting timer for: '+values['ContextID']);
}
}
function reset_repeater(id,ref)
{
if (ref == false) return;
if (ref == true) ref = '0';
exec('/opt/BrandMeister/link.sh '+id+' '+ref, function(status, output)
{
console.log('Exit status:', status);
});
}
setInterval(function()
{
for (index in db)
{
if (Math.floor(new Date() / 1000) - db[index]['last'] > timeout)
{
if (per_repeater[index])
{
if (db[index]['ref'] != per_repeater[index])
{
console.log("Resetting reflector for "+index+" to: "+per_repeater[index]);
db[index]={'last': Math.floor(new Date() / 1000), 'ref': per_repeater[index]};
reset_repeater(index,per_repeater[index]);
}
}
else
{
if (db[index]['ref'] != default_ref)
{
console.log("Resetting reflector for "+index);
db[index]={'last': Math.floor(new Date() / 1000), 'ref': default_ref};
reset_repeater(index,default_ref);
}
}
}
}
}, 10 * 1000);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment