try using flow2src node to separate flows

This commit is contained in:
JcDenis 2024-04-27 11:54:34 +02:00
parent 018fa9cddd
commit 8d2734e748
14 changed files with 212 additions and 2 deletions

View file

@ -730,7 +730,8 @@
"af148bf44b019b35",
"b961d989c357e6d6",
"2cc2cdcf0b1f710e",
"56d93c268a656fc4"
"56d93c268a656fc4",
"d02f1b2f2c3a2a30"
],
"x": 94,
"y": 3019,
@ -6083,6 +6084,30 @@
"y": 2280,
"wires": []
},
{
"id": "d02f1b2f2c3a2a30",
"type": "comment",
"z": "ab51b1e8cad7b700",
"g": "d1b208e623179a25",
"name": "MQTT nodered base topic must be same as automate name (default is iotredloop)",
"info": "",
"x": 820,
"y": 3120,
"wires": []
},
{
"id": "ff47fafeee1a758e",
"type": "flow2src",
"z": "ab51b1e8cad7b700",
"name": "",
"incFlows": "Kernel,K.Routine",
"incSubflows": "",
"srcFolder": "src",
"chkAutoFlow2Src": true,
"x": 1220,
"y": 60,
"wires": []
},
{
"id": "2623529da72f4fab",
"type": "catch",

View file

@ -6,7 +6,8 @@
"node-red-contrib-msg-speed": "2.1.0",
"node-red-contrib-queue-gate": "1.5.5",
"node-red-contrib-simple-gate": "0.5.2",
"node-red-contrib-stackhero-influxdb-v2": "1.0.4"
"node-red-contrib-stackhero-influxdb-v2": "1.0.4",
"@steveorevo/node-red-flow2src": "1.1.0"
},
"node-red": {
"settings": {

View file

@ -0,0 +1,7 @@
var d = Number(msg.payload);
var h = Math.floor(d / 60);
var m = Math.floor(d % 60);
if (h < 10) { h = h < 5 ? '00' : '0' + h; }
if (m < 10) { m = m < 5 ? '00' : '0' + m; }
msg.payload = h + ':' + m;
return msg;

View file

@ -0,0 +1,42 @@
// Check and recreate clean message of device description
// output 1 : error message
// output 2 : device registration
// script var
var msg = msg;
var newmsg = {};
// no message
if (typeof msg === 'undefined'){
return [null,null];
}
// check possible var existence
if (typeof msg.bucket === 'undefined' ||
typeof msg.measurement === 'undefined' ||
typeof msg.field === 'undefined' ||
typeof msg.format === 'undefined' ||
typeof msg.default === 'undefined'
) {
node.status({
fill: "red", shape: "ring", text: 'undefined device'});
return [msg,null];
}
// recreate msg
newmsg = {
'bucket': msg.bucket,
'measurement': msg.measurement,
'field': msg.field,
'format': msg.format,
'path': msg.bucket + '/' + msg.measurement + '/' + msg.field,
'payload': msg.default,
'protocol': typeof msg.protocol === 'undefined' ? '' : msg.protocol,
'model': typeof msg.model === 'undefined' ? '' : msg.model,
'id': typeof msg.id === 'undefined' ? '' : msg.id,
'option': typeof msg.option === 'undefined' ? 0 : msg.option
};
node.status({ fill: 'green', shape: "ring", text: newmsg.path + ' = ' + newmsg.payload });
return [null,newmsg];

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,50 @@
// output 1 : error message
// output 2 : device registration
// script var
var msg = msg;
var newmsg = {};
// try if msg.topic is a path
if (typeof msg.topic === 'string' &&
typeof msg.bucket === 'undefined' &&
typeof msg.measurement === 'undefined' &&
typeof msg.field === 'undefined'
) {
const device = msg.topic.split('/');
if (typeof device[1] === 'string' &&
typeof device[2] === 'string' &&
typeof device[3] === 'string'
) {
msg.source = device[0];
msg.bucket = device[1];
msg.measurement = device[2];
msg.field = device[3];
}
}
// check var existence
if (typeof msg.bucket === 'undefined' ||
typeof msg.measurement === 'undefined' ||
typeof msg.field === 'undefined'
) {
node.status({
fill: "red", shape: "ring", text: 'undefined device'});
return [msg,null];
}
// recreate msg
newmsg = {
'topic': 'metric',
'source': typeof msg.source === 'string' ? msg.source : 'unknow',
'bucket': msg.bucket,
'measurement': msg.measurement,
'field': msg.field,
'path': msg.bucket + '/' + msg.measurement + '/' + msg.field,
'payload': msg.payload,
'repeat': typeof msg.repeat === 'boolean' ? msg.repeat : false
};
node.status({ fill: 'green', shape: "ring", text: newmsg.source + ' : ' + newmsg.path + ' = ' + newmsg.payload });
return [null,newmsg];

View file

@ -0,0 +1,11 @@
// script var
var msg = msg;
var newmsg = {};
// recreate msg
newmsg = {
'topic':'gate',
'payload':'open'
};
return newmsg;

View file

@ -0,0 +1,11 @@
// script var
var msg = msg;
var newmsg = {};
// recreate msg
newmsg = {
'topic':'gate',
'payload': msg.payload
};
return newmsg;

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

57
src/manifest.json Normal file
View file

@ -0,0 +1,57 @@
[
{
"id": "fabb645e0d88c91c",
"property": "func",
"file": "Kernel/check_device.js"
},
{
"id": "fabb645e0d88c91c",
"property": "initialize",
"file": "Kernel/check_device_initializejs"
},
{
"id": "fabb645e0d88c91c",
"property": "finalize",
"file": "Kernel/check_device_finalizejs"
},
{
"id": "2ba23548e87b0292",
"property": "func",
"file": "Kernel/set_gate_message.js"
},
{
"id": "2ba23548e87b0292",
"property": "initialize",
"file": "Kernel/set_gate_message_initializejs"
},
{
"id": "2ba23548e87b0292",
"property": "finalize",
"file": "Kernel/set_gate_message_finalizejs"
},
{
"id": "82229e46e51f94f5",
"property": "func",
"file": "Kernel/check_metric.js"
},
{
"id": "e6a4e861a99b196c",
"property": "func",
"file": "Kernel/set_gate_message2.js"
},
{
"id": "e6a4e861a99b196c",
"property": "initialize",
"file": "Kernel/set_gate_message2_initializejs"
},
{
"id": "e6a4e861a99b196c",
"property": "finalize",
"file": "Kernel/set_gate_message2_finalizejs"
},
{
"id": "0385dd3208b83d41",
"property": "func",
"file": "K_Routine/minute_to_HH_mm.js"
}
]