version 2025-02-01
This commit is contained in:
parent
ef7817bf22
commit
c052887a1f
11 changed files with 368 additions and 700 deletions
|
|
@ -5,7 +5,7 @@ exports.color = '#888600';
|
|||
exports.version = '1.0.2';
|
||||
exports.icon = 'sign-out';
|
||||
exports.input = 2;
|
||||
exports.output = 4;
|
||||
exports.output = 3;
|
||||
exports.options = { host: 'tb-stage.worksys.io', port: 1883, clientid: "", username: "" };
|
||||
|
||||
exports.html = `<div class="padding">
|
||||
|
|
@ -209,19 +209,12 @@ exports.install = function(instance) {
|
|||
instance.send(SEND_TO.rpcCall, {"topic":topic, "content":message });
|
||||
});
|
||||
|
||||
client.on('close', function(err) {
|
||||
client.on('close', function() {
|
||||
clientReady = false;
|
||||
wsmqtt_status = 'disconnected';
|
||||
|
||||
if (err && err.toString().indexOf('Error')) {
|
||||
instance.status("Err: "+err.code, "red");
|
||||
instance.send(SEND_TO.debug, {"message":"Client CLOSE signal received !", "error":err, "opt":opts });
|
||||
} else {
|
||||
instance.status("Disconnected", "red");
|
||||
instance.send(SEND_TO.debug, {"message":"Client CLOSE signal received !", "error":err, "opt":opts });
|
||||
}
|
||||
|
||||
client.reconnect();
|
||||
|
||||
instance.status("Disconnected", "red");
|
||||
instance.send(SEND_TO.debug, {"message":"Client CLOSE signal received !"});
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
|
|
@ -247,22 +240,16 @@ exports.install = function(instance) {
|
|||
|
||||
if(clientReady)
|
||||
{
|
||||
//do we have some data in backup file?
|
||||
//if any, process data from database
|
||||
//do we have some data in backup file? if any, process data from database
|
||||
if(saveTelemetryOnError)
|
||||
{
|
||||
//read telemetry data and send back to server
|
||||
if(!processingData) processDataFromDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
if(clientReady)
|
||||
{
|
||||
|
||||
let stringifiedJson = JSON.stringify(data.data);
|
||||
client.publish("v1/gateway/telemetry", stringifiedJson, {qos: 1});
|
||||
|
||||
instance.send(3, stringifiedJson);
|
||||
|
||||
//backup telemetry
|
||||
if(createTelemetryBackup)
|
||||
{
|
||||
|
|
@ -285,7 +272,6 @@ exports.install = function(instance) {
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
//logger.debug("Client unavailable. Data not sent !", JSON.stringify(data.data));
|
||||
instance.send(SEND_TO.debug, {"message":"Client unavailable. Data not sent !", "data": data.data });
|
||||
|
||||
|
|
@ -298,7 +284,6 @@ exports.install = function(instance) {
|
|||
data.data.id = UID();
|
||||
nosql.insert(data.data);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -445,12 +430,10 @@ exports.install = function(instance) {
|
|||
|
||||
try {
|
||||
|
||||
let o = JSON.parse(JSON.stringify(item));
|
||||
delete o.id;
|
||||
let message = JSON.stringify(o);
|
||||
let message = JSON.parse(JSON.stringify(item));
|
||||
delete message.id;
|
||||
|
||||
client.publish("v1/gateway/telemetry", message, {qos:1});
|
||||
instance.send(3, message);
|
||||
client.publish("v1/gateway/telemetry", JSON.stringify(message), {qos:1});
|
||||
|
||||
//remove from database
|
||||
await promisifyBuilder(nosql.remove().where("id", id));
|
||||
|
|
@ -460,7 +443,6 @@ exports.install = function(instance) {
|
|||
console.log("processDataFromDatabase", error);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue