iobroker.lorawan 1.0.3 → 1.0.5

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
@@ -23,6 +23,12 @@ For now there is documentation in English here: https://wiki.hafenmeister.de
23
23
  Placeholder for the next version (at the beginning of the line):
24
24
  ### **WORK IN PROGRESS**
25
25
  -->
26
+ ### 1.0.5 (2024-05-10)
27
+ * (BenAhrdt) device offline location changed
28
+
29
+ ### 1.0.4 (2024-05-10)
30
+ * (BenAhrdt) changed icon and offline time
31
+
26
32
  ### 1.0.3 (2024-05-10)
27
33
  * (BenAhrdt) notifications for connection and disconnection LNS added
28
34
  * (BenAhrdt) notifiction for device offline added
package/io-package.json CHANGED
@@ -1,8 +1,34 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "lorawan",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "news": {
6
+ "1.0.5": {
7
+ "en": "device offline location changed",
8
+ "de": "gerät offline-standort geändert",
9
+ "ru": "устройство офлайн расположение изменено",
10
+ "pt": "dispositivo localização offline alterado",
11
+ "nl": "apparaat offline locatie gewijzigd",
12
+ "fr": "changement d'emplacement hors ligne du périphérique",
13
+ "it": "dispositivo posizione offline cambiato",
14
+ "es": "ubicación del dispositivo sin conexión cambiado",
15
+ "pl": "zmiana lokalizacji urządzenia offline",
16
+ "uk": "змінено розташування пристрою",
17
+ "zh-cn": "设备离线位置已更改"
18
+ },
19
+ "1.0.4": {
20
+ "en": "changed icon and offline time",
21
+ "de": "geändertes icon und offline-zeit",
22
+ "ru": "измененная иконка и автономное время",
23
+ "pt": "ícone alterado e tempo offline",
24
+ "nl": "veranderd pictogram en offline tijd",
25
+ "fr": "changement d'icône et de l'heure hors ligne",
26
+ "it": "cambiato icona e tempo offline",
27
+ "es": "cambiado icono y tiempo sin conexión",
28
+ "pl": "zmieniony czas ikon i offline",
29
+ "uk": "змінена ікона і в автономному режимі",
30
+ "zh-cn": "更改图标和离线时间"
31
+ },
6
32
  "1.0.3": {
7
33
  "en": "notifications for connection and disconnection LNS added\nnotifiction for device offline added",
8
34
  "de": "benachrichtigungen für Anschluss und Abschaltung LNS hinzugefügt\nnotification für gerät offline hinzugefügt",
@@ -67,32 +93,6 @@
67
93
  "pl": "aktualizacja Vicki device- config",
68
94
  "uk": "оновлення Vicki налаштування пристрою",
69
95
  "zh-cn": "更新 Vicki 设备配置"
70
- },
71
- "0.6.5": {
72
- "en": "setObject changed into setObjectAsync",
73
- "de": "menge Objekt geändert in Set ObjektAsync",
74
- "ru": "set Объект изменен на набор ОбъектАсинк",
75
- "pt": "conjunto Objeto alterado em conjunto ObjectAsync",
76
- "nl": "ingesteld Object veranderd in set ObjectAsync",
77
- "fr": "ensemble Objet modifié en jeu ObjetAsync",
78
- "it": "set Oggetto cambiato in set Luogo di origine",
79
- "es": "set Objeto cambiado en conjunto ObjectAsync",
80
- "pl": "zestaw Obiekt zmieniony w zestaw ObjectAsync",
81
- "uk": "комплекти Об'єкт змінився в комплекті Об'єктАсинхрон",
82
- "zh-cn": "设定 对象更改为集合 对象同步"
83
- },
84
- "0.6.4": {
85
- "en": "Change writing of deviceinformations at Ttn",
86
- "de": "Schreiben von Geräteinformationen bei Ttn ändern",
87
- "ru": "Изменение записи устройств в Ttn",
88
- "pt": "Alterar a escrita de informações de dispositivos no Ttn",
89
- "nl": "Het schrijven van apparaatinformatie bij Ttn wijzigen",
90
- "fr": "Modifier l'écriture des informations de l'appareil à Ttn",
91
- "it": "Cambia la scrittura di informazioni sui dispositivi a Ttn",
92
- "es": "Cambiar la escritura de las informaciones de dispositivo en Ttn",
93
- "pl": "Zmień pisanie informacji na temat treści w Ttn",
94
- "uk": "Зміна письмової інформації про пристрій",
95
- "zh-cn": "在 Ttn 更改设备信息的写入"
96
96
  }
97
97
  },
