iobroker.lorawan 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,13 +15,19 @@ The adapter communicates bidirectionally with LoraWan devices via LoRaWAN Networ
15
15
  Adapter was created in collaboration with Joerg Froehner LoraWan@hafenmeister.com
16
16
 
17
17
  For Documentation use the doc folder.
18
- For now there is documentation in English here: http://www.hafenmeister.com/LoraWan/Iobroker-Adapter.pdf
18
+ For now there is documentation in English here: https://wiki.hafenmeister.de
19
19
 
20
20
  ## Changelog
21
21
  <!--
22
22
  Placeholder for the next version (at the beginning of the line):
23
23
  ### **WORK IN PROGRESS**
24
24
  -->
25
+ ### 0.6.3 (2024-03-05)
26
+ * (BenAhrdt) def of deviceinformations changed
27
+
28
+ ### 0.6.2 (2024-03-05)
29
+ * (BenAhrdt) seperate dp for deviceinformations
30
+
25
31
  ### 0.6.1 (2024-03-02)
26
32
  * (BenAhrdt) better concept to write values and change setObjectNotExists to extendObject
27
33
 
package/io-package.json CHANGED
@@ -1,8 +1,34 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "lorawan",
4
- "version": "0.6.1",
4
+ "version": "0.6.3",
5
5
  "news": {
6
+ "0.6.3": {
7
+ "en": "def of deviceinformations changed",
8
+ "de": "def von geräteinformationen geändert",
9
+ "ru": "изменена дефабрикация устройств",
10
+ "pt": "def das informações do dispositivo alteradas",
11
+ "nl": "de def van apparaatinformatie gewijzigd",
12
+ "fr": "def des informations de l'appareil changé",
13
+ "it": "def delle informazioni sui dispositivi modificate",
14
+ "es": "def de las desinformaciones de dispositivo cambiadas",
15
+ "pl": "def deviceinformations changed",
16
+ "uk": "змінено деф приладів",
17
+ "zh-cn": "设备信息已更改"
18
+ },
19
+ "0.6.2": {
20
+ "en": "seperate dp for deviceinformations",
21
+ "de": "seperate dp für geräteinformationen",
22
+ "ru": "seperate dp for deviceinformations",
23
+ "pt": "seperar dp para informações do dispositivo",
24
+ "nl": "aparte dp voor apparaatinformatie",
25
+ "fr": "seperate dp pour les informations de l'appareil",
26
+ "it": "seperate dp per informazioni sui dispositivi",
27
+ "es": "dp de seperato para desinformaciones de dispositivo",
28
+ "pl": "seperate dp for deviceinformations",
29
+ "uk": "seperate dp для пристроюінформаційних систем",
30
+ "zh-cn": "设备信息的 seperate dp"
31
+ },
6
32
  "0.6.1": {
7
33
  "en": "better concept to write values and change setObjectNotExists to extendObject",
8
34
  "de": "besseres Konzept zum Schreiben von Werten und Änderungsset ObjectNotExists to erweitern Gegenstand",
@@ -67,32 +93,6 @@
67
93
  "pl": "zmień folder dla pisarzy",
68
94
  "uk": "змінити папку для запису",
69
95
  "zh-cn": "更改写入文件夹"
70
- },
71
- "0.5.2": {
72
- "en": "make writetrigger more flexible",
73
- "de": "schreibtrigger flexibler gestalten",
74
- "ru": "сделать пишущее устройство более гибким",
75
- "pt": "fazer writetrigger mais flexível",
76
- "nl": "schrijftrigger flexibeler maken",
77
- "fr": "rendre le trigger plus flexible",
78
- "it": "rendere writetrigger più flessibile",
79
- "es": "hacer la escritura más flexible",
80
- "pl": "uczynić pisarkę bardziej elastyczną",
81
- "uk": "зробити напилення більш гнучким",
82
- "zh-cn": "使写入器更加灵活"
83
- },
84
- "0.5.1": {
85
- "en": "detecting of triggerwords changed",
86
- "de": "erkennung von triggerworten geändert",
87
- "ru": "изменено обнаружение триггеров",
88
- "pt": "detecção de palavras de gatilho alteradas",
89
- "nl": "detectie van gewijzigde triggerwoorden",
90
- "fr": "la détection des mots-clés a changé",
91
- "it": "rilevazione delle parole d'innesco modificate",
92
- "es": "detección de palabras de disparador cambiadas",
93
- "pl": "wykrywanie zmienionych tryggerwords",
94
- "uk": "виявлення змінених фраз",
95
- "zh-cn": "检测触发词已更改"
96
96
  }
97
97
  },
98
98
  "title": "LoRaWAN",
