-
Notifications
You must be signed in to change notification settings - Fork 2
/
NodeRED_Localization.json
349 lines (348 loc) · 14.4 KB
/
NodeRED_Localization.json
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
[
{
"id": "f6f780f.35cf68",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "8761ae83.294d1",
"type": "function",
"z": "f6f780f.35cf68",
"name": "Convert to GPS-json",
"func": "var msg1 = {};\nif (!msg.payload.hasOwnProperty(\"error\")) {\nif (msg.payload.hasOwnProperty(\"result\")) {\n// processed with Lora Cloud\n msg1.payload = msg.payload;\n msg1.payload.date = Date().toString();\n msg1.payload.lon = msg.payload.result.locationEst.longitude;\n msg1.payload.lat = msg.payload.result.locationEst.latitude;\n msg1.payload.radius = msg.payload.result.locationEst.toleranceHoriz;\n if (msg1.payload.radius > 1000) {\n msg1.payload.radius = 1000\n } \n delete msg1.payload.result;\n delete msg1.payload.warnings;\n}\nif (msg.payload.location) {\n// processed with Google or Here\n msg1.payload = msg.payload;\n msg1.payload.date = Date().toString();\n msg1.payload.lon = msg.payload.location.lng;\n msg1.payload.lat = msg.payload.location.lat;\n\n // processed with Google\n if (msg.payload.accuracy) {\n msg1.payload.radius = msg.payload.accuracy;\n delete msg1.payload.accuracy;\n }\n \n // processed with HERE\n if (msg.payload.location.accuracy) {\n msg1.payload.radius = msg.payload.location.accuracy;\n }\n delete msg1.payload.location;\n}\n msg1.payload.layer = \"Current Location\";\n msg1.payload.name = \"My Wemos Node\";\n msg1.payload.icon=\"user\";\n msg1.payload.iconColor=\"blue\";\n}\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"x": 160,
"y": 580,
"wires": [
[
"51c36e75.440478",
"b5f4ab10.31acb",
"7452809.82f5d8",
"40ebfec6.21fd1"
]
],
"info": "This node will convert location input to coordinates for the worldmap node. LoRaCloud has a different format, so this will be converted. Every service gets it's own icon and colour."
},
{
"id": "7452809.82f5d8",
"type": "function",
"z": "f6f780f.35cf68",
"name": "Convert to TrackLine",
"func": "var msg1 = {};\nif (msg.payload) {\n msg1.payload = msg.payload;\n\n msg1.payload.layer = \"Track\";\n msg1.payload.name = \"Track line\";\n \n delete msg1.payload.radius;\n}\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"x": 620,
"y": 660,
"wires": [
[
"31d448ab.ba43e"
]
]
},
{
"id": "40ebfec6.21fd1",
"type": "function",
"z": "f6f780f.35cf68",
"name": "Convert to TrackPins",
"func": "var msg1 = {};\nif (msg.payload) {\n msg1.payload=msg.payload;\n\n msg1.payload.layer = \"Pins\";\n msg1.payload.iconColor = \"green\";\n msg1.payload.icon = \"map-pin\";\n msg1.payload.name=Date().toString();\n \n delete msg1.payload.radius;\n}\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"x": 620,
"y": 600,
"wires": [
[]
]
},
{
"id": "b5f4ab10.31acb",
"type": "function",
"z": "f6f780f.35cf68",
"name": "Convert to Worldmap",
"func": "var msg1 = {};\nif (msg.payload) {\n msg1.payload=msg.payload;\n\n delete msg1.payload.radius;\n}\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"x": 620,
"y": 540,
"wires": [
[
"655a0509.b6678c"
]
]
},
{
"id": "db8dc3bf.0cc52",
"type": "http request",
"z": "f6f780f.35cf68",
"name": "",
"method": "use",
"ret": "txt",
"url": "",
"tls": "",
"x": 670,
"y": 100,
"wires": [
[
"a69004b7.ee23a8"
]
]
},
{
"id": "a69004b7.ee23a8",
"type": "json",
"z": "f6f780f.35cf68",
"name": "Convert to JSON",
"pretty": false,
"x": 410,
"y": 260,
"wires": [
[
"a843e17b.92081",
"dac46196.80563"
]
]
},
{
"id": "5fe29f6e.c08d2",
"type": "mqtt in",
"z": "f6f780f.35cf68",
"name": "wemos_localization",
"topic": "<app-id>/devices/<device-id>/up",
"qos": "2",
"datatype": "json",
"broker": "5f6d0e3f.7d112",
"x": 110,
"y": 100,
"wires": [
[
"d4ad022b.05ff7",
"1b6fb6b.c7b45c9",
"b6f4d759.15081",
"a1b74ca0.e7346"
]
]
},
{
"id": "1b6fb6b.c7b45c9",
"type": "function",
"z": "f6f780f.35cf68",
"name": "Ask HERE Geolocation API",
"func": "var here_apikey = \"<FILL_IN_YOUR_HERE_API_KEY>\"\n\nvar dev_url = \"https://pos.ls.hereapi.com/positioning/v1/locate?apiKey=\"+here_apikey;\n\nvar data = {\n \"wlan\": []\n };\n\nif (msg.payload.payload_fields.macaddress.mac_1) {\n\tdata[\"wlan\"][0] = {\n\t\t\t\t\"mac\": msg.payload.payload_fields.macaddress.mac_1,\n\t\t\t\t\"powrx\": msg.payload.payload_fields.macaddress.rssi_1,\n\t\t\t\t};\n}\n\nif (msg.payload.payload_fields.macaddress.mac_2) {\n\tdata[\"wlan\"][1] = {\n\t\t\t\t\"mac\": msg.payload.payload_fields.macaddress.mac_2,\n\t\t\t\t\"powrx\": msg.payload.payload_fields.macaddress.rssi_2,\n\t\t\t\t};\n}\nif (msg.payload.payload_fields.macaddress.mac_3) {\n\tdata[\"wlan\"][2] = {\n\t\t\t\t\"mac\": msg.payload.payload_fields.macaddress.mac_3,\n\t\t\t\t\"powrx\": msg.payload.payload_fields.macaddress.rssi_3,\n\t\t\t\t};\n}\n\n\nvar NewMsg = {\n \"method\" : \"POST\",\n \"url\" : dev_url,\n \"headers\" : {\n \"Content-Type\": \"application/json\"\n },\n \"payload\" : JSON.stringify(data)\n };\n\nreturn NewMsg;\n\n",
"outputs": 1,
"noerr": 0,
"x": 380,
"y": 160,
"wires": [
[
"db8dc3bf.0cc52"
]
]
},
{
"id": "655a0509.b6678c",
"type": "worldmap",
"z": "f6f780f.35cf68",
"name": "LoRaWANgeolocation",
"lat": "52.211825",
"lon": "5.966469",
"zoom": "",
"layer": "OSM",
"cluster": "",
"maxage": "12000",
"usermenu": "show",
"layers": "show",
"panit": "true",
"hiderightclick": "false",
"coords": "none",
"path": "worldmap",
"x": 960,
"y": 600,
"wires": []
},
{
"id": "31d448ab.ba43e",
"type": "worldmap-tracks",
"z": "f6f780f.35cf68",
"name": "Map Track",
"depth": "200",
"x": 690,
"y": 740,
"wires": [
[
"655a0509.b6678c"
]
]
},
{
"id": "a843e17b.92081",
"type": "debug",
"z": "f6f780f.35cf68",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 670,
"y": 240,
"wires": []
},
{
"id": "51c36e75.440478",
"type": "debug",
"z": "f6f780f.35cf68",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 150,
"y": 660,
"wires": []
},
{
"id": "d4ad022b.05ff7",
"type": "function",
"z": "f6f780f.35cf68",
"name": "Ask Google Geolocation API",
"func": "var google_apikey = \"<FILL_IN_YOUR_GOOGLE_API_KEY>\";\nvar dev_url = \"https://www.googleapis.com/geolocation/v1/geolocate?key=\"+google_apikey;\n\nvar data = {\n \"considerIp\": \"false\",\n \"wifiAccessPoints\": []\n };\n\nif (msg.payload.payload_fields.macaddress.mac_1) {\n\tdata[\"wifiAccessPoints\"][0] = {\n\t\t\t\t\"macAddress\": msg.payload.payload_fields.macaddress.mac_1,\n\t\t\t\t\"signalStrength\": msg.payload.payload_fields.macaddress.rssi_1\n\t\t\t\t};\n}\n\nif (msg.payload.payload_fields.macaddress.mac_2) {\n\tdata[\"wifiAccessPoints\"][1] = {\n\t\t\t\t\"macAddress\": msg.payload.payload_fields.macaddress.mac_2,\n\t\t\t\t\"signalStrength\": msg.payload.payload_fields.macaddress.rssi_2\n\t\t\t\t};\n}\n\nif (msg.payload.payload_fields.macaddress.mac_3) {\n\tdata[\"wifiAccessPoints\"][2] = {\n\t\t\t\t\"macAddress\": msg.payload.payload_fields.macaddress.mac_3,\n\t\t\t\t\"signalStrength\": msg.payload.payload_fields.macaddress.rssi_3\n\t\t\t\t};\n}\n\nvar NewMsg = {\n \"method\" : \"POST\",\n \"url\" : dev_url,\n \"headers\" : {\n \"Content-Type\": \"application/json\"\n },\n \"payload\" : JSON.stringify(data)\n };\n\nreturn NewMsg;",
"outputs": 1,
"noerr": 0,
"x": 380,
"y": 100,
"wires": [
[
"db8dc3bf.0cc52"
]
]
},
{
"id": "b6f4d759.15081",
"type": "function",
"z": "f6f780f.35cf68",
"name": "Ask LoRa Cloud geolocation API",
"func": "var loracloud_token = \"<FILL_IN_YOUR_LORACLOUD_API_KEY>\";\nvar dev_url = \"https://gls.loracloud.com/api/v3/solve/singleframe\";\n\nvar data = {\n \"gateways\": [],\n \"frame\":[]\n };\n\n// Send all individual values from struc to MQTT with corresponding topic\nvar dataIterator = 0;\nfor (var key in msg.payload.metadata.gateways){\n// var noFieldMissing = true;\nif(!msg.payload.metadata.gateways[key].hasOwnProperty('gtw_id')){\n break;\n }\nif(!msg.payload.metadata.gateways[key].hasOwnProperty('latitude')){\n break;\n }\n if(!typeof msg.payload.metadata.gateways[key].hasOwnProperty('longitude')){\n break;\n }\n if(!typeof msg.payload.metadata.gateways[key].hasOwnProperty('altitude')){\n break;\n }\n \n // When all required fields are available, add gateway for reporting,\n data[\"gateways\"][dataIterator] = {\n\t\t\"gatewayId\": msg.payload.metadata.gateways[dataIterator].gtw_id,\n\t\t\"latitude\": msg.payload.metadata.gateways[dataIterator].latitude,\n\t\t\"longitude\": msg.payload.metadata.gateways[dataIterator].longitude,\n\t\t\"altitude\": msg.payload.metadata.gateways[dataIterator].altitude,\n\t};\n\n\tdataIterator++;\n}\n\n//Send all individual values from struc to MQTT with corresponding topic\ndataIterator = 0;\nfor (key in msg.payload.metadata.gateways){\n// noFieldMissing = true;\n if(!msg.payload.metadata.gateways[key].hasOwnProperty('gtw_id')) {\n break;\n }\n if(!msg.payload.metadata.gateways[key].hasOwnProperty('latitude')) {\n break;\n }\n if(!typeof msg.payload.metadata.gateways[key].hasOwnProperty('longitude')) {\n break;\n }\n if(!typeof msg.payload.metadata.gateways[key].hasOwnProperty('altitude')) {\n break;\n }\n \n // When all required fields are available, add gateway for reporting,\n data[\"frame\"][dataIterator] = [\n msg.payload.metadata.gateways[key].gtw_id,\n msg.payload.metadata.gateways[key].rf_chain,\n msg.payload.metadata.gateways[key].timestamp,\n msg.payload.metadata.gateways[key].rssi,\n msg.payload.metadata.gateways[key].snr\n ]\n\t\n\tdataIterator++;\n}\n\nvar NewMsg = {\n \"method\" : \"POST\",\n \"url\" : dev_url,\n \"headers\" : {\n \"Ocp-Apim-Subscription-Key\" : loracloud_token,\n \"Content-Type\": \"application/json\"\n },\n \"payload\" : JSON.stringify(data)\n};\n\nreturn NewMsg;\n",
"outputs": 1,
"noerr": 0,
"x": 400,
"y": 40,
"wires": [
[
"db8dc3bf.0cc52"
]
]
},
{
"id": "dac46196.80563",
"type": "switch",
"z": "f6f780f.35cf68",
"name": "Check HERE not found",
"property": "payload.error.code",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "404",
"vt": "str"
},
{
"t": "eq",
"v": "400",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 270,
"y": 360,
"wires": [
[
"18bc772.10c0989"
],
[
"8d9c1a1f.aeaa98"
],
[
"8761ae83.294d1"
]
]
},
{
"id": "18bc772.10c0989",
"type": "debug",
"z": "f6f780f.35cf68",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.error.description",
"targetType": "msg",
"x": 610,
"y": 340,
"wires": []
},
{
"id": "8d9c1a1f.aeaa98",
"type": "debug",
"z": "f6f780f.35cf68",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.error.message",
"targetType": "msg",
"x": 600,
"y": 380,
"wires": []
},
{
"id": "a1b74ca0.e7346",
"type": "debug",
"z": "f6f780f.35cf68",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 110,
"y": 180,
"wires": []
},
{
"id": "5f6d0e3f.7d112",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "mqtt://eu.thethings.network",
"port": "1990",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": ""
}
]