98
98
  "titleLang": {
@@ -1,4 +1,5 @@
1
1
  const { isDeepStrictEqual } = require("util");
2
+ const schedule = require("node-schedule");
2
3
 
3
4
  class directorieshandlerClass {
4
5
  constructor(adapter) {
@@ -32,6 +33,14 @@ class directorieshandlerClass {
32
33
  wifi: "wifi"
33
34
  };
34
35
 
36
+ this.cronJobs = {};
37
+ this.cronJobIds = {
38
+ checkTimestamp: "checkTimestamp"
39
+ };
40
+ this.cronJosValues = {
41
+ checkTimestamp: "* * * * *"
42
+ };
43
+
35
44
  /*********************************************************************
36
45
  * ********************* Definition of Assigns **********************
37
46
  * ******************************************************************/
@@ -189,6 +198,64 @@ class directorieshandlerClass {
189
198
  objectNative: "objectNative",
190
199
  objectIconPath: "objectIconPath"
191
200
  };
201
+
202
+ // Create cronjob to check timestamps (for device offline notification)
203
+ this.cronJobs[this.cronJobIds.checkTimestamp] = schedule.scheduleJob(this.cronJosValues.checkTimestamp,this.checkTimestamps.bind(this));
204
+
205
+ }
206
+
207
+ /*********************************************************************
208
+ * ************************ Check Timestamp *****************************
209
+ * ******************************************************************/
210
+
211
+ async checkTimestamps(){
212
+ const activeFunction = "checkTimestamps";
213
+ try{
214
+ const adapterObjects = await this.adapter.getAdapterObjectsAsync();
215
+ // Generate Infos of all defices and decoded folders
216
+ for(const adapterObject of Object.values(adapterObjects)){
217
+ if(adapterObject._id.endsWith(`${this.reachableSubfolders.uplinkRaw}.json`)){
218
+ const uplinkState = await this.adapter.getStateAsync(adapterObject._id);
219
+ if(uplinkState){
220
+ const msInOneHour = 1000 * 60 * 60;
221
+ const maxDifferenceMin = 0 * msInOneHour;
222
+ const maxDifferenceMax = 1 * msInOneHour;
223
+ const timestampNow = Date.now();
224
+ const timestampData = uplinkState.ts;
225
+ const difference = timestampNow - timestampData;
226
+ if(difference >= maxDifferenceMin && difference <= maxDifferenceMax){
227
+ const changeInfo = await this.adapter.getChangeInfo(adapterObject._id);
228
+ if(changeInfo){
229
+ this.adapter.registerNotification("lorawan", "LoRaWAN device offline", `The LoRaWAN device ${changeInfo.usedDeviceId} in the application ${changeInfo.usedApplicationName} is offline`);
230
+ const deviceFolderId = adapterObject._id.substring(0,adapterObject._id.indexOf(".uplink"));
231
+ const deviceFolderObject = await this.adapter.getObjectAsync(deviceFolderId);
232
+ // Set foldericon to low / no connection
233
+ if(deviceFolderObject){
234
+ deviceFolderObject.common.icon = "icons/wifiSfX_0.png";
235
+ await this.adapter.extendObjectAsync(deviceFolderId,{
236
+ common: deviceFolderObject.common,
237
+ });
238
+ }
239
+
240
+ //const devicefolder = await this.getObjectAsync()
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ catch(error){
248
+ this.adapter.log.error(`error at ${activeFunction}: ` + error);
249
+ }
250
+ }
251
+
252
+ // Clear all schedules, if there are some
253
+ clearAllSchedules(){
254
+ for(const cronJob in this.cronJobs)
255
+ {
256
+ schedule.cancelJob(this.cronJobs[cronJob]);
257
+ delete this.cronJobs[cronJob];
258
+ }
192
259
  }
193
260
 
194
261
  /*********************************************************************
@@ -70,7 +70,7 @@ class messagehandlerClass {
70
70
  const activeFunction = "generateDeviceinfosAtStartup";
71
71
  try{
72
72
  const adapterObjectsAtStart = await this.adapter.getAdapterObjectsAsync();
73
- // Generate Infos of all defices and decoded folders
73
+ // Generate Infos of all devices and decoded folders
74
74
  for(const adapterObject of Object.values(adapterObjectsAtStart)){
75
75
  if(adapterObject._id.endsWith(`${this.directoryhandler.reachableSubfolders.uplinkRaw}.json`)){
76
76
  const uplinkState = await this.adapter.getStateAsync(adapterObject._id);
package/main.js CHANGED
@@ -7,7 +7,6 @@
7
7
  // The adapter-core module gives you access to the core ioBroker functions
8
8
  // you need to create an adapter
9
9
  const utils = require("@iobroker/adapter-core");
10
- const schedule = require("node-schedule");
11
10
  const mqttClientClass = require("./lib/modules/mqttclient");
12
11
  const messagehandlerClass = require("./lib/modules/messagehandler");
13
12
  const downlinkConfighandlerClass = require("./lib/modules/downlinkConfighandler");
@@ -33,14 +32,6 @@ class Lorawan extends utils.Adapter {
33
32
  chirpstack: "chirpstack"
34
33
  };
35
34
 
36
- this.cronJobs = {};
37
- this.cronJobIds = {
38
- checkTimestamp: "checkTimestamp"
39
- };
40
- this.cronJosValues = {
41
- checkTimestamp: "* * * * *"//"0 * * * *"
42
- };
43
-
44
35
  // Simulation variables
45
36
  this.simulation = {};
46
37
  }
@@ -75,9 +66,6 @@ class Lorawan extends utils.Adapter {
75
66
  this.log.silly(`the adapter starts with downlinkconfigs: ${JSON.stringify(this.config.downlinkConfig)}.`);
76
67
  this.log.silly(`the active downlinkconfigs are: ${JSON.stringify(this.downlinkConfighandler.activeDownlinkConfigs)}`);
77
68
 
78
- // Create cronjob to check timestamps (for device offline notification)
79
- this.cronJobs[this.cronJobIds.checkTimestamp] = schedule.scheduleJob(this.cronJosValues.checkTimestamp,this.checkTimestamps.bind(this));
80
-
81
69
  /*setTimeout(async () => {
82
70
  await this.startSimulation();
83
71
  }, 5000);*/
@@ -93,36 +81,6 @@ class Lorawan extends utils.Adapter {
93
81
  }
94
82
  }
95
83
 
96
- async checkTimestamps(){
97
- const activeFunction = "checkTimestamps";
98
- try{
99
- const adapterObjects = await this.getAdapterObjectsAsync();
100
- // Generate Infos of all defices and decoded folders
101
- for(const adapterObject of Object.values(adapterObjects)){
102
- if(adapterObject._id.endsWith(`${this.messagehandler?.directoryhandler.reachableSubfolders.uplinkRaw}.json`)){
103
- const uplinkState = await this.getStateAsync(adapterObject._id);
104
- if(uplinkState){
105
- const msInOneHour = 1000 * 60 * 60;
106
- const maxDifferenceMin = 25 * msInOneHour;
107
- const maxDifferenceMax = 26 * msInOneHour;
108
- const timestampNow = Date.now();
109
- const timestampData = uplinkState.ts;
110
- const difference = timestampNow - timestampData;
111
- if(difference >= maxDifferenceMin && difference <= maxDifferenceMax){
112
- const changeInfo = await this.getChangeInfo(adapterObject._id);
113
- if(changeInfo){
114
- this.registerNotification("lorawan", "LoRaWAN device offline", `The LoRaWAN device ${changeInfo.usedDeviceId} in the application ${changeInfo.usedApplicationName} is offline`);
115
- }
116
- }
117
- }
118
- }
119
- }
120
- }
121
- catch(error){
122
- this.log.error(`error at ${activeFunction}: ` + error);
123
- }
124
- }
125
-
126
84
  async startSimulation(){
127
85
 
128
86
  // TTN
@@ -186,6 +144,11 @@ class Lorawan extends utils.Adapter {
186
144
  this.clearTimeout(this.simulation.timeout);
187
145
  delete this.simulation.timeout;
188
146
  }
147
+
148
+ // Clear Schedules im directoriehandler
149
+ this.messagehandler?.directoryhandler.clearAllSchedules();
150
+
151
+ // Destroy mqtt client
189
152
  this.mqttClient?.destroy();
190
153
  callback();
191
154
  } catch (e) {
@@ -552,15 +515,6 @@ class Lorawan extends utils.Adapter {
552
515
  this.log.error(`error at ${activeFunction}: ` + error);
553
516
  }
554
517
  }
555
-
556
- // Clear all schedules, if there are some
557
- clearAllSchedules(){
558
- for(const cronJob in this.cronJobs)
559
- {
560
- schedule.cancelJob(this.cronJobs[cronJob]);
561
- delete this.cronJobs[cronJob];
562
- }
563
- }
564
518
  }
565
519
 
566
520
  if (require.main !== module) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.lorawan",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "converts the desired lora gateway data to a ioBroker structure",
5
5
  "author": {
6
6
  "name": "BenAhrdt",