-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
1949 lines (1694 loc) · 52.9 KB
/
main.js
File metadata and controls
1949 lines (1694 loc) · 52.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const pkg = require('./package.json');
let options;
if (pkg.hasOwnProperty("NRelectron")) { options = pkg["NRelectron"] }
// Setup user directory and flowfile (if editable)
var userdir = __dirname;
var psmid
global.array_config = [];
// Some settings you can edit if you don't set them in package.json
//console.log(options)
const editable = true; // set this to false to create a run only application - no editor/no console
const allowLoadSave = true; // set to true to allow import and export of flow file
const showMap = true; // set to true to add Worldmap to the menu
const kioskMode = false; // set to true to start in kiosk mode
const addNodes = true; // set to false to block installing extra nodes
let flowfile = 'electronflow.json'; // default Flows file name - loaded at start
const urldash = "/ui/#/0" // url for the dashboard page
const urledit = "/red"; // url for the editor page
const urlconsole = "/console.htm"; // url for the console page
const urlmap = "/worldmap"; // url for the worldmap
const nrIcon = "nodered.png" // Icon for the app in root dir (usually 256x256)
let urlStart; // Start on this page
if (options.start.toLowerCase() === "editor") { urlStart = urledit; }
else if (options.start.toLowerCase() === "map") { urlStart = urlmap; }
else { urlStart = urledit }
global.x__ = 200;
global.y__ = 40;
// TCP port to use
//const
/* var a;
a = Math.random() * 16383 + 49152 */ // fix it if you like
const listenPort = "18880"; // or random ephemeral port
const fetch =require('node-fetch');
const os = require('os');
var fs = require('fs');
const url = require('url');
const path = require('path');
const http = require('http');
const express = require("express");
const electron = require('electron');
const isDev = require('electron-is-dev');
const { app, Menu } = electron;
const ipc = electron.ipcMain;
const ipcRenderer =electron.ipcRenderer;
const dialog = electron.dialog;
const BrowserWindow = electron.BrowserWindow;
var RED = require("node-red");
const { element } = require('protractor');
const { dirname } = require('logic-solver');
var red_app = express();
// Add a simple route for static content served from 'public'
red_app.use("/", express.static("web"));
//red_app.use(express.static(__dirname +"/public"));
// Create a server
var server = http.createServer(red_app);
if (editable) {
// if running as raw electron use the current directory (mainly for dev)
if (process.argv[1] && (process.argv[1] === "main.js")) {
userdir = __dirname;
if ((process.argv.length > 2) && (process.argv[process.argv.length - 1].indexOf(".json") > -1)) {
if (path.isAbsolute(process.argv[process.argv.length - 1])) {
flowfile = process.argv[process.argv.length - 1];
}
else {
flowfile = path.join(process.cwd(), process.argv[process.argv.length - 1]);
}
}
}
else { // We set the user directory to be in the users home directory...
userdir = os.homedir() + '/.node-red';
if (!fs.existsSync(userdir)) {
fs.mkdirSync(userdir);
}
if ((process.argv.length > 1) && (process.argv[process.argv.length - 1].indexOf(".json") > -1)) {
if (path.isAbsolute(process.argv[process.argv.length - 1])) {
flowfile = process.argv[process.argv.length - 1];
}
else {
flowfile = path.join(process.cwd(), process.argv[process.argv.length - 1]);
}
}
else {
if (!fs.existsSync(userdir + "/" + flowfile)) {
fs.writeFileSync(userdir + "/" + flowfile, fs.readFileSync(__dirname + "/" + flowfile));
}
let credFile = flowfile.replace(".json", "_cred.json");
if (fs.existsSync(__dirname + "/" + credFile) && !fs.existsSync(userdir + "/" + credFile)) {
fs.writeFileSync(userdir + "/" + credFile, fs.readFileSync(__dirname + "/" + credFile));
}
}
}
}
/*
console.log("CWD",process.cwd());
console.log("DIR",__dirname);
console.log("UserDir :",userdir);
console.log("FlowFile :",flowfile);
console.log("PORT",listenPort); */
// Keep a global reference of the window objects, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
let conWindow;
let appWindow;
let deviceWindow;
let logBuffer = [];
let logBuffer2 = ["a", "b", "c"];
let logLength = 250; // No. of lines of console log to keep.
const levels = ["", "fatal", "error", "warn", "info", "debug", "trace"];
ipc.on('clearLogBuffer', function () { logBuffer = []; });
var config = [];
ipc.on('clearLogBuffer', function (event, arg) { console.log(arg) });
// Create the settings object - see default settings.js file for other options
var settings = {
uiHost: "localhost", // only allow local connections, remove if you want to allow external access
httpAdminRoot: "/red", // set to false to disable editor and deploy
httpNodeRoot: "/",
userDir: userdir,
httpNodeCors: {
origin: "*",
methods: "GET,PUT,POST,DELETE"
},
flowFile: flowfile,
editorTheme: { projects: { enabled: false }, palette: { editable: addNodes } }, // enable projects feature
functionGlobalContext: {}, // enables global context - add extras ehre if you need them
logging: {
websock: {
level: 'info',
metrics: false,
handler: function () {
return function (msg) {
if (editable) { // No logging if not editable
var ts = (new Date(msg.timestamp)).toISOString();
ts = ts.replace("Z", " ").replace("T", " ");
var line = "";
if (msg.type && msg.id) {
line = ts + " : [" + levels[msg.level / 10] + "] [" + msg.type + ":" + msg.id + "] " + msg.msg;
}
else {
line = ts + " : [" + levels[msg.level / 10] + "] " + msg.msg;
}
logBuffer.push(line);
if (conWindow) { conWindow.webContents.send('debugMsg', line); }
if (logBuffer.length > logLength) { logBuffer.shift(); }
}
}
}
}
}
}
if (!editable) {
settings.httpAdminRoot = false;
settings.readOnly = true;
}
// Initialise the runtime with a server and settings
RED.init(server, settings);
// Serve the editor UI from /red (if editable)
if (settings.httpAdminRoot !== false) {
red_app.use(settings.httpAdminRoot, RED.httpAdmin);
}
// Serve the http nodes UI from /
red_app.use(settings.httpNodeRoot, RED.httpNode);
// Create the Application's main menu
const template = [{
label: "View",
submenu: [
{
label: 'Create a new application',
accelerator: "Shift+CmdOrCtrl+H",
click() { createNewApp(); }
},
{
label: 'Import Flow',
accelerator: "Shift+CmdOrCtrl+O",
click() { openFlow(); }
},
{
label: 'Save Flow',
accelerator: "Shift+CmdOrCtrl+S",
click() { saveFlow(); }
},
{ type: 'separator' },
{
label: 'Console',
accelerator: "Shift+CmdOrCtrl+C",
click() { createConsole(); }
},
{
label: 'Dashboard',
accelerator: "Shift+CmdOrCtrl+D",
click() { mainWindow.loadURL("http://localhost:" + listenPort + urldash); }
},
{
label: 'Worldmap',
accelerator: "Shift+CmdOrCtrl+M",
click() { mainWindow.loadURL("http://localhost:" + listenPort + urlmap); }
},
{ type: 'separator' },
{ type: 'separator' },
{
label: 'Documentation',
click() { electron.shell.openExternal('https://nodered.org/docs') }
},
{
label: 'Flows and Nodes',
click() { electron.shell.openExternal('https://flows.nodered.org') }
},
{
label: 'Discourse Forum',
click() { electron.shell.openExternal('https://discourse.nodered.org/') }
},
{ type: 'separator' },
{ role: 'togglefullscreen' },
{ role: 'quit' }
]
}];
if (!showMap) { template[0].submenu.splice(6, 1); }
if (!editable) {
template[0].submenu.splice(3, 1);
template[0].submenu.splice(4, 1);
}
if (!allowLoadSave) { template[0].submenu.splice(0, 2); }
// Top and tail menu on Mac
if (process.platform === 'darwin') {
template[0].submenu.unshift({ type: 'separator' });
template[0].submenu.unshift({ label: "About " + options.productName || "FloWare Framework", selector: "orderFrontStandardAboutPanel:" });
template[0].submenu.unshift({ type: 'separator' });
template[0].submenu.unshift({ type: 'separator' });
}
// Add Dev menu if in dev mode
if (isDev) {
template.push({
label: 'Development',
submenu: [
{
label: 'Editor',
accelerator: "Shift+CmdOrCtrl+E",
click() { mainWindow.loadURL(`http://localhost:${listenPort}${urledit}`); }
},
{
label: 'Refresh', accelerator: 'CmdOrCtrl+R',
click(item, focusedWindow) {
if (focusedWindow) focusedWindow.reload()
}
},
{
label: 'Developer console',
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click(item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.toggleDevTools()
}
}
]
})
}
async function saveFlow() {
const fileName = __dirname;
console.log("\n", fileName)
const options = {
title: 'flow1',
defaultPath: fileName,
filters: [
{ name: 'json', extensions: ['json'] }
],
};
var pathh = dialog.showSaveDialogSync(options);
findPath(pathh);
}
function findPath(pathh) {
if (pathh) {
var flo = JSON.stringify(RED.nodes.getFlows());
var indexinizio = flo.search("flows");
var indexfine = flo.search("}]")
var flow = flo.slice(indexinizio + 7, indexfine + 2) //file settato correttamente
//qui si aggiunge la parte dei dati analizzati nello stesso file
//write a file
fs.writeFile(pathh, flow, function (err) {
if (err) {
dialog.showErrorBox('Error', err);
}
else {
dialog.showMessageBox({
icon: nrIcon,
message: "Flow file saved as\n\n" + pathh,
buttons: ["OK"]
});
}
});
}
}
async function openFlow() {
const options = {
filters: [
{ name: 'json', extensions: ['json'] }
],
};
var filePaths;
filePaths = dialog.showOpenDialogSync(null, options);
await takeFlow(filePaths);
await analyseFlowFile(flowfile);
}
function takeFlow(filePaths) {
if (filePaths && filePaths.length > 0) {
var paths = filePaths.toString();
fs.readFile(paths, 'utf-8', (err, data) => {
try {
var flo = JSON.parse(data);
if (Array.isArray(flo) && (flo.length > 0)) {
RED.nodes.setFlows(flo);
//console.log("flo", flo);
flowfile = flo; //setto come file il file appena importato
mainWindow.loadURL("http://localhost:" + listenPort + urledit);
}
else {
dialog.showErrorBox("Error", "Failed to parse flow file.\n\n " + flo + ".\n\nAre you sure it's a flow file ?");
console.log(err);
}
}
catch (e) {
dialog.showErrorBox("Error", "Failed to load flow file.\n\n " + e);
console.log(e);
}
})
}
}
function deviceAnalisys() {
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, "real-time.html"),
protocol: 'file:',
slashes: true
}))
//conWindow.webContents.openDevTools();
}
// Create the console log window
function createConsole() {
if (conWindow) { conWindow.show(); return; }
// Create the hidden console window
conWindow = new BrowserWindow({
title: "FloWare Console",
width: 700,
height: 500,
icon: path.join(__dirname, nrIcon),
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true
}
});
conWindow.loadURL(url.format({
pathname: path.join(__dirname, urlconsole),
protocol: 'file:',
slashes: true
}))
conWindow.webContents.on('did-finish-load', () => {
conWindow.webContents.send('logBuff', logBuffer);
});
conWindow.on('closed', () => {
conWindow = null;
});
}
function createNewApp() {
if (appWindow) { appWindow.show(); return; }
// Create the hidden console window
appWindow = new BrowserWindow({
title: "Create a new Application",
width: 700,
height: 500,
icon: path.join(__dirname, nrIcon),
autoHideMenuBar: true,
preload: path.join('newapp3.html'),
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
appWindow.loadURL(path.join(__dirname, 'newapp3.html'));
appWindow.on('closed', () => {
appWindow = null;
});
}
var main_name
flo = global.json
var elementi_analizzati = global.array_config
var path_eventi
var result_event;
ipc.on("FloWareConfiguration", async (event, flo,psmid) => {
console.log(psmid)
main_name= flo[0].Name
main_name=main_name.replace(/\s/g, '');
path_eventi="http://pedvalar.webs.upv.es/microservices/system/"+main_name+"/floware/psm/"+psmid+"/events"
response = await fetch(path_eventi, {
method: 'GET',
headers: { Accept: 'application/json', },
});
result_event = (await response.json());
console.log((result_event));
for (elementflo = 0; elementflo < flo.length; elementflo++) {
if (flo[elementflo].Selection == "Selected") {
if ((flo[elementflo]["Device type"] == "Sensor" || flo[elementflo]["Device type"] == "Tag"|| flo[elementflo]["Device type"] == "Actuator" )) {
if((flo[elementflo]["Device type"] == "Sensor" || flo[elementflo]["Device type"] == "Tag")){
global.inp = "in"
}
else{
global.inp="out"
}
Object.keys((flo[elementflo]["Operations"])).forEach(element => {
var id_comment = "159c15f9."
var min = 1
var max = 999999
var r = parseInt(Math.random() * (max - min) + min);
id_comment += r;
var comment;
var comment2;
var vr= "Device Name: "
comment2 = `
{
"id": "${id_comment}",
"type": "comment",
"z": "",
"name": "${vr+flo[elementflo]["Name"]}",
"info": "",
"x":${global.x__},
"y": ${global.y__},
"wires": [[]]
}`
comment2 = JSON.parse(comment2)
elementi_analizzati.push(comment2)
global.y__ +=40;
result_event.forEach(element2 => {
if ((flo[elementflo]["Name"] == element2.device) && (flo[elementflo]["Operations"][element]["Operation Name"] == element2.operation)) {
var min = 1
var max = 999999
var id_comment = "159c15f9."
var r = parseInt(Math.random() * (max - min) + min);
id_comment += r;
var message= "Event condition: "+ element2.device + element2.name+ " "+ element2.operation+" "+ element2.condition
comment = `
{
"id": "${id_comment}",
"type": "comment",
"z": "",
"name": "${message}",
"info": "",
"x":${global.x__},
"y": ${global.y__},
"wires": [[]]
}`
comment = JSON.parse(comment)
elementi_analizzati.push(comment)
// global.y__ += parseInt((Math.random() * (200 - 100) + 100));
global.y__ +=50;
}
});
// console.log((flo[elementflo]["Operations"][element]["Operation Name"], flo[elementflo]["Operations"][element]["Service"]))
if (flo[elementflo]["Operations"][element]["Service"] == "MQTT") {
subm((flo[elementflo]["Operations"][element]["Data Type"]),(flo[elementflo]["Operations"][element]["Operation Name"]), (flo[elementflo]["Operations"][element]["specification"]["QoS"]), (flo[elementflo]["Operations"][element]["specification"]["Topic"]), (flo[elementflo]["Operations"][element]["specification"]["Server Broker"]), (flo[elementflo]["Operations"][element]["specification"]["Port"]));
}
else if (flo[elementflo]["Operations"][element]["Service"] == "UDP") {
set_udp(n, yy, (flo[elementflo]["Operations"][element]["Operation Name"]), global.inp);
}
else if (flo[elementflo]["Operations"][element]["Service"] == "TCP") {
set_tcp(n, yy, (flo[elementflo]["Operations"][element]["Operation Name"]), global.inp);
}
else if (flo[elementflo]["Operations"][element]["Service"] == "WEBSOCKET") {
set_websocket(n, yy, (flo[elementflo]["Operations"][element]["Operation Name"]), global.inp);
}
else if (flo[elementflo]["Operations"][element]["Service"] == "HTTP") {
sub_http((flo[elementflo]["Operations"][element]["Data Type"]),(flo[elementflo]["Operations"][element]["specification"]["Address"]),(flo[elementflo]["Operations"][element]["specification"]["Method"]),(flo[elementflo]["Operations"][element]["Operation Name"]),(flo[elementflo]["Operations"][element]["specification"]["Port"]));
}
else if (flo[elementflo]["Operations"][element]["Service"] == "LoRa") {
set_lora(n, yy, (flo[elementflo]["Operations"][element]["Operation Name"]), global.inp);
}
});
}
}
}
var min = 1
var max = 999999
var r = parseInt(Math.random() * (max - min) + min); //random id file
var id = "41f61d2."
id += r; // z = file_id
var id_tab = `b7abfg80.${r}`
var ui_tab = `
{
"id":"${id_tab}",
"type": "ui_tab",
"z": "",
"tab":"",
"name": "Smart Scenario",
"icon": "dashboard",
"disabled": false,
"hidden": false
}`
ui_tab = JSON.parse(ui_tab)
var initials = `
{"id":"${id}",
"type": "tab",
"label": "Flow ${r}",
"disabled": false,
"info": ""
}
`
initials = JSON.parse(initials)
elementi_analizzati.push(ui_tab)
elementi_analizzati.forEach(element_ => {
if (element_.type == "ui_group") {
element_.tab = id_tab
}
})
elementi_analizzati.push(initials) //deve rimanere in ultima posizione del file
for (var i = 0; i < elementi_analizzati.length - 1; i++) { // must not contain initials!!!
elementi_analizzati[i].z = `${id}`;
}
elementi_analizzati = JSON.stringify(elementi_analizzati)
//console.log(elementi_analizzati)
var random = parseInt(Math.random() * (10000 - 1) + 1)
var paths = `${__dirname}/files`
paths += random
fs.mkdir(paths, function (err) {
if (err) {
console.log('failed to create directory', err);
} else {
fs.writeFile(`${paths}/projectFile${random}.json`, elementi_analizzati, function (err) {
if (err) {
console.log('error writing file', err);
} else {
console.log('writing file succeeded' + `${paths}/projectFile${random}.json`);
}
});
}
});
RED.nodes.setFlows(JSON.parse(elementi_analizzati));
appWindow = null; //not works for now
mainWindow.loadURL("http://localhost:" + listenPort + urledit);
});
global.systems_ = []
ipc.on("system_total", (err, value) => {
global.systems_ = value
})
//console.log(global.array_config)
//ipcRenderer.send("setMyGlobalConfiguration3", global.array_config);
ipc.on("setMyGlobalConfiguration2", (event, mySelectedGlobalValue2) => {
// global.selectedGlobalValue= mySelectedGlobalValue;
//contiene la configurazione del feature model
// scelta dall'utente
global.zz = []
global.zz = mySelectedGlobalValue2
appWindow.loadURL(url.format({
pathname: path.join(__dirname, "./newapp2.html"),
protocol: 'file:',
slashes: true,
}))
});
ipc.on("ping", (event, value) => {
event.reply('ping-reply', global.zz)
})
function create_colleg(node, datatype, x, y) {
global.nodename = node.name
var node = node;
var encr;
var min = 1
var max = 999999
var r = parseInt(Math.random() * (max - min) + min);
global.x__ = parseInt(global.x__)
global.y__ = parseInt(global.y__)
if (global.encrypt_ != null) {
var encr_id = `897696c.${r}`
var decrypt_id = `4567f696c.${r}`
encr =
`{
"id": "${encr_id}",
"type": "decrypt",
"z": "",
"name": "",
"algorithm":"${global.encrypt_}",
"key": "1234",
"x": "${parseInt(x) + 160} ",
"y": "${parseInt(y)}",
"wires": [
[]
]
}`
decr =
`{
"id": "${decrypt_id}",
"type": "encrypt",
"z": "",
"name": "",
"algorithm":"${global.encrypt_}",
"key": "1234",
"x": "${parseInt(x) + 380} ",
"y": "${parseInt(y - 60)}",
"wires": [
[]
]
}`
encr = JSON.parse(encr)
decr = JSON.parse(decr)
if (node.type.includes("in") || (node.type.includes("uplink") || (node.type.includes("request")))) {
node.wires[0].push(encr_id)
}
}
if (datatype == "Numeric") {
var id_json = `82e7263f.${r}`
var id_debug = `2a08c57b.${r}`
var id_chart = `9d19d8fc.${r}`
var id_template = `46dg574s.${r}`;
var id_gauge = `a82ffb36.${r}`;
var id_ui_group = `dca5gfd0.${r}`
var ui_group =
` {
"id": "${id_ui_group}",
"type": "ui_group",
"z": "",
"name": "${node.name}",
"tab": "",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
}`
ui_group = JSON.parse(ui_group)
global.array_config.push(ui_group)
var debug =
` {
"id": "${id_debug}",
"type": "debug",
"z": "",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": ${x + parseInt(610)},
"y":${y - parseInt(20)},
"wires": []
}`
var template =
` {
"id": "${id_template}",
"type": "template",
"z": "",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{{payload.value}}",
"output": "str",
"x": ${x + parseInt(380)},
"y":${y + parseInt(40)},
"wires": [
[
"${id_chart}"
]
]
}`
var json =
` {
"id": "${id_json}",
"type": "json",
"z": "",
"name": "",
"property": "payload",
"action": "obj",
"pretty": true,
"x": ${x + parseInt(370)},
"y":${y},
"wires": [
[
"${id_debug}",
"${id_gauge}",
"${id_template}"
]
]
}`
var chart =
`
{
"id": "${id_chart}",
"type": "ui_chart",
"name":"${node.name} monitoring",
"z": "",
"ymin": "0",
"ymax": "50",
"group": "${id_ui_group}",
"order": 1,
"width": 0,
"height": 0,
"label": "${node.name} chart",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": 1,
"removeOlderPoints": "",
"removeOlderUnit": "3600",
"cutout": 0,
"useOneColor": false,
"useUTC": false,
"colors": [
"#1f77b4",
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"useOldStyle": false,
"outputs": 1,
"x": ${x + parseInt(590)},
"y":${y + parseInt(40)},
"wires": [
[]
]
}`
var gauge =
`{
"id": "${id_gauge}",
"type": "ui_gauge",
"z": "",
"name":"${node.name}",
"group": "${id_ui_group}",
"order": 1,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "",
"label": "",
"format": "{{payload.value}}",
"min": 0,
"max": "40",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": ${x + parseInt(590)},
"y":${y - parseInt(60)},
"wires": []
}`
if (global.encrypt_ != null) {
encr.wires[0].push(id_json)
node.wires[0].push(encr_id)
}
else if (global.encrypt_ == null) {
node.wires[0].push(id_json)
}
chart = JSON.parse(chart)
debug = JSON.parse(debug)
json = JSON.parse(json)
gauge = JSON.parse(gauge)
template = JSON.parse(template)
global.array_config.push(gauge)
global.array_config.push(json)
global.array_config.push(debug)
global.array_config.push(chart)
global.array_config.push(template)
}
else if (datatype == "Boolean") {
x = parseInt(x)
y = parseInt(y)
var id_switch = `82e7263f.${r}`
var id_text = `82erwr3f.${r}`
var id_json = `sdf45dgd.${r}`
var id_json2 = `hrt45gd.${r}`
var id_ui_group = `dca5gfd0.${r}`
var ui_group =
` {
"id": "${id_ui_group}",
"type": "ui_group",
"z": "",
"name": "${node.name}",
"tab": "",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
}`
ui_group = JSON.parse(ui_group)
global.array_config.push(ui_group)
var json =
` {
"id": "${id_json}",
"type": "json",
"z": "",
"name": "",
"property": "payload",
"action": "str",
"pretty": false,
"x": ${x + parseInt(370)},
"y":${y},
"wires": [
[
"${id_text}"
]
]
}`
var json2 =
` {
"id": "${id_json2}",
"type": "json",
"z": "",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": ${x + parseInt(370)},
"y":${y - parseInt(60)},
"wires": [
[
]
]
}`
var switch_ =
` {
"id": "${id_switch}",
"type": "ui_switch",
"z": "",
"name":"${node.name} switch",
"label": "switch",
"tooltip": "",
"group": "${id_ui_group}",
"order": 2,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"x": ${global.x__ + parseInt(110)},
"y":${global,y__ - parseInt(60)},
"wires": [
[
]
]
}`
var ui_text =
` {
"id": "${id_text}",
"type": "ui_text",
"z": "",
"name":"${node.name} state",
"group": "${id_ui_group}",
"order": 1,