@@ -195,6 +195,19 @@
195
195
  "def": false
196
196
  },
197
197
  "native": {}
198
+ },
199
+ {
200
+ "_id": "info.deviceinformations",
201
+ "type": "state",
202
+ "common": {
203
+ "role": "json",
204
+ "name": "Information of all devices",
205
+ "type": "json",
206
+ "read": true,
207
+ "write": false,
208
+ "def": ""
209
+ },
210
+ "native": {}
198
211
  }
199
212
  ]
200
213
  }
@@ -180,7 +180,7 @@ class directorieshandlerClass {
180
180
  // go to every element in the object
181
181
  for(const elementName in obj){
182
182
  // Check the the elementname is not in ignored object
183
- if(!this.ignoredElementNames[elementName] && !options?.ignoredElementNames[elementName]){
183
+ if(!this.ignoredElementNames[elementName] && (!options || !options.ignoredElementNames || !options.ignoredElementNames[elementName])){
184
184
  // Check if the element is an object
185
185
  if(typeof obj[elementName] === "object" && obj[elementName] && !obj[elementName].isState){
186
186
  // Generate the desired id
@@ -265,7 +265,7 @@ class directorieshandlerClass {
265
265
  await this.adapter.setObject(objectId,myObject);
266
266
  }
267
267
  // Jump into next step (next directory / attribute)
268
- await this.generateRekursivObjects(obj[elementName],objectId,topic,message);
268
+ await this.generateRekursivObjects(obj[elementName],objectId,topic,message,options);
269
269
  }
270
270
  else{
271
271
  const common = {
@@ -296,7 +296,8 @@ class directorieshandlerClass {
296
296
  objectId.substring(1,objectId.length);
297
297
  }
298
298
  // Check for an assign definition (calculation and / or role assignment)
299
- if(this.assigns[elementName]){
299
+ if(this.assigns[elementName] && !options?.dontAssign){
300
+ this.adapter.log.debug(`the state with th id ${objectId} will be assigned by internal function`);
300
301
  stateVal = this.assigns[elementName](stateVal,common);
301
302
  }
302
303
  common.read = common.role !== "button";
@@ -15,6 +15,10 @@ class messagehandlerClass {
15
15
  boolean: "switch",
16
16
  json: "json"
17
17
  };
18
+
19
+ // Define present devices for general datainfo via jsonformat in infor folder
20
+ this.idDeviceinformations = "info.deviceinformations";
21
+ this.deviceinformations = {};
18
22
  }
19
23
 
20
24
 
@@ -62,6 +66,62 @@ class messagehandlerClass {
62
66
  }
63
67
  }
64
68
 
69
+ async generateDeviceinfosAtStartup(){
70
+ const activeFunction = "generateDeviceinfosAtStartup";
71
+ try{
72
+ const adapterObjectsAtStart = await this.adapter.getAdapterObjectsAsync();
73
+ // Generate Infos of all defices and decoded folders
74
+ for(const adapterObject of Object.values(adapterObjectsAtStart)){
75
+ if(adapterObject._id.endsWith(`${this.directoryhandler.reachableSubfolders.uplinkRaw}.json`)){
76
+ const uplinkState = await this.adapter.getStateAsync(adapterObject._id);
77
+ await this.assignDeviceInformation(adapterObject._id,JSON.parse(uplinkState.val));
78
+ }
79
+ }
80
+ }
81
+ catch(error){
82
+ this.adapter.log.error(`error at ${activeFunction}: ` + error);
83
+ }
84
+ }
85
+
86
+ // Assign base information to presentDevices
87
+ async assignDeviceInformation(id,message){
88
+ const activeFunction = "assignDeviceInformation";
89
+ try{
90
+ const changeInfo = await this.adapter.getChangeInfo(id);
91
+ // Create Attribute for application id
92
+ if(!this.deviceinformations[changeInfo.deviceEUI]){
93
+ this.deviceinformations[changeInfo.deviceEUI] = {};
94
+ this.deviceinformations[changeInfo.deviceEUI].uplink = {};
95
+ this.deviceinformations[changeInfo.deviceEUI].uplink.decoded = {};
96
+ }
97
+ this.deviceinformations[changeInfo.deviceEUI].applicationId = changeInfo.applicationId;
98
+ this.deviceinformations[changeInfo.deviceEUI].applicationName = changeInfo.applicationName;
99
+ this.deviceinformations[changeInfo.deviceEUI].usedApplicationName = changeInfo.usedApplicationName;
100
+ this.deviceinformations[changeInfo.deviceEUI].deviceId = changeInfo.deviceId;
101
+ this.deviceinformations[changeInfo.deviceEUI].usedDeviceId = changeInfo.usedDeviceId;
102
+
103
+ // Check origin
104
+ switch(this.adapter.config.origin){
105
+ case this.adapter.origin.ttn:
106
+ if(message.uplink_message && message.uplink_message.decoded_payload){
107
+ this.deviceinformations[changeInfo.deviceEUI].uplink.decoded = message.uplink_message.decoded_payload;
108
+ this.deviceinformations[changeInfo.deviceEUI].uplink.time = message.rx_metadata.time;
109
+ }
110
+ break;
111
+ case this.adapter.origin.chirpstack:
112
+ if(message.object){
113
+ this.deviceinformations[changeInfo.deviceEUI].uplink.decoded = message.object;
114
+ this.deviceinformations[changeInfo.deviceEUI].uplink.time = message.rxInfo[0].nsTime;
115
+ }
116
+ break;
117
+ }
118
+ await this.adapter.setStateAsync(this.idDeviceinformations,JSON.stringify(this.deviceinformations),true);
119
+ }
120
+ catch(error){
121
+ this.adapter.log.error(`error at ${activeFunction}: ` + error);
122
+ }
123
+ }
124
+
65
125
  //Add directories at startup (so theyare present before next upload)
66
126
  async addDirectoriesToPresentDirectory(startDirectory){
67
127
  await this.directoryhandler.generateRekursivObjects(this.directoryhandler.directories.application.devices.deviceEUI.downlink.nextSend,`${startDirectory}.${this.directoryhandler.reachableSubfolders.downlinkNextSend}`,"","");
@@ -230,7 +290,7 @@ class messagehandlerClass {
230
290
  common: {
231
291
  name: "last recieved message",
232
292
  type: "json",
233
- role: "value",
293
+ role: "json",
234
294
  read: true,
235
295
  write: false
236
296
  },
@@ -314,6 +374,12 @@ class messagehandlerClass {
314
374
  * ******************************************************************/
315
375
 
316
376
  await this.adapter.checkSendDownlinkWithUplink(`${deviceStartdirectory}.downlink.control.push`);
377
+
378
+ /*********************************************************************
379
+ * ******************* assign deviceinformations **********************
380
+ * ******************************************************************/
381
+
382
+ await this.assignDeviceInformation(deviceStartdirectory,message);
317
383
  }
318
384
 
319
385
  /*********************************************************************
@@ -336,7 +402,7 @@ class messagehandlerClass {
336
402
  common: {
337
403
  name: "last recieved message",
338
404
  type: "json",
339
- role: "value",
405
+ role: "json",
340
406
  read: true,
341
407
  write: false
342
408
  },
@@ -429,7 +495,7 @@ class messagehandlerClass {
429
495
  common: {
430
496
  name: "last recieved message",
431
497
  type: "json",
432
- role: "value",
498
+ role: "json",
433
499
  read: true,
434
500
  write: false
435
501
  },
@@ -516,7 +582,7 @@ class messagehandlerClass {
516
582
  common: {
517
583
  name: "last recieved message",
518
584
  type: "json",
519
- role: "value",
585
+ role: "json",
520
586
  read: true,
521
587
  write: false
522
588
  },
@@ -584,6 +650,7 @@ class messagehandlerClass {
584
650
  startId = `${deviceStartdirectory}.${this.directoryhandler.reachableSubfolders.uplinkDecoded}`;
585
651
  this.adapter.log.silly(`write decoded payload (Object)`);
586
652
  await this.directoryhandler.generateRekursivObjects(message.object,startId,topic,message);
653
+
587
654
  /*********************************************************************
588
655
  * ************************* remaining *******************************
589
656
  * ******************************************************************/
@@ -597,6 +664,12 @@ class messagehandlerClass {
597
664
  * ******************************************************************/
598
665
 
599
666
  await this.adapter.checkSendDownlinkWithUplink(`${deviceStartdirectory}.downlink.control.push`);
667
+
668
+ /*********************************************************************
669
+ * ******************* assign deviceinformations **********************
670
+ * ******************************************************************/
671
+
672
+ await this.assignDeviceInformation(deviceStartdirectory,message);
600
673
  }
601
674
 
602
675
  /*********************************************************************
@@ -618,7 +691,7 @@ class messagehandlerClass {
618
691
  common: {
619
692
  name: "last recieved message",
620
693
  type: "json",
621
- role: "value",
694
+ role: "json",
622
695
  read: true,
623
696
  write: false
624
697
  },
@@ -707,7 +780,7 @@ class messagehandlerClass {
707
780
  common: {
708
781
  name: "last recieved message",
709
782
  type: "json",
710
- role: "value",
783
+ role: "json",
711
784
  read: true,
712
785
  write: false
713
786
  },
package/main.js CHANGED
@@ -55,6 +55,9 @@ class Lorawan extends utils.Adapter {
55
55
  // generate new configed downlinkstates on allready existing devices at adapter startup
56
56
  await this.messagehandler.generateDownlinksAndRemoveStatesAtStatup();
57
57
 
58
+ // generate deviceinfo of all devices in info folder
59
+ await this.messagehandler.generateDeviceinfosAtStartup();
60
+
58
61
  //Subscribe all configuration and control states
59
62
  this.subscribeStatesAsync("*");
60
63
  this.log.silly(`the adapter starts with downlinkconfigs: ${JSON.stringify(this.config.downlinkConfig)}.`);
@@ -326,10 +329,13 @@ class Lorawan extends utils.Adapter {
326
329
  // Check for changeInfo
327
330
  if(changeInfo){
328
331
  // Get Obect from startdirectory
332
+ const applicationDirectoryObject = await this.getObjectAsync(changeInfo.applicationId);
329
333
  const startDirectoryObject = await this.getObjectAsync(changeInfo.objectStartDirectory);
330
- if(startDirectoryObject){
331
- changeInfo.applicationName = startDirectoryObject.native.applicationName;
334
+ if(applicationDirectoryObject && startDirectoryObject){
335
+ changeInfo.applicationName = applicationDirectoryObject.native.applicationName;
336
+ changeInfo.usedApplicationName = applicationDirectoryObject.common.name;
332
337
  changeInfo.deviceId = startDirectoryObject.native.deviceId;
338
+ changeInfo.usedDeviceId = startDirectoryObject.common.name;
333
339
  }
334
340
  // Get deviceType
335
341
  const deviceTypeIdState = await this.getStateAsync(myId);
@@ -396,7 +402,7 @@ class Lorawan extends utils.Adapter {
396
402
  if(obj.message.deviceEUI){
397
403
  const changeInfo = await this.getChangeInfoFromDeviceEUI(obj.message.deviceEUI,`${this.messagehandler?.directoryhandler.reachableSubfolders.configuration}.devicetype`);
398
404
  if(changeInfo){
399
- result = {applicationId: changeInfo.applicationId, applicationName: changeInfo.applicationName, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, deviceType: changeInfo.deviceType, received:obj.message};
405
+ result = {applicationId: changeInfo.applicationId, applicationName: changeInfo.applicationName, usedApplicationName: changeInfo.usedApplicationName, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, usedDeviceId: changeInfo.usedDeviceId, deviceType: changeInfo.deviceType, received:obj.message};
400
406
  }
401
407
  else{
402
408
  result = {error:true, message:"No device found", received:obj.message};
@@ -417,7 +423,7 @@ class Lorawan extends utils.Adapter {
417
423
  if(await this.objectExists(uplinkId)){
418
424
  const stateResult = await this.getStateAsync(changeInfo.id);
419
425
  if(stateResult){
420
- result = {applicationId: changeInfo.applicationId, applicationName: changeInfo.applicationName, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, deviceType: changeInfo.deviceType, value: stateResult.val, received:obj.message};
426
+ result = {applicationId: changeInfo.applicationId, applicationName: changeInfo.applicationName, usedApplicationName: changeInfo.usedApplicationName, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, usedDeviceId: changeInfo.usedDeviceId, deviceType: changeInfo.deviceType, value: stateResult.val, received:obj.message};
421
427
  }
422
428
  }
423
429
  else{
@@ -449,7 +455,7 @@ class Lorawan extends utils.Adapter {
449
455
  // Check limit
450
456
  if((!downlinkObject.common.min || obj.message.value >= downlinkObject.common.min) && (!downlinkObject.common.max || obj.message.value <= downlinkObject.common.max)){
451
457
  await this.setStateAsync(downlinkId,obj.message.value);
452
- result = {applicationId: changeInfo.applicationId, applicationName: changeInfo.applicationName, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, deviceType: changeInfo.deviceType, downlink: obj.message.downlink, value: obj.message.value, received:obj.message};
458
+ result = {applicationId: changeInfo.applicationId, applicationName: changeInfo.applicationName, usedApplicationName: changeInfo.usedApplicationName, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, deviceType: changeInfo.deviceType, downlink: obj.message.downlink, value: obj.message.value, received:obj.message};
453
459
  }
454
460
  else{
455
461
  result = {error:true, message:"value is not in valid range", received:obj.message};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.lorawan",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "converts the desired lora gateway data to a ioBroker structure",
5
5
  "author": {
6
6
  "name": "BenAhrdt",