-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbridge.html
129 lines (125 loc) · 5.17 KB
/
bridge.html
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
<script src="resources/@sammachin/node-red-matter-bridge/qrcode.min.js"></script>
<script type="text/javascript">
RED.nodes.registerType('matterbridge',{
category: 'config',
defaults: {
name: {},
vendorId : {value: "0xFFF1"},
productId : {value: "0x8000"},
vendorName : {value: "Node-RED-Matter"},
productName : {value: "Node-RED-Bridge"},
storageLocation: {required: true},
networkInterface : {required: true},
logLevel: {value: "ERROR"}
},
label: function() {
return this.name||"Bridge";
},
oneditprepare: function(){
var nodeid=this.id
var selectedInterface = this.networkInterface
var url = '_matterbridge/commisioning/'+nodeid;
$.get(url, function(r) {
if (r.state =='ready'){
let status = document.getElementById('status')
let mpc = r.manualPairingCode
status.innerText = `Manual Pairing Code: ${mpc.slice(0,4)+'-'+mpc.slice(4,7)+"-"+mpc.slice(7,11)}`
var qrcode = new QRCode(document.getElementById('qrcode'), {
text: r.qrPairingCode,
width: 250,
height: 250,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
});
}
else if (r.state == 'commissioned'){
let status = document.getElementById('status')
status.innerText = `Bridge is Commissioned into a fabric`
}
console.log(r)
})
.error(function(e) {
console.log(e.status);
})
$.get('_matterbridge/interfaces', function(r) {
let interfaces = document.getElementById('node-config-input-networkInterface');
r.forEach(i => {
interfaces.add(new Option(i, i));
});
console.log(selectedInterface)
if (typeof selectedInterface !== 'undefined'){
console.log('defined')
interfaces.value = selectedInterface
}
})
.error(function(e) {
console.log(e.status);
})
console.log(this.storageLocation)
if (!this.storageLocation){
$.get('_matterbridge/homedir', function(r) {
defaultLocation=(`${r}/.matter`)
let sLoc = document.getElementById('node-config-input-storageLocation');
sLoc.value = defaultLocation
})
.error(function(e) {
console.log(e.status);
})
}
},
oneditsave: function(){
console.log(this)
}
});
</script>
<script type="text/x-red" data-template-name="matterbridge">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-vendorId">Vendor ID</label>
<input type="text" id="node-config-input-vendorId" placeholder="0xFFF1">
</div>
<div class="form-row">
<label for="node-config-input-vendorName">Vendor Name</label>
<input type="text" id="node-config-input-vendorName" placeholder="Node-RED-Matter">
</div>
<div class="form-row">
<label for="node-config-input-productId">Product ID</label>
<input type="text" id="node-config-input-productId" placeholder="0x8000">
</div>
<div class="form-row">
<label for="node-config-input-productName">Product Name</label>
<input type="text" id="node-config-input-productName" placeholder="Node-RED-Bridge">
</div>
<div class="form-row">
<label for="node-config-input-networkInterface">Network interface</label>
<select type="text" id="node-config-input-networkInterface" style="width:50%;" >
</select>
</div>
<div class="form-row">
<label for="node-config-input-storageLocation">Storage Location</label>
<input type="text" id="node-config-input-storageLocation" style="width:50%;" >
</div>
<div class="form-row">
<label for="node-config-input-logLevel">Log Level</label>
<select type="text" id="node-config-input-logLevel" style="width:50%;" >
<option value="DEBUG">Debug</option>
<option value="INFO">Info</option>
<option value="WARN">Warn</option>
<option value="ERROR">Error</option>
<option value="FATAL">Fatal</option>
</select>
</div>
<div class="form-row">
<div id="qrcode"></div>
<div id="status">
<p>The bridge node must be deployed before it can be commissioned</p>
</div>
</div>
</script>
<script type="text/x-red" data-help-name="matterbridge">
Config Node with the required parameters to setup a bridge
</script>