-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
78 lines (67 loc) · 1.9 KB
/
app.js
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
/* global process */
var http = require('http');
var express = require('express');
var RED = require('node-red');
var request = require('request');
var app = express();
app.use('/', express.static('public'));
var server = http.createServer(app);
var settings = {
httpAdminRoot: "/red",
httpNodeRoot: "/api",
userDir: './.nodered',
functionGlobalContext: {}
};
RED.init(server, settings);
app.use(settings.httpAdminRoot, RED.httpAdmin);
app.use(settings.httpNodeRoot, RED.httpNode);
server.listen(8000);
RED.start().then(initFlows);
function initFlows() {
//READ From DB.
var flows = [
{
"id": "d01ade6a.afa7e",
"type": "mqtt-broker",
"broker": "localhost",
"port": "1883",
"clientid": "client1",
//how can I pass credentials here in flow array?!!
"credentials": {
"user": "client1",
"password": "pass1"
}
},
{
"id": "459e1943.d0745",
"type": "mqtt in",
"name": "test_topic",
"topic": "test_topic",
"broker": "d01ade6a.afa7e",
"x": 231, "y": 198, "z": "4a8212ad.6b8304",
"wires": [["55e90008.0d6238"]]
},
{
"id": "55e90008.0d6238",
"type": "debug",
"name": "",
"active": true,
"console": "false",
"complete": "false",
"x": 450, "y": 199, "z": "4a8212ad.6b8304",
"wires": []
}
];
var flowOpt = {
url : 'http://localhost:8000/red/flows',
method : 'POST',
body : JSON.stringify(flows),
headers : {
'Content-type' : 'application/json',
'Node-RED-Deployment-Type' : 'full'
}
};
request(flowOpt, function (err, res, body) {
// do other stuff ...
});
}