Wiki source code of Demo for Smart Office, Factory

Version 49.1 by Hera Guo on 2024/11/07 09:55

Hide last authors
Hera Guo 11.1 1 **Table of Contents:**
2
3 {{toc/}}
4
5
6
7
Chxy 2.1 8 = 1. About this demo =
9
10 This demo is to show the installation for various sensors in Dragino Office, Dragino Facotry & ThingsEye Office. It covers various types of sensors such as Temperature, Humidity, CO2, Water Flow, Vibration & many many.
11
12 User can check this [[Public Share Link>>https://thingseye.io/dashboard/d17f70f0-6b5f-11ef-a329-6fb88c149adb?publicId=33180810-5c40-11ef-a329-6fb88c149adb ]] and see the dash board for this demo. The dash board keeps updating, while the main structure will keep the same. It has **Three Level DashBoard **as decribe below.
13
14 * **First Level - Overview for all branches**: This dashboard shows all branches overview status and location.
15 * **Second Level - Branch Level**: This dashboard shows all sensors installation and status in the selected branch.
16 * **Third Level - Sensor Level**: This dashboard shows the detail reading for a specify sensor
17
Chxy 4.1 18 [[image:Level1.png||height="133" width="298"]] [[image:Arrow.png||height="27" width="51"]] [[image:Level2.png||height="134" width="264"]][[image:Arrow.png||height="27" width="51"]] [[image:2024-09-26 23-47-06.png||height="130" width="256"]]
Chxy 5.1 19
20
21 The rest of this chapter will provide the introduction for how to set up similiar solution.
22
23
Hera Guo 15.1 24 = 2.Basic configuration instructions =
Chxy 5.1 25
Hera Guo 14.1 26 When you start a complex IoT project, you first need to learn some basic configuration methods for ThingsEye.
Chxy 5.1 27
Hera Guo 14.1 28 Here are some instructions you need to know:
Chxy 5.1 29
Hera Guo 14.1 30 Dashboard creation and some basic configurations:[[https:~~/~~/wiki.thingseye.io/xwiki/bin/view/Main/How%20to%20import%20and%20use%20the%20dashboard%3F/#H3.2.2.1CreatA0alarm>>https://wiki.thingseye.io/xwiki/bin/view/Main/How%20to%20import%20and%20use%20the%20dashboard%3F/#H3.2.2.1CreatA0alarm]]
Chxy 5.1 31
Hera Guo 15.1 32 Rule chain creation:[[https:~~/~~/wiki.thingseye.io/xwiki/bin/view/Main/Basic%20configuration%20of%20rule%20chains>>https://wiki.thingseye.io/xwiki/bin/view/Main/Basic%20configuration%20of%20rule%20chains/]]
Chxy 5.1 33
Hera Guo 14.1 34 Devices connected to thingseye:[[https:~~/~~/wiki.thingseye.io/xwiki/bin/view/Main/How%20to%20connect%20my%20devices%20to%20ThingsEye%3F/>>https://wiki.thingseye.io/xwiki/bin/view/Main/How%20to%20connect%20my%20devices%20to%20ThingsEye%3F/]]
Chxy 5.1 35
Hera Guo 15.1 36 = 3.overview =
Chxy 5.1 37
Hera Guo 15.1 38 == 3.1 MHierarchical architectureore features ==
39
40 Before we start a project, we first need to understand the organizational structure of the project. Only with a clear outline can our project construction process be smoother
41
42 **Assets:**Dragino Office  、Dragino Factory
43
44 **Devices:**
45
46 Dragino Factory:temperature and humidity measurement×7、Gateway×1
47
48 Dragino Office:temperature and humidity measurement×2、Air quality measurement×4
49
50 == 3.2 Dashboard architecture ==
51
52 In this demo, the dashboard is divided into three layers, namely: home page, asset, and device.
53
54 **home page:**It includes three parts: map, asset list, and all alarm. From this interface, you can see how many factories, offices, and so on there are
55
56 **asset:**It includes three parts: asset map, device list, and asset alarm. From this interface, you can see how many sensors are deployed in the office or project, where they are located, and their alarm status
57
58 **device:**This section displays the specific information collected by the device, and different types of sensors have different display interfaces
59
Hera Guo 20.1 60 [[image:屏幕截图 2024-11-04 134645.png]]
Hera Guo 15.1 61
62 First floor:
63
64 [[image:1730702565889-204.png||height="771" width="1445"]]
65
66 Second floor:
67
68 [[image:1730702622551-808.png||height="756" width="1450"]]
69
70 Third floor:
71
72 [[image:1730702656725-496.png||height="775" width="1455"]]
73
74 [[image:1730702814435-805.png||height="797" width="1458"]]
75
76
77 [[image:1730702688377-367.png||height="770" width="1462"]]
78
79 * How many types of devices do you need, how many layers of third level dashboards you need to create.
80
81 == 3.3 Alarm rules ==
82
83 High Temperature、Low Temperature、High humidity、Low humidity、Low voltage、Device Disconnected
84
Hera Guo 33.1 85 [[image:屏幕截图 2024-11-04 135045.png]]
Hera Guo 15.1 86
87 = 4.configuration details =
88
89 After understanding the architecture and layering of the complete project, we can start configuring it
90
91 == 4.1 Dashboard configuration details ==
92
Hera Guo 16.1 93 === 4.1.1.Data source (Entity aliases) ===
94
Hera Guo 20.1 95 detail:Obtain data based on dashboard status
Hera Guo 16.1 96
Hera Guo 18.1 97 [[image:1730709424998-915.png||height="729" width="1436"]]
Hera Guo 16.1 98
Hera Guo 20.1 99 Alarm:Obtain alarm information
Hera Guo 16.1 100
Hera Guo 18.1 101 [[image:1730709479828-595.png||height="696" width="1435"]]
Hera Guo 16.1 102
Hera Guo 20.1 103 Dragino&GXHL,Ltd:Obtain data through asset types
Hera Guo 16.1 104
Hera Guo 18.1 105 [[image:1730709511861-439.png||height="714" width="1435"]]
Hera Guo 16.1 106
Hera Guo 20.1 107 Selected Supermarket:Retrieve devices by device type
Hera Guo 16.1 108
Hera Guo 18.1 109 [[image:1730709527720-418.png||height="751" width="1433"]]
Hera Guo 16.1 110
Hera Guo 20.1 111 Supermarket Devices:Obtain data through device type
Hera Guo 16.1 112
Hera Guo 20.1 113 [[image:1730709555797-383.png||height="726" width="1434"]]
Hera Guo 16.1 114
Hera Guo 20.1 115 LHT65N Device:Obtain data based on device type
Hera Guo 16.1 116
Hera Guo 20.1 117 [[image:1730857191863-514.png||height="725" width="1433"]]
Hera Guo 16.1 118
119 === 4.1.2.Page Configuration ===
120
Hera Guo 19.1 121 ==== 4.1.2.1、Configure the interface of the third layer Davies. ====
Hera Guo 15.1 122
Hera Guo 19.1 123 ==== 4.1.2.2、Configure the interface of the second layer asset ====
Hera Guo 15.1 124
Hera Guo 20.1 125 ===== 4.1.2.2.1 Equipment distribution diagram: =====
Hera Guo 15.1 126
Hera Guo 19.1 127 **Data:**
Hera Guo 15.1 128
Hera Guo 19.1 129 [[image:1730770392454-317.png||height="745" width="1439"]]
Hera Guo 15.1 130
Hera Guo 20.1 131 **Appearannce:**In this module, we need to arrange our devices in the corresponding positions and use icons to display our devices. Therefore, in the Appearance interface, we need to configure them
Hera Guo 19.1 132
Hera Guo 20.1 133 **Tooltip function:**This module displays the current information of the device
134
135 [[image:1730857537965-184.png]]
136
Hera Guo 19.1 137 {{code language="none"}}
138 var msg = data
139 if(msg.Label=="gateway" && msg.type == "gateway"){
140 var stauts
141 if (msg.gatewaystauts=="true"){
142 stauts = "Connect"
143 }
144 else{
145 stauts = "Disconnected"
146 }
147 var str = "<b>"+msg.entityName+"</b><br/><b>"+stauts+"</b><br/>"
148 return str
149 }
150 else if(msg.type=="gxhl01" && msg.Label!="gateway"){
151 var str = "<b>"+msg.entityName+"</b><br/><b>"+msg.Label+"</b><br/><b>Bat:</b>"+msg.BatV+"V<br/><b>Temperature:</b>"+ msg.TempC_SHT+ "°C<br/><b>Humidity:</b>"+msg.Hum_SHT+"%"
152 return str
153 }
154 else{
155 var str = "<b>"+msg.entityName+"</b><br/><b>"+msg.Label+"</b><br/><b>Bat:</b>"+msg.BatV+"V<br/><b>Temperature:</b>"+ msg.temperature+ "°C<br/><b>Humidity:"+msg.humidity+"%"+"</b><br/>"+
156 "<b>Co2:"+msg.co2+"</b></br><b>Air_Pressure:"+msg.air_pressure
157
158 return str
159 }
160 {{/code}}
161
Hera Guo 20.1 162 (% class="wikigeneratedid" id="HMarkerimagefunctionFF1A" %)
163 **Marker image function:**This module can display different icons based on different types of sensors and their status to achieve its functionality
Hera Guo 19.1 164
Hera Guo 20.1 165 (% class="wikigeneratedid" %)
166 [[image:1730857750749-240.png]]
167
Hera Guo 19.1 168 {{code language="none"}}
169 var res
170 var msg = data
171 if(msg.Label=="gateway" && msg.type=="gateway"){
172 if (msg.gatewaystauts == "true"){
173 res = {
174 url: images[3],
175 size: 40
176 }
177 }
178 else{
179 res = {
180 url: images[2],
181 size: 40
182 }
183 }}
184 else if(msg.Label!="gateway" && msg.type=="gxhl01" ){
185 if (msg.active=="false"){
186 res = {
187 url: images[1],
188 size: 40
189 }}
190 else{
191 res = {
192 url: images[0],
193 size: 40
194 }
195 }
196 }
197 else if(msg.type=="LWL02"){
198 if (msg.WATER_LEAK_STATUS=="0"){
199 res = {
200 url: images[6],
201 size: 40
202 }}
203 else{
204 res = {
205 url: images[7],
206 size: 40
207 }
208 }
209 }
210 else if(msg.type=="LDS02"){
211 if (msg.DOOR_OPEN_STATUS=="0"){
212 res = {
213 url: images[5],
214 size: 40
215 }}
216 else{
217 res = {
218 url: images[8],
219 size: 40
220 }
221 }
222 }
223 else if(msg.type=="LDS12"){
224 res = {
225 url: images[10],
226 size: 40
227 }}
228 else if(msg.type=="SE01"){
229 res = {
230 url: images[9],
231 size: 40
232 }}
233 else if(msg.type=="PB01"){
234 res = {
235 url: images[11],
236 size: 40
237 }}
238 else if(msg.type=="S31b"){
239 res = {
240 url: images[12],
241 size: 40
242 }}
243 else if(msg.type=="LHT65N"){
244 res = {
245 url: images[13],
246 size: 40
247 }}
248 else{
249 res = {
250 url: images[4],
251 size: 40
252 }
253 }
254 return res;
255 {{/code}}
256
Hera Guo 35.1 257 (% class="wikigeneratedid" %)
258 [[image:1730770875793-351.png]]
Hera Guo 19.1 259
Hera Guo 36.1 260 (% class="wikigeneratedid" %)
261 **Actions:**We need to implement the function of entering the details interface through the corresponding device icon, so in this module, we need to add actions to achieve redirection
262
Hera Guo 19.1 263 {{code language="none"}}
264 var entitySubType;
265 var $injector = widgetContext.$scope.$injector;
266 $injector.get(widgetContext.servicesMap.get('entityService')).getEntity(entityId.entityType, entityId.id)
267 .subscribe(function(data) {
268 entitySubType = data.type;
269 console.log(entitySubType)
270 if (entitySubType == 'gateway') {
271 openDashboardStates('gateway_detail');
272 } else if (entitySubType == 'gxhl01') {
273 openDashboardStates('detail');
274 }
275 else if(entitySubType == 'AQS01-dragino-office'){
276 openDashboardStates("aqs01_detail")
277 }
278 else if (entitySubType == 'LDS12') {
279 openDashboardStates('lds12_detail');
280 }
281 else if (entitySubType == 'LDS02') {
282 openDashboardStates('lds02_detail');
283 }
284 else if (entitySubType == 'SE01') {
285 openDashboardStates('se01_detail');
286 }
287 else if (entitySubType == 'PB01') {
288 openDashboardStates('pb01_detail');
289 }
290 else if (entitySubType == 'LWL02') {
291 openDashboardStates('lwl02_detail');
292 }
293 else if (entitySubType == 'LPS8N') {
294 openDashboardStates('lps8n_detail');
295 }
296 else if (entitySubType == 'LHT65N') {
297 openDashboardStates('lht65n_detail');
298 }
299 else if (entitySubType == 'S31b') {
300 openDashboardStates('s31b_detail');
301 }
302 });
303
304 function openDashboardStates(statedId) {
305 var stateParams = widgetContext.stateController.getStateParams();
306 var params = {
307 entityId: entityId,
308 entityName: entityName
309 };
310
311 if (stateParams.city) {
312 params.city = stateParams.city;
313 }
314
315 widgetContext.stateController.openState(statedId, params, false);
316 }
317
318 {{/code}}
319
320 [[image:1730771103096-522.png]]
321
Hera Guo 20.1 322 ===== 4.1.2.2.2 Device List =====
Hera Guo 19.1 323
Hera Guo 26.1 324 (% class="wikigeneratedid" id="HDataFF1A" %)
325 **Data:**
Hera Guo 19.1 326
327 [[image:1730771199343-553.png]]
328
Hera Guo 20.1 329 **Actions:**Equipment distribution diagram: In this module, functions need to be implemented such as adding devices, editing devices, deleting devices, and jumping to the device details page. Therefore, the following actions need to be added:
Hera Guo 19.1 330
331 [[image:1730771228766-212.png]]
332
Hera Guo 20.1 333 (% class="wikigeneratedid" id="HEditdeviceFF1A" %)
Hera Guo 38.1 334 **Edit device:**Implementation function: Device editing
Hera Guo 19.1 335
Hera Guo 20.1 336 [[image:1730771256045-238.png]]
337
Hera Guo 19.1 338 {{code language="none"}}
339 let $injector = widgetContext.$scope.$injector;
340 let customDialog = $injector.get(widgetContext.servicesMap.get('customDialog'));
341 let deviceService = $injector.get(widgetContext.servicesMap.get('deviceService'));
342 let attributeService = $injector.get(widgetContext.servicesMap.get('attributeService'));
343
344 openEditDeviceDialog();
345
346 function openEditDeviceDialog() {
347 customDialog.customDialog(htmlTemplate, EditDeviceDialogController).subscribe();
348 }
349
350 function EditDeviceDialogController(instance) {
351 let vm = instance;
352
353 vm.device = null;
354 vm.attributes = {};
355
356 vm.editDeviceFormGroup = vm.fb.group({
357 deviceName: ['', [vm.validators.required]],
358 deviceType: ['', [vm.validators.required]],
359 deviceLabel: [''],
360 attributes: vm.fb.group({
361 latitude: [null],
362 longitude: [null]
363 })
364 });
365
366 vm.cancel = function() {
367 vm.dialogRef.close(null);
368 };
369
370 vm.save = function() {
371 vm.editDeviceFormGroup.markAsPristine();
372 if (vm.editDeviceFormGroup.get('deviceType').value !== vm.device.type) {
373 delete vm.device.deviceProfileId;
374 }
375 vm.device.name = vm.editDeviceFormGroup.get('deviceName').value,
376 vm.device.type = vm.editDeviceFormGroup.get('deviceType').value,
377 vm.device.label = vm.editDeviceFormGroup.get('deviceLabel').value
378 deviceService.saveDevice(vm.device).subscribe(
379 function () {
380 saveAttributes().subscribe(
381 function () {
382 widgetContext.updateAliases();
383 vm.dialogRef.close(null);
384 }
385 );
386 }
387 );
388 };
389
390 getEntityInfo();
391
392 function getEntityInfo() {
393 deviceService.getDevice(entityId.id).subscribe(
394 function (device) {
395 attributeService.getEntityAttributes(entityId, 'SERVER_SCOPE',
396 ['latitude', 'longitude']).subscribe(
397 function (attributes) {
398 for (let i = 0; i < attributes.length; i++) {
399 vm.attributes[attributes[i].key] = attributes[i].value;
400 }
401 vm.device = device;
402 vm.editDeviceFormGroup.patchValue(
403 {
404 deviceName: vm.device.name,
405 deviceType: vm.device.type,
406 deviceLabel: vm.device.label,
407 attributes: {
408 latitude: vm.attributes.latitude,
409 longitude: vm.attributes.longitude
410 }
411 }, {emitEvent: false}
412 );
413 }
414 );
415 }
416 );
417 }
418
419 function saveAttributes() {
420 let attributes = vm.editDeviceFormGroup.get('attributes').value;
421 let attributesArray = [];
422 for (let key in attributes) {
423 attributesArray.push({key: key, value: attributes[key]});
424 }
425 if (attributesArray.length > 0) {
426 return attributeService.saveEntityAttributes(entityId, 'SERVER_SCOPE', attributesArray);
427 } else {
428 return widgetContext.rxjs.of([]);
429 }
430 }
431 }
432 {{/code}}
433
Hera Guo 40.1 434 **Delete device:**Implementation function: Device deletion
435
Hera Guo 20.1 436 [[image:1730771318657-502.png]]
437
Hera Guo 19.1 438 {{code language="none"}}
439 let $injector = widgetContext.$scope.$injector;
440 let dialogs = $injector.get(widgetContext.servicesMap.get('dialogs'));
441 let deviceService = $injector.get(widgetContext.servicesMap.get('deviceService'));
442
443 openDeleteDeviceDialog();
444
445 function openDeleteDeviceDialog() {
446 let title = "Are you sure you want to delete the device " + entityName + "?";
447 let content = "Be careful, after the confirmation, the device and all related data will become unrecoverable!";
448 dialogs.confirm(title, content, 'Cancel', 'Delete').subscribe(
449 function (result) {
450 if (result) {
451 deleteDevice();
452 }
453 }
454 );
455 }
456
457 function deleteDevice() {
458 deviceService.deleteDevice(entityId.id).subscribe(
459 function () {
460 widgetContext.updateAliases();
461 }
462 );
463 }
464
465 {{/code}}
466
Hera Guo 38.1 467 **jump:I**mplementation function: Jump to the device details page
Hera Guo 19.1 468
Hera Guo 20.1 469 [[image:1730771386258-676.png]]
470
Hera Guo 19.1 471 {{code language="none"}}
472 console.log(entityName)
473 var entitySubType;
474 var $injector = widgetContext.$scope.$injector;
475 //console.log($injector)
476 $injector.get(widgetContext.servicesMap.get('entityService')).getEntity(entityId.entityType, entityId.id)
477 .subscribe(function(data) {
478 console.log(data)
479 entitySubType = data.type;
480 console.log(entitySubType)
481 if (entitySubType == 'AQS01-dragino-office') {
482 openDashboardStates('aqs01_detail');
483 }else if (entitySubType == 'gateway') {
484 openDashboardStates('gateway_detail');
485 } else if (entitySubType == 'gxhl01') {
486 openDashboardStates('detail');
487
488 } else if (entitySubType == 'tank-type1') {
489 openDashboardStates('test1');
490 }
491 else if (entitySubType == 'LDS12') {
492 openDashboardStates('lds12_detail');
493 }
494 else if (entitySubType == 'LDS02') {
495 openDashboardStates('lds02_detail');
496 }
497 else if (entitySubType == 'SE01') {
498 openDashboardStates('se01_detail');
499 }
500 else if (entitySubType == 'PB01') {
501 openDashboardStates('pb01_detail');
502 }
503 else if (entitySubType == 'LWL02') {
504 openDashboardStates('lwl02_detail');
505 }
506 else if (entitySubType == 'LPS8N') {
507 openDashboardStates('lps8n_detail');
508 }
509 else if (entitySubType == 'LHT65N') {
510 openDashboardStates('lht65n_detail');
511 }
512 else if (entitySubType == 'S31b') {
513 openDashboardStates('s31b_detail');
514 }
515 });
516
517 function openDashboardStates(statedId) {
518 var stateParams = widgetContext.stateController.getStateParams();
519 //console.log(stateParams)
520 var params = {
521 entityId: entityId,
522 entityName: entityName
523 };
524 widgetContext.stateController.updateState(statedId, params, false);
525 }
526 {{/code}}
527
Hera Guo 23.1 528 (% class="wikigeneratedid" id="H-1" %)
Hera Guo 38.1 529 **Add device:**Implementation function: Add device
Hera Guo 19.1 530
Hera Guo 20.1 531 [[image:1730771441589-122.png]]
532
Hera Guo 19.1 533 {{code language="none"}}
534 let $injector = widgetContext.$scope.$injector;
535 let customDialog = $injector.get(widgetContext.servicesMap.get('customDialog'));
536 let deviceService = $injector.get(widgetContext.servicesMap.get('deviceService'));
537 let attributeService = $injector.get(widgetContext.servicesMap.get('attributeService'));
538
539 openAddDeviceDialog();
540
541 function openAddDeviceDialog() {
542 customDialog.customDialog(htmlTemplate, AddDeviceDialogController).subscribe();
543 }
544
545 function AddDeviceDialogController(instance) {
546 let vm = instance;
547
548 vm.addDeviceFormGroup = vm.fb.group({
549 deviceName: ['', [vm.validators.required]],
550 deviceType: ['', [vm.validators.required]],
551 deviceLabel: [''],
552 attributes: vm.fb.group({
553 latitude: [null],
554 longitude: [null]
555 })
556 });
557
558 vm.cancel = function() {
559 vm.dialogRef.close(null);
560 };
561
562 vm.save = function() {
563 vm.addDeviceFormGroup.markAsPristine();
564 let device = {
565 name: vm.addDeviceFormGroup.get('deviceName').value,
566 type: vm.addDeviceFormGroup.get('deviceType').value,
567 label: vm.addDeviceFormGroup.get('deviceLabel').value
568 };
569 deviceService.saveDevice(device).subscribe(
570 function (device) {
571 saveAttributes(device.id).subscribe(
572 function () {
573 widgetContext.updateAliases();
574 vm.dialogRef.close(null);
575 }
576 );
577 }
578 );
579 };
580
581 function saveAttributes(entityId) {
582 let attributes = vm.addDeviceFormGroup.get('attributes').value;
583 let attributesArray = [];
584 for (let key in attributes) {
585 attributesArray.push({key: key, value: attributes[key]});
586 }
587 if (attributesArray.length > 0) {
588 return attributeService.saveEntityAttributes(entityId, "SERVER_SCOPE", attributesArray);
589 } else {
590 return widgetContext.rxjs.of([]);
591 }
592 }
593 }
594 {{/code}}
595
Hera Guo 20.1 596 ==== ====
Hera Guo 19.1 597
Hera Guo 45.1 598 ===== 4.1.2.2.3 Asset Alarm: =====
Hera Guo 19.1 599
Hera Guo 20.1 600 **Data:**
Hera Guo 19.1 601
Hera Guo 49.1 602 [[image:1730771504586-433.png]]
Hera Guo 19.1 603
604 ==== 4.1.2.3、Configure the first layer menu interface ====
605
Hera Guo 47.1 606 ===== 4.1.2.3.1 Map: =====
Hera Guo 44.1 607
608 **Data:**
609
Hera Guo 43.1 610 ===== =====
Hera Guo 19.1 611
Hera Guo 42.1 612 [[image:1730710271230-716.png||height="729" width="1427"]]
Hera Guo 17.1 613
Hera Guo 38.1 614 **Actions**:The map interface has two actions, among which Select supermarket can refresh the device list and related alarms on the right side to enter the location, and Supermarket_detail can jump to the second level physical interface to view the details of the location based on the selected location
Hera Guo 17.1 615
Hera Guo 18.1 616 [[image:1730710850458-781.png||height="770" width="1429"]]
Hera Guo 17.1 617
Hera Guo 38.1 618 **Select supermarket:**Implementation function: Refresh the side page
Hera Guo 17.1 619
620 {{code language="none"}}
621 var params = widgetContext.stateController.getStateParams();
622 var selectedSupermarket = params['selectedSupermarket'];
623 if (selectedSupermarket && selectedSupermarket.entityId.id === entityId.id) {
624 params['selectedSupermarket'] = null;
625 } else {
626 params['selectedSupermarket'] = { entityId: entityId, entityName: entityName, entityLabel: entityLabel };
627 }
628 widgetContext.stateController.updateState(null, params);
629 {{/code}}
630
Hera Guo 18.1 631 [[image:1730710875401-848.png||height="767" width="1429"]]
Hera Guo 17.1 632
Hera Guo 38.1 633 **Supermarket_detail:**Implementation function: Jump to the asset details page
Hera Guo 17.1 634
635 {{code language="none"}}
636 var params = JSON.parse(JSON.stringify(widgetContext.stateController.getStateParams()));
637 params['selectedSupermarket'] = {
638 entityId: entityId,
639 entityName: entityName,
640 entityLabel: entityLabel,
641 };
642 params['targetEntityParamName'] = 'selectedSupermarket';
643 params['selectedDevice'] = null;
644
645 widgetContext.stateController.openState('svgmap', params);
646 {{/code}}
647
Hera Guo 18.1 648 [[image:1730710990334-601.png||height="772" width="1433"]]
Hera Guo 17.1 649
Hera Guo 25.1 650 * (((
651 In this demo, exclusive map icons were set as follows:
652 )))
Hera Guo 17.1 653
654 {{code language="none"}}
655 var res = {
656 url: images[0],
657 size: 66
658 };
659 return res;
660 {{/code}}
661
Hera Guo 18.1 662 [[image:1730710395303-672.png||height="771" width="1438"]]
Hera Guo 17.1 663
Hera Guo 20.1 664 ===== 4.1.2.3.1 Asset List: =====
Hera Guo 17.1 665
Hera Guo 20.1 666 **Data:**
Hera Guo 17.1 667
Hera Guo 18.1 668 [[image:1730710693066-349.png||height="772" width="1439"]]
Hera Guo 17.1 669
Hera Guo 38.1 670 **Actions:**The Assets List interface has an action, which is the same as the Supermarket_details in the Map. You can jump to the second level entity interface to view the details of the selected location based on its location
Hera Guo 18.1 671
672 [[image:1730712335338-750.png||height="751" width="1423"]]
673
674 [[image:1730712473941-913.png||height="781" width="1422"]]
675
676 All Alarms:
677
678 [[image:1730712539209-554.png||height="764" width="1424"]]
679
Hera Guo 15.1 680 == 4.2 Alarm configuration details ==
681
Hera Guo 28.1 682 === 4.2.1 High temperature ===
683
684 Creat:
685
686 [[image:1730862483514-101.png||height="750" width="1407"]]
687
688 Clear:
689
690 [[image:1730862584519-902.png||height="758" width="1404"]]
691
692 === 4.2.2 Low Temperature ===
693
694 Creat:
695
696 [[image:1730863708259-750.png||height="752" width="1403"]]
697
698 Clear:
699
700 [[image:1730863750414-979.png||height="746" width="1403"]]
701
702 === 4.2.3 High humidity ===
703
704 Creat:
705
706 [[image:1730864045747-876.png||height="752" width="1396"]]
707
708 Clear:
709
710 [[image:1730864077395-395.png||height="735" width="1393"]]
711
712 === 4.2.4 Low humidity ===
713
714 Creat:
715
716 [[image:1730864117808-484.png||height="741" width="1392"]]
717
718 Clear:
719
720 [[image:1730864159071-895.png||height="745" width="1392"]]
721
722 === 4.2.5 Low voltage ===
723
724 Creat:
725
726 [[image:1730864207037-477.png||height="740" width="1388"]]
727
728 Clear:
729
730 [[image:1730864250506-111.png||height="735" width="1389"]]
731
732 === 4.2.6 Device Disconnected ===
733
734 Creat:
735
736 [[image:1730864293216-991.png||height="739" width="1387"]]
737
738 Clear:
739
740 [[image:1730864331859-740.png||height="735" width="1385"]]
741
Hera Guo 15.1 742 == 4.3 Rule chain configuration details ==
743
Hera Guo 28.1 744 [[image:1730864784118-474.png]]
745
746 **Script:**Email configuration for sending device alarm information
747
748 [[image:1730864676542-406.png||height="732" width="1384"]]
749
750 {{code language="none"}}
751 function locatime(timenumber){
752 var date = new Date(timenumber)
753 return date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
754 }
755 var name = msg.name
756 var devicename = msg.originatorName
757 var label = msg.originatorLabel
758 var status = msg.status
759 var detaildata =JSON.parse(msg.details.data)
760 var tempswitch
761
762 if (name != "Device Disconnected") {
763 //detaildata=JSON.parse(msg.details.data)
764 if (detaildata.Temperature_alarm_switch == true) {
765 tempswitch = "open"
766 } else {
767 tempswitch = "close"
768 }
769 var humswitch
770 if (detaildata.Humidity_alarm_switch == true) {
771 humswitch = "open"
772 } else {
773 humswitch = "close"
774 }
775 var batswitch
776 if (detaildata.Voltage_alarm_switch == true) {
777 batswitch = "open"
778 } else {
779 batswitch = "close"
780 }
781 var str2 = "<p>-- Temperature alarm switch status: " +
782 tempswitch + "</p>" +
783 "<p>-- Humidity alarm switch status: " + humswitch +
784 "</p>" +
785 "<p>-- Voltage alarm switch status: " + batswitch
786 }
787
788 if (name == "High Temperature" && status ==
789 "ACTIVE_UNACK") {
790 var emailstr =
791 "<div><p><span style='color: black; font-weight: bold'>" +
792 "Device " + label + " has alarm:</span></p>" +
793 "<p><span style='color: red; font-weight: bold'>-- High Temperature Alarm</span></p>" +
794 "<p>-- Current Temperature : " + detaildata
795 .TempC_SHT + "</p><br>" +
796 "<p>Device Configure:</p>" +
797 "<p>-- Temperature Threshold : min: " + detaildata
798 .Low_temperature_alarm + ", max: " + detaildata
799 .High_temperature_alarm + "</p>" +
800 "<p>-- Humidity Threshold: min: " + detaildata
801 .Low_humidity_alarm + ", max:" + detaildata
802 .High_humidity_alarm + "</p>" +
803 "<p>-- Battery threshold: min: " + detaildata
804 .Low_voltage_alarm + "</p>" + str2 + "</div>"
805 return {
806 msg: {
807 "data": emailstr
808 },
809 metadata: metadata,
810 msgType: msgType
811 };
812 } else if (name == "Low Temperature" && status ==
813 "ACTIVE_UNACK") {
814 var emailstr =
815 "<div><p><span style='color: black; font-weight: bold'>" +
816 "Device " + label + " has alarm:</span></p>" +
817 "<p><span style='color: red; font-weight: bold'>-- Low Temperature Alarm</span></p>" +
818 "<p>-- Current Temperature : " + detaildata
819 .TempC_SHT + "</p><br>" +
820 "<p>Device Configure:</p>" +
821 "<p>-- Temperature Threshold : min: " + detaildata
822 .Low_temperature_alarm + ", max: " + detaildata
823 .High_temperature_alarm + "</p>" +
824 "<p>-- Humidity Threshold: min: " + detaildata
825 .Low_humidity_alarm + ", max:" + detaildata
826 .High_humidity_alarm + "</p>" +
827 "<p>-- Battery threshold: min: " + detaildata
828 .Low_voltage_alarm + "</p>" + str2 + "</div>"
829
830 return {
831 msg: {
832 "data": emailstr
833 },
834 metadata: metadata,
835 msgType: msgType
836 };
837
838 } else if (name == "Device Disconnected" && status ==
839 "ACTIVE_UNACK") {
840 var time1 = locatime(Number(detaildata.lastActivityTime))
841 //var time1 = detaildata.lastActivityTime
842 // var chazhi = parseInt((detaildata.inactivityAlarmTime-detaildata.lastActivityTime)/1000/60)
843 // var emailstr =
844 // "<div><p><span style='color: red; font-weight: bold'>" +
845 // "Device " + label + " has Alarm</span></p><p>Last activity time: "+time1+"</p><p>Last Uplink: 21"+"minutes ago</p></div>"
846
847 var emailstr ="Device " + label + " has Alarm##Last activity time: "+time1+"##Last Uplink: 21minutes ago"
848 var newType = "POST_TELEMETRY_REQUEST"
849 return {
850 msg:emailstr,
851 metadata: metadata,
852 msgType: newType
853 }
854 } else if (name == "High humidity" && status ==
855 "ACTIVE_UNACK") {
856 var emailstr =
857 "<div><p><span style='color: black; font-weight: bold'>" +
858 "Device " + label + " has alarm:</span></p>" +
859 "<p><span style='color: red; font-weight: bold'>-- High Humidity Alarm</span></p>" +
860 "<p>-- Current Temperature : " + detaildata
861 .Hum_SHT + "</p><br>" +
862 "<p>Device Configure:</p>" +
863 "<p>-- Temperature Threshold : min: " + detaildata
864 .Low_temperature_alarm + ", max: " + detaildata
865 .High_temperature_alarm + "</p>" +
866 "<p>-- Humidity Threshold: min: " + detaildata
867 .Low_humidity_alarm + ", max:" + detaildata
868 .High_humidity_alarm + "</p>" +
869 "<p>-- Battery threshold: min: " + detaildata
870 .Low_voltage_alarm + "</p>" + str2 + "</div>"
871
872 return {
873 msg: {
874 "data": emailstr
875 },
876 metadata: metadata,
877 msgType: msgType
878 };
879 } else if (name == "Low humidity" && status ==
880 "ACTIVE_UNACK") {
881 var emailstr =
882 "<div><p><span style='color: black; font-weight: bold'>" +
883 "Device " + label + " has alarm:</span></p>" +
884 "<p><span style='color: red; font-weight: bold'>-- Low Humidity Alarm</span></p>" +
885 "<p>-- Current Temperature : " + detaildata
886 .Hum_SHT + "</p><br>" +
887 "<p>Device Configure:</p>" +
888 "<p>-- Temperature Threshold : min: " + detaildata
889 .Low_temperature_alarm + ", max: " + detaildata
890 .High_temperature_alarm + "</p>" +
891 "<p>-- Humidity Threshold: min: " + detaildata
892 .Low_humidity_alarm + ", max:" + detaildata
893 .High_humidity_alarm + "</p>" +
894 "<p>-- Battery threshold: min: " + detaildata
895 .Low_voltage_alarm + "</p>" + str2 + "</div>"
896
897 return {
898 msg: {
899 "data": emailstr
900 },
901 metadata: metadata,
902 msgType: msgType
903 };
904 } else if (name == "Low voltage" && status ==
905 "ACTIVE_UNACK") {
906 var emailstr =
907 "<div><p><span style='color: black; font-weight: bold'>" +
908 "Device " + label + " has alarm:</span></p>" +
909 "<p><span style='color: red; font-weight: bold'>-- Low Voltage Alarm</span></p>" +
910 "<p>-- Current Temperature : " + detaildata.BatV +
911 "</p><br>" +
912 "<p>Device Configure:</p>" +
913 "<p>-- Temperature Threshold : min: " + detaildata
914 .Low_temperature_alarm + ", max: " + detaildata
915 .High_temperature_alarm + "</p>" +
916 "<p>-- Humidity Threshold: min: " + detaildata
917 .Low_humidity_alarm + ", max:" + detaildata
918 .High_humidity_alarm + "</p>" +
919 "<p>-- Battery threshold: min: " + detaildata
920 .Low_voltage_alarm + "</p>" + str2 + "</div>"
921
922 return {
923 msg: {
924 "data": emailstr
925 },
926 metadata: metadata,
927 msgType: msgType
928 };
929 } else if (name == "High Temperature" && status ==
930 "CLEARED_UNACK") {
931 var emailstr =
932 "<div><p><span style='color: green; font-weight: bold'>Device " +
933 label +
934 " High Temperature Alarm Cleared</span></p>" +
935 "<p>-- Current Temperature : " + detaildata
936 .TempC_SHT + "</p><br>" +
937 "<p>Device Configure:</p>" +
938 "<p>-- Temperature Threshold : min: " + detaildata
939 .Low_temperature_alarm + ", max: " + detaildata
940 .High_temperature_alarm + "</p>" +
941 "<p>-- Humidity Threshold: min: " + detaildata
942 .Low_humidity_alarm + ", max:" + detaildata
943 .High_humidity_alarm + "</p>" +
944 "<p>-- Battery threshold: min: " + detaildata
945 .Low_voltage_alarm + "</p>" + str2 + "</div>"
946
947 return {
948 msg: {
949 "data": emailstr
950 },
951 metadata: metadata,
952 msgType: msgType
953 };
954 } else if (name == "Low Temperature" && status ==
955 "CLEARED_UNACK") {
956 var emailstr =
957 "<div><p><span style='color: green; font-weight: bold'>Device " +
958 label +
959 " Low Temperature Alarm Cleared</span></p>" +
960 "<p>-- Current Temperature : " + detaildata
961 .TempC_SHT + "</p><br>" +
962 "<p>Device Configure:</p>" +
963 "<p>-- Temperature Threshold : min: " + detaildata
964 .Low_temperature_alarm + ", max: " + detaildata
965 .High_temperature_alarm + "</p>" +
966 "<p>-- Humidity Threshold: min: " + detaildata
967 .Low_humidity_alarm + ", max:" + detaildata
968 .High_humidity_alarm + "</p>" +
969 "<p>-- Battery threshold: min: " + detaildata
970 .Low_voltage_alarm + "</p>" + str2 + "</div>"
971
972 return {
973 msg: {
974 "data": emailstr
975 },
976 metadata: metadata,
977 msgType: msgType
978 };
979 } else if (name == "High humidity" && status ==
980 "CLEARED_UNACK") {
981 var emailstr =
982 "<div><p><span style='color: green; font-weight: bold'>Device " +
983 label + " High Humidity Alarm Cleared</span></p>" +
984 "<p>-- Current Temperature : " + detaildata
985 .Hum_SHT + "</p><br>" +
986 "<p>Device Configure:</p>" +
987 "<p>-- Temperature Threshold : min: " + detaildata
988 .Low_temperature_alarm + ", max: " + detaildata
989 .High_temperature_alarm + "</p>" +
990 "<p>-- Humidity Threshold: min: " + detaildata
991 .Low_humidity_alarm + ", max:" + detaildata
992 .High_humidity_alarm + "</p>" +
993 "<p>-- Battery threshold: min: " + detaildata
994 .Low_voltage_alarm + "</p>" + str2 + "</div>"
995
996 return {
997 msg: {
998 "data": emailstr
999 },
1000 metadata: metadata,
1001 msgType: msgType
1002 };
1003 } else if (name == "Low humidity" && status ==
1004 "CLEARED_UNACK") {
1005 var emailstr =
1006 "<div><p><span style='color: green; font-weight: bold'>Device " +
1007 label + " Low Humidity Alarm Cleared</span></p>" +
1008 "<p>-- Current Temperature : " + detaildata
1009 .Hum_SHT + "</p><br>" +
1010 "<p>Device Configure:</p>" +
1011 "<p>-- Temperature Threshold : min: " + detaildata
1012 .Low_temperature_alarm + ", max: " + detaildata
1013 .High_temperature_alarm + "</p>" +
1014 "<p>-- Humidity Threshold: min: " + detaildata
1015 .Low_humidity_alarm + ", max:" + detaildata
1016 .High_humidity_alarm + "</p>" +
1017 "<p>-- Battery threshold: min: " + detaildata
1018 .Low_voltage_alarm + "</p>" + str2 + "</div>"
1019 return {
1020 msg: {
1021 "data": emailstr
1022 },
1023 metadata: metadata,
1024 msgType: msgType
1025 };
1026 } else if (name == "Low voltage" && status ==
1027 "CLEARED_UNACK") {
1028
1029 var emailstr =
1030 "<div><p><span style='color: green; font-weight: bold'>Device " +
1031 label + " Low Voltage Alarm Cleared</span></p>" +
1032 "<p>-- Current Temperature : " + detaildata.BatV +
1033 "</p><br><br>" +
1034 "<p>Device Configure:</p>" +
1035 "<p>-- Temperature Threshold : min: " + detaildata
1036 .Low_temperature_alarm + ", max: " + detaildata
1037 .High_temperature_alarm + "</p>" +
1038 "<p>-- Humidity Threshold: min: " + detaildata
1039 .Low_humidity_alarm + ", max:" + detaildata
1040 .High_humidity_alarm + "</p>" +
1041 "<p>-- Battery threshold: min: " + detaildata
1042 .Low_voltage_alarm + "</p>" + str2 + "</div>"
1043
1044 return {
1045 msg: {
1046 "data": emailstr
1047 },
1048 metadata: metadata,
1049 msgType: msgType
1050 };
1051 } else if (name == "Device Disconnected" && status ==
1052 "CLEARED_UNACK") {
1053 var time1 = locatime(Number(detaildata.lastActivityTime))
1054 //var time1 = detaildata.lastActivityTime
1055 // var chazhi = parseInt((detaildata.inactivityAlarmTime-detaildata.lastActivityTime)/1000/60)
1056 // var emailstr =
1057 // "<div><p><span style='color: green; font-weight: bold'>" +
1058 // "Device " + label + " has Alarm Cleared</span></p><p>Last activity time: "+time1+"</p></div>"
1059 var emailstr ="Device " + label + " has Alarm Cleared##Last activity time: "+time1
1060 var newType = "POST_TELEMETRY_REQUEST"
1061 return {
1062 msg: emailstr,
1063 metadata: metadata,
1064 msgType: newType
1065 }
1066 }
1067 {{/code}}
1068
1069 (% class="wikigeneratedid" %)
1070 **Generate Report:**
1071
1072 (% class="wikigeneratedid" %)
1073 [[image:1730865053380-293.png]]
1074
1075 = 5.other =
1076
1077 * If you want to create a similar dashboard, after understanding the case, you can download and import the dashboard, device profiles, rule chains, etc. of the case on GitHub, and make modifications based on them.
Hera Guo 29.1 1078 * GitHub address:[[https:~~/~~/github.com/ThingsEye-io/te-platform/tree/main/case/Dragino%20Office%20%26%20Factory>>https://github.com/ThingsEye-io/te-platform/tree/main/case/Dragino%20Office%20%26%20Factory]]