Send to rado platform; show_dbdata, db loads after start
This commit is contained in:
parent
ed0fe5b15d
commit
f63ac50497
22 changed files with 6380 additions and 2279 deletions
|
|
@ -49,13 +49,8 @@ class DataToTbHandler {
|
|||
for(let i = 0; i < arrayOfValues.length; i++)
|
||||
{
|
||||
ts = arrayOfValues[i].ts;
|
||||
|
||||
//console.log("sendToTb------------>before", arrayOfValues[i].values, tbname);
|
||||
|
||||
let values = this.prepareValuesForTb(tbname, ts, arrayOfValues[i].values);
|
||||
|
||||
//console.log("sendToTb------------>after", values);
|
||||
|
||||
if(!this.isEmptyObject(values))
|
||||
{
|
||||
arrayOfValuesToSend.push({ts: ts, values: values});
|
||||
|
|
@ -68,17 +63,6 @@ class DataToTbHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
let dataToTb = {
|
||||
[tbname]: [
|
||||
{
|
||||
"ts": Date.now(),
|
||||
"values": values
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
this.messageCounter++;
|
||||
|
||||
let dataToTbModified = {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class ErrorToServiceHandler
|
|||
console.log("ErrorToServiceHandler------------------------>send to service", dataToInfoSender);
|
||||
|
||||
//TODO UGLY!!!
|
||||
if(this.projects_id === undefined) this.projects_id = FLOW.OMS_projects_id;
|
||||
if(this.projects_id === undefined) this.projects_id = FLOW.GLOBALS.settings.project_id;
|
||||
|
||||
/*
|
||||
if(this.projects_id === undefined)
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
//key is device, value = str
|
||||
let sentValues= {};
|
||||
|
||||
function sendError(func, device, weight, str, extra, tb_output, instance, type) {
|
||||
// if ((weight === ERRWEIGHT.DEBUG) && (instance.CONFIG.debug === false)){
|
||||
// return; // Allow debug messages only if CONFIG.debug is active
|
||||
// }
|
||||
|
||||
let key = device;
|
||||
if(type != undefined) key = type;
|
||||
|
||||
if(sentValues.hasOwnProperty(key))
|
||||
{
|
||||
if(sentValues[key] == str)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sentValues[key] = str;
|
||||
|
||||
let content = {
|
||||
"type": weight,
|
||||
"status": "new",
|
||||
"source": {
|
||||
"func":func,
|
||||
"component":instance.id,
|
||||
"component_name":instance.name,
|
||||
"edge":device
|
||||
},
|
||||
"message":str,
|
||||
"message_data": extra
|
||||
};
|
||||
|
||||
let msg = {};
|
||||
msg[device] = [
|
||||
{
|
||||
"ts": Date.now(),
|
||||
"values": {
|
||||
"_event":content
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// Msg can be outputted from components only after configuration
|
||||
/*if (canSendErrData()){
|
||||
sendBufferedErrors();
|
||||
} else {
|
||||
bufferError(msg);
|
||||
}*/
|
||||
instance.send(tb_output, msg); // Even if error server is unavailable, send this message to output, for other possible component connections
|
||||
|
||||
}
|
||||
|
||||
|
||||
let ERRWEIGHT = {
|
||||
EMERGENCY: "emergency", // System unusable
|
||||
ALERT: "alert", // Action must be taken immidiately
|
||||
CRITICAL: "critical", // Component unable to function
|
||||
ERROR: "error", // Error, but component able to recover from it
|
||||
WARNING: "warning", // Possibility of error, system running futher
|
||||
NOTICE: "notice", // Significant message but not an error, things user might want to know about
|
||||
INFO: "informational", // Info
|
||||
DEBUG: "debug" // Debug - only if CONFIG.debug is enabled
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
sendError,
|
||||
ERRWEIGHT
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
const ERRWEIGHT = {
|
||||
EMERGENCY: "emergency", // System unusable
|
||||
ALERT: "alert", // Action must be taken immidiately
|
||||
CRITICAL: "critical", // Component unable to function
|
||||
ERROR: "error", // Error, but component able to recover from it
|
||||
WARNING: "warning", // Possibility of error, system running futher
|
||||
NOTICE: "notice", // Significant message but not an error, things user might want to know about
|
||||
INFO: "informational", // Info
|
||||
DEBUG: "debug" // Debug - only if CONFIG.debug is enabled
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
function sendError(func, device, weight, str, extra){
|
||||
if ((weight === ERRWEIGHT.DEBUG) && (instance.CONFIG.debug === false)){
|
||||
return; // Allow debug messages only if CONFIG.debug is active
|
||||
}
|
||||
|
||||
let content = {
|
||||
"type": weight,
|
||||
"status": "new",
|
||||
"source": {
|
||||
"func":func,
|
||||
"component":instance.id,
|
||||
"component_name":instance.name,
|
||||
"edge":myEdge
|
||||
},
|
||||
"message":str,
|
||||
"message_data": extra
|
||||
};
|
||||
let msg = {};
|
||||
msg[device] = [
|
||||
{
|
||||
"ts": Date.now(),
|
||||
"values": {
|
||||
"_event":content
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// Msg can be outputted from components only after configuration
|
||||
/*if (canSendErrData()){
|
||||
sendBufferedErrors();
|
||||
} else {
|
||||
bufferError(msg);
|
||||
}*/
|
||||
instance.send(0, msg); // Even if error server is unavailable, send this message to output, for other possible component connections
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
sendError,
|
||||
ERRWEIGHT,
|
||||
}
|
||||
30
flow/helper/logger.js
Normal file
30
flow/helper/logger.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
//https://github.com/log4js-node/log4js-node/blob/master/examples/example.js
|
||||
//file: { type: 'file', filename: path.join(__dirname, 'log/file.log') }
|
||||
|
||||
var log4js = require("log4js");
|
||||
var path = require('path');
|
||||
|
||||
log4js.configure({
|
||||
appenders: {
|
||||
errLogs: { type: 'file', compress:true, daysToKeep: 2, maxLogSize: 1048576, backups: 1, keepFileExt: true, filename: path.join(__dirname + "/../../", 'err.txt') },
|
||||
monitorLogs: { type: 'file', compress:true, daysToKeep: 2, maxLogSize: 1048576, backups: 1, keepFileExt: true, filename: path.join(__dirname + "/../../", 'monitor.txt') },
|
||||
console: { type: 'console' }
|
||||
},
|
||||
categories: {
|
||||
errLogs: { appenders: ['console', 'errLogs'], level: 'error' },
|
||||
monitorLogs: { appenders: ['console', 'monitorLogs'], level: 'trace' },
|
||||
//another: { appenders: ['console'], level: 'trace' },
|
||||
default: { appenders: ['console'], level: 'trace' }
|
||||
}
|
||||
});
|
||||
|
||||
const errLogger = log4js.getLogger("errLogs");
|
||||
const logger = log4js.getLogger();
|
||||
const monitor = log4js.getLogger("monitorLogs");
|
||||
|
||||
//USAGE
|
||||
//logger.debug("text")
|
||||
//monitor.info('info');
|
||||
//errLogger.error("some error");
|
||||
|
||||
module.exports = { errLogger, logger, monitor };
|
||||
|
|
@ -1,10 +1,6 @@
|
|||
|
||||
const { promisifyBuilder, makeMapFromDbResult } = require('./db_helper.js');
|
||||
const dbNotifications = TABLE("notifications");
|
||||
|
||||
//key is device, value = str
|
||||
let sentValues= {};
|
||||
let notificationsData = {};
|
||||
let notificationsData = null;
|
||||
|
||||
let ERRWEIGHT = {
|
||||
EMERGENCY: "emergency", // System unusable
|
||||
|
|
@ -24,12 +20,9 @@ function getKey(map, val) {
|
|||
//https://stackoverflow.com/questions/41117799/string-interpolation-on-variable
|
||||
var template = (tpl, args) => tpl.replace(/\${(\w+)}/g, (_, v) => args[v]);
|
||||
|
||||
async function initNotifications()
|
||||
{
|
||||
let response = await promisifyBuilder(dbNotifications.find());
|
||||
notificationsData = makeMapFromDbResult(response, "key");
|
||||
|
||||
console.log("initNotifications done" );
|
||||
function initNotification() {
|
||||
notificationsData = FLOW.GLOBALS.notificationsData;
|
||||
}
|
||||
|
||||
function sendNotification(func, device, key, params, extra, tb_output, instance, saveKey) {
|
||||
|
|
@ -39,7 +32,7 @@ function sendNotification(func, device, key, params, extra, tb_output, instance,
|
|||
let storeToSendValues = true;
|
||||
if(saveKey == undefined) storeToSendValues = false;
|
||||
|
||||
let lang = FLOW.OMS_language;
|
||||
let lang = FLOW.GLOBALS.settings.language;
|
||||
if(lang != "en" || lang != "sk") lang = "en";
|
||||
|
||||
let tpl = key;
|
||||
|
|
@ -55,7 +48,8 @@ function sendNotification(func, device, key, params, extra, tb_output, instance,
|
|||
}
|
||||
else
|
||||
{
|
||||
console.error("sendNotification: Notifications: undefined key", key, func, notificationsData);
|
||||
//console.error("sendNotification: Notifications: undefined key", key, func, notificationsData);
|
||||
console.error("sendNotification: Notifications: undefined key", key, func );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +85,7 @@ function sendNotification(func, device, key, params, extra, tb_output, instance,
|
|||
|
||||
if(storeToSendValues) sentValues[saveKey] = tpl;
|
||||
|
||||
let str = FLOW.OMS_rvo_name;
|
||||
let str = FLOW.GLOBALS.settings.rvo_name;
|
||||
if(str != "") str = str + ": ";
|
||||
str = str + tpl;
|
||||
|
||||
|
|
@ -132,6 +126,6 @@ function sendNotification(func, device, key, params, extra, tb_output, instance,
|
|||
|
||||
module.exports = {
|
||||
sendNotification,
|
||||
initNotifications,
|
||||
ERRWEIGHT
|
||||
}
|
||||
ERRWEIGHT,
|
||||
initNotification
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,18 +40,17 @@ async function writeData(port, data, readbytes, timeout){
|
|||
return new Promise((resolve, reject) => {
|
||||
|
||||
// If first item in data array is 255, we just write broadcast command to rsPort
|
||||
// We wait 3 seconds and resolve([ "b", "r", "o", "a", "d", "c", "a", "s", "t" ])
|
||||
// We wait 3 seconds and resolve(["broadcast"])
|
||||
// It is important to resolve with array
|
||||
if(data[0] == 255) {
|
||||
|
||||
port.write(Buffer.from(data), function(err) {
|
||||
if (err) {
|
||||
port.removeListener('data', callback);
|
||||
reject(err.message);
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(resolve, 3000, [ "b", "r", "o", "a", "d", "c", "a", "s", "t" ]);
|
||||
setTimeout(resolve, 3000, ["broadcast"]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue