iobroker.lorawan 0.1.13 → 0.2.1

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
@@ -22,6 +22,12 @@ For now there is documentation in English here: http://www.hafenmeister.com/Lora
22
22
  Placeholder for the next version (at the beginning of the line):
23
23
  ### **WORK IN PROGRESS**
24
24
  -->
25
+ ### 0.2.1 (2024-02-13)
26
+ * (BenAhrdt) check types of messaging values and implements more blockly blocks
27
+
28
+ ### 0.2.0 (2024-02-12)
29
+ * (BenAhrdt) more functionality in messageing
30
+
25
31
  ### 0.1.13 (2024-02-12)
26
32
  * (BenAhrdt) building of directory changed and message implemented
27
33
 
@@ -0,0 +1,242 @@
1
+ /* eslint-disable prefer-const */
2
+ /* eslint-disable no-undef */
3
+ // @ts-nocheck
4
+ "use strict";
5
+
6
+ // @ts-ignore
7
+ if (typeof goog !== "undefined") {
8
+ // @ts-ignore
9
+ // eslint-disable-next-line no-undef
10
+ goog.provide("Blockly.JavaScript.Sendto");
11
+ // @ts-ignore
12
+ // eslint-disable-next-line no-undef
13
+ goog.require("Blockly.JavaScript");
14
+ }
15
+
16
+
17
+ // --- general translations --------------------------------------------------
18
+ Blockly.Words["anyInstance"] = {"en": "all instances","pt": "todas as instâncias","pl": "wszystkie przypadki","nl": "alle instanties","it": "tutte le istanze","es": "todas las instancias","fr": "toutes les instances","de": "Alle Instanzen","ru": "На все драйвера"};
19
+ Blockly.Words["lorawanDeviceEUI"] = {"en": "device EUI","de": "Geräte EUI","ru": "устройство EUI","pt": "dispositivo EUI","nl": "apparaat EUI","fr": "dispositif IUE","it": "dispositivo EUI","es": "dispositivo EUI","pl": "urządzenie EUI","uk": "пристрій EUI","zh-cn": "设备 EUI"};
20
+
21
+ /**************************************************************************
22
+ ******************************Get Device Info******************************
23
+ **************************************************************************/
24
+
25
+ // --- Get DeviceInfo translations --------------------------------------------------
26
+ Blockly.Words["lorawanGetDeviceInfo"] = {"en": "lorawan Device Info", "de": "lorawan Geräteinfo", "ru": "lorawan Device Info", "pt": "lorawan Informações do dispositivo", "nl": "lorawan Apparaatinformatie", "fr": "lorawan Informations sur le périphérique", "it": "lorawan Dispositivi Info", "es": "lorawan Device Info", "pl": "informacje o urządzeniu Lorawan", "uk": "інформація про пристрій lorawan", "zh-cn": "lorawan 设备信息"};
27
+ Blockly.Words["lorawanGetDeviceInfotooltip"] = {"en": "get Informations about the device with the given device EUI", "de": "informationen über das Gerät mit der angegebenen Geräte EUI", "ru": "получить информацию об устройстве с данным устройством EUI", "pt": "obter informações sobre o dispositivo com o dispositivo dado EUI", "nl": "informatie over het apparaat met het gegeven apparaat opvragen EUI", "fr": "obtenir des informations sur l'appareil avec l'appareil donné IUE", "it": "ottenere informazioni sul dispositivo con il dispositivo fornito EUI", "es": "obtener Información sobre el dispositivo con el dispositivo dado EUI", "pl": "pobierz informacje o urządzeniu z podanym urządzeniem EUI", "uk": "отримувати інформацію про пристрій з заданим пристроєм EUI", "zh-cn": "用指定的设备获取设备信息 EUI"};
28
+
29
+ // eslint-disable-next-line no-undef
30
+ Blockly.Sendto.blocks["lorawanGetDeviceInfo"] =
31
+ "<block type='lorawanGetDeviceInfo'>"
32
+ + " <value name='INSTANCE'>"
33
+ + " </value>"
34
+ + " <value name='deviceEUI'>"
35
+ + " <shadow type='text'>"
36
+ + " <field name='TEXT'>text</field>"
37
+ + " </shadow>"
38
+ + " </value>"
39
+ + "</block>";
40
+
41
+ // eslint-disable-next-line no-undef
42
+ Blockly.Blocks["lorawanGetDeviceInfo"] = {
43
+ init: function() {
44
+ const options = [[Blockly.Translate("anyInstance"), ""]];
45
+ if (typeof main !== "undefined" && main.instances) {
46
+ for (let i = 0; i < main.instances.length; i++) {
47
+ // eslint-disable-next-line prefer-const
48
+ let m = main.instances[i].match(/^system.adapter.lorawan.(\d+)$/);
49
+ if (m) {
50
+ // eslint-disable-next-line prefer-const
51
+ let k = parseInt(m[1], 10);
52
+ options.push(["lorawan." + k, "." + k]);
53
+ }
54
+ }
55
+ if (options.length === 0) {
56
+ for (let u = 0; u <= 4; u++) {
57
+ options.push(["lorawan." + u, "." + u]);
58
+ }
59
+ }
60
+ } else {
61
+ for (let n = 0; n <= 4; n++) {
62
+ options.push(["lorawan." + n, "." + n]);
63
+ }
64
+ }
65
+
66
+ this.appendDummyInput("INSTANCE")
67
+ .appendField(Blockly.Translate("lorawanGetDeviceInfo"))
68
+ .appendField(new Blockly.FieldDropdown(options), "INSTANCE");
69
+
70
+ this.appendValueInput("deviceEUI")
71
+ .appendField(Blockly.Translate("lorawanDeviceEUI"));
72
+
73
+ this.setColour(Blockly.Sendto.HUE);
74
+ this.setTooltip(Blockly.Translate("lorawanGetDeviceInfotooltip"));
75
+ }
76
+ };
77
+
78
+ Blockly.JavaScript["lorawanGetDeviceInfo"] = function(block){
79
+ const dropdown_instance = block.getFieldValue("INSTANCE");
80
+ const value_devEUI = Blockly.JavaScript.valueToCode(block, "deviceEUI", Blockly.JavaScript.ORDER_ATOMIC);
81
+ return 'sendTo("lorawan' + dropdown_instance + '", "getDeviceInfo", {deviceEUI: ' + value_devEUI + "}, async (result) => {console.log(result);});";
82
+ };
83
+
84
+ /**************************************************************************
85
+ *********************************Get uplink********************************
86
+ **************************************************************************/
87
+
88
+ // --- Get DeviceInfo translations --------------------------------------------------
89
+ Blockly.Words["lorawanGetUplink"] = {"en": "lorawan uplinkinfo", "de": "lorawan uplinkinfo", "ru": "lorawan uplinkinfo", "pt": "o que fazer", "nl": "lorawan uplinkinfo", "fr": "lorawan uplinkinfo", "it": "condividi su google", "es": "lorawan uplinkinfo", "pl": "lorawan uplinkinfo", "uk": "український", "zh-cn": "lorawan 上行链接信息"};
90
+ Blockly.Words["lorawanGetUplinktooltip"] = {"en": "get information about the given uplink", "de": "informationen zum angegebenen uplink", "ru": "получить информацию об отказе от ссылки", "pt": "obter informações sobre o link fornecido", "nl": "informatie krijgen over de opgegeven uplink", "fr": "obtenir des informations sur le lien ascendant donné", "it": "ottenere informazioni su il link up", "es": "obtener información sobre el enlace dado", "pl": "uzyskać informacje o danym łączniku", "uk": "отримувати інформацію про задану посилання", "zh-cn": "获取上行链路的信息"};
91
+ Blockly.Words["lorawanUplink"] = {"en": "uplink","de": "uplink","ru": "uplink", "pt": "o que é","nl": "uplink","fr": "lien ascendant","it": "uplink","es": "subtítulos","pl": "link","uk": "посилання","zh-cn": "上行链接"};
92
+ Blockly.Words["lorawanSubfolder"] = {"en": "subfolder", "de": "unterordner", "ru": "subfolder", "pt": "subpastas", "nl": "submap", "fr": "sous-dossier", "it": "sottocartella", "es": "subcarpeta", "pl": "podfolder", "uk": "підпалювач", "zh-cn": "子文件夹"};
93
+
94
+ // eslint-disable-next-line no-undef
95
+ Blockly.Sendto.blocks["lorawanGetUplink"] =
96
+ "<block type='lorawanGetUplink'>"
97
+ + " <value name='INSTANCE'>"
98
+ + " </value>"
99
+ + " <value name='deviceEUI'>"
100
+ + " <shadow type='text'>"
101
+ + " <field name='TEXT'>text</field>"
102
+ + " </shadow>"
103
+ + " </value>"
104
+ + " <value name='uplink'>"
105
+ + " <shadow type='text'>"
106
+ + " <field name='TEXT'>text</field>"
107
+ + " </shadow>"
108
+ + " </value>"
109
+ + " <value name='subfolder'>"
110
+ + " <shadow type='text'>"
111
+ + " <field name='TEXT'>decoded</field>"
112
+ + " </shadow>"
113
+ + " </value>"
114
+ + "</block>";
115
+
116
+ // eslint-disable-next-line no-undef
117
+ Blockly.Blocks["lorawanGetUplink"] = {
118
+ init: function() {
119
+ const options = [[Blockly.Translate("anyInstance"), ""]];
120
+ if (typeof main !== "undefined" && main.instances) {
121
+ for (let i = 0; i < main.instances.length; i++) {
122
+ // eslint-disable-next-line prefer-const
123
+ let m = main.instances[i].match(/^system.adapter.lorawan.(\d+)$/);
124
+ if (m) {
125
+ // eslint-disable-next-line prefer-const
126
+ let k = parseInt(m[1], 10);
127
+ options.push(["lorawan." + k, "." + k]);
128
+ }
129
+ }
130
+ if (options.length === 0) {
131
+ for (let u = 0; u <= 4; u++) {
132
+ options.push(["lorawan." + u, "." + u]);
133
+ }
134
+ }
135
+ } else {
136
+ for (let n = 0; n <= 4; n++) {
137
+ options.push(["lorawan." + n, "." + n]);
138
+ }
139
+ }
140
+
141
+ this.appendDummyInput("INSTANCE")
142
+ .appendField(Blockly.Translate("lorawanGetUplink"))
143
+ .appendField(new Blockly.FieldDropdown(options), "INSTANCE");
144
+
145
+ this.appendValueInput("deviceEUI")
146
+ .appendField(Blockly.Translate("lorawanDeviceEUI"));
147
+
148
+ this.appendValueInput("uplink")
149
+ .appendField(Blockly.Translate("lorawanUplink"));
150
+
151
+ this.appendValueInput("subfolder")
152
+ .appendField(Blockly.Translate("lorawanSubfolder"));
153
+
154
+ this.setColour(Blockly.Sendto.HUE);
155
+ this.setTooltip(Blockly.Translate("lorawanGetUplinktooltip"));
156
+ }
157
+ };
158
+
159
+ Blockly.JavaScript["lorawanGetUplink"] = function(block){
160
+ const dropdown_instance = block.getFieldValue("INSTANCE");
161
+ const value_devEUI = Blockly.JavaScript.valueToCode(block, "deviceEUI", Blockly.JavaScript.ORDER_ATOMIC);
162
+ const value_uplink = Blockly.JavaScript.valueToCode(block, "uplink", Blockly.JavaScript.ORDER_ATOMIC);
163
+ const value_subfolder = Blockly.JavaScript.valueToCode(block, "subfolder", Blockly.JavaScript.ORDER_ATOMIC);
164
+ return 'sendTo("lorawan' + dropdown_instance + '", "getUplink", {deviceEUI: ' + value_devEUI + ", uplink: " + value_uplink + ", subfolder: " + value_subfolder +"}, async (result) => {console.log(result);});";
165
+ };
166
+
167
+ /**************************************************************************
168
+ *******************************Set downlink********************************
169
+ **************************************************************************/
170
+
171
+ // --- Get DeviceInfo translations --------------------------------------------------
172
+ Blockly.Words["lorawanSetDownlink"] = {"en": "lorawan downlink", "de": "lorawan downlink", "ru": "lorawan downlink", "pt": "para baixo", "nl": "lorawan downlink", "fr": "lorawan lien descendant", "it": "lorawan downlink", "es": "lorawan downlink", "pl": "lorawan downlink", "uk": "логін", "zh-cn": "龙卷风下行链路"};
173
+ Blockly.Words["lorawanSetDownlinktooltip"] = {"en": "set downlink", "de": "downlink zur lorawan instanz absetzen", "ru": "set downlink", "pt": "definir link", "nl": "downlink instellen", "fr": "définir la liaison descendante", "it": "impostare il collegamento", "es": "desplazamiento", "pl": "set downlink", "uk": "увійти", "zh-cn": "设置下行链路"};
174
+ Blockly.Words["lorawanDownlink"] = {"en": "downlink","de": "downlink","ru": "downlink", "pt": "o que é","nl": "downlink","fr": "lien ascendant","it": "downlink","es": "subtítulos","pl": "link","uk": "посилання","zh-cn": "上行链接"};
175
+
176
+ // eslint-disable-next-line no-undef
177
+ Blockly.Sendto.blocks["lorawanSetDownlink"] =
178
+ "<block type='lorawanSetDownlink'>"
179
+ + " <value name='INSTANCE'>"
180
+ + " </value>"
181
+ + " <value name='deviceEUI'>"
182
+ + " <shadow type='text'>"
183
+ + " <field name='TEXT'>text</field>"
184
+ + " </shadow>"
185
+ + " </value>"
186
+ + " <value name='downlink'>"
187
+ + " <shadow type='text'>"
188
+ + " <field name='TEXT'>text</field>"
189
+ + " </shadow>"
190
+ + " </value>"
191
+ + " <value name='xxxx'>"
192
+ + " <shadow type='text'>"
193
+ + " <field name='xx'>cc</field>"
194
+ + " </shadow>"
195
+ + " </value>"
196
+ + "</block>";
197
+
198
+ // eslint-disable-next-line no-undef
199
+ Blockly.Blocks["lorawanSetDownlink"] = {
200
+ init: function() {
201
+ const options = [[Blockly.Translate("anyInstance"), ""]];
202
+ if (typeof main !== "undefined" && main.instances) {
203
+ for (let i = 0; i < main.instances.length; i++) {
204
+ let m = main.instances[i].match(/^system.adapter.lorawan.(\d+)$/);
205
+ if (m) {
206
+ // eslint-disable-next-line prefer-const
207
+ let k = parseInt(m[1], 10);
208
+ options.push(["lorawan." + k, "." + k]);
209
+ }
210
+ }
211
+ if (options.length === 0) {
212
+ for (let u = 0; u <= 4; u++) {
213
+ options.push(["lorawan." + u, "." + u]);
214
+ }
215
+ }
216
+ } else {
217
+ for (let n = 0; n <= 4; n++) {
218
+ options.push(["lorawan." + n, "." + n]);
219
+ }
220
+ }
221
+
222
+ this.appendDummyInput("INSTANCE")
223
+ .appendField(Blockly.Translate("lorawanSetDownlink"))
224
+ .appendField(new Blockly.FieldDropdown(options), "INSTANCE");
225
+
226
+ this.appendValueInput("deviceEUI")
227
+ .appendField(Blockly.Translate("lorawanDeviceEUI"));
228
+
229
+ this.appendValueInput("downlink")
230
+ .appendField(Blockly.Translate("lorawanDownlink"));
231
+
232
+ this.setColour(Blockly.Sendto.HUE);
233
+ this.setTooltip(Blockly.Translate("lorawanSetDownlinktooltip"));
234
+ }
235
+ };
236
+
237
+ Blockly.JavaScript["lorawanSetDownlink"] = function(block){
238
+ const dropdown_instance = block.getFieldValue("INSTANCE");
239
+ const value_devEUI = Blockly.JavaScript.valueToCode(block, "deviceEUI", Blockly.JavaScript.ORDER_ATOMIC);
240
+ const value_downlink = Blockly.JavaScript.valueToCode(block, "downlink", Blockly.JavaScript.ORDER_ATOMIC);
241
+ return 'sendTo("lorawan' + dropdown_instance + '", "setDownlink", {deviceEUI: ' + value_devEUI + ", downlink: " + value_downlink +"}, async (result) => {console.log(result);});";
242
+ };
package/io-package.json CHANGED
@@ -1,8 +1,34 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "lorawan",
4
- "version": "0.1.13",
4
+ "version": "0.2.1",
5
5
  "news": {
6
+ "0.2.1": {
7
+ "en": "check types of messaging values and implements more blockly blocks",
8
+ "de": "überprüfen sie die arten der messaging-werte und implementiert mehr blockweise blöcke",
9
+ "ru": "проверить типы значений обмена сообщениями и реализовать более блоков",
10
+ "pt": "verificar os tipos de valores de mensagens e implementa blocos mais bloqueados",
11
+ "nl": "controleer soorten messaging waarden en implementeert meer blokken",
12
+ "fr": "vérifier les types de valeurs de messagerie et implémente des blocs plus bloc",
13
+ "it": "controllare i tipi di valori di messaggistica e implementa più blocchi bloccati",
14
+ "es": "comprobar tipos de valores de mensajería e implementar bloques más bloque",
15
+ "pl": "sprawdzają typy wartości wiadomości i wdrażają blokowane bloki",
16
+ "uk": "перевіряти типи значень обміну повідомленнями та реалізовувати більше блоків",
17
+ "zh-cn": "检查消息值的类型, 执行更多块"
18
+ },
19
+ "0.2.0": {
20
+ "en": "more functionality in messageing",
21
+ "de": "mehr funktionalität in der meldung",
22
+ "ru": "больше функциональности в сообщении",
23
+ "pt": "mais funcionalidade em mensagens",
24
+ "nl": "meer functionaliteit in berichtgeving",
25
+ "fr": "plus de fonctionnalité dans la messagerie",
26
+ "it": "più funzionalità nel messaggio",
27
+ "es": "más funcionalidad en el mensaje",
28
+ "pl": "większa funkcjonalność w zakresie rozwiązywania problemów",
29
+ "uk": "більше функцій в повідомленнях",
30
+ "zh-cn": "信件中更多的功能"
31
+ },
6
32
  "0.1.13": {
7
33
  "en": "building of directory changed and message implemented",
8
34
  "de": "aufbau des geänderten verzeichnisses und der implementierten meldung",
@@ -67,32 +93,6 @@
67
93
  "pl": "crc obliczenia improuved",
68
94
  "uk": "розрахунок обертів",
69
95
  "zh-cn": "crc 计算未启动"
70
- },
71
- "0.1.8": {
72
- "en": "implement crc calculation",
73
- "de": "ck-berechnung implementieren",
74
- "ru": "целевые вычисления",
75
- "pt": "cálculo de crc de implementação",
76
- "nl": "crc berekening uitvoeren",
77
- "fr": "mettre en œuvre le calcul crc",
78
- "it": "implementare il calcolo crc",
79
- "es": "cálculo de crc",
80
- "pl": "implementation crc calculation",
81
- "uk": "реалізація розрахунку кришки",
82
- "zh-cn": "执行计算"
83
- },
84
- "0.1.7": {
85
- "en": "change filter on statechange",
86
- "de": "änderungsfilter auf statechange",
87
- "ru": "изменение фильтра для изменения состояния",
88
- "pt": "filtro de mudança de estado",
89
- "nl": "filter wijzigen bij statusverandering",
90
- "fr": "modifier le filtre sur le changement d'état",
91
- "it": "cambiare il filtro sul cambio di stato",
92
- "es": "filtro de cambio en el cambio de estado",
93
- "pl": "zmienić filtr na statechange",
94
- "uk": "зміна фільтра на державну зміну",
95
- "zh-cn": "状态更改过滤器"
96
96
  }
97
97
  },
98
98
  "title": "LoRaWAN",
@@ -143,6 +143,7 @@
143
143
  "connectionType": "cloud",
144
144
  "messagebox": true,
145
145
  "dataSource": "push",
146
+ "blockly": true,
146
147
  "adminUI": {
147
148
  "config": "json"
148
149
  },
@@ -36,7 +36,9 @@
36
36
  "multiplyfaktor": 60,
37
37
  "unit": "min",
38
38
  "onClick": "030111",
39
- "crc":"noCrc"
39
+ "crc":"noCrc",
40
+ "limitMin": true,
41
+ "limitMinValue": 1
40
42
  },
41
43
  {
42
44
  "name": "RO2_target",
@@ -19,7 +19,9 @@
19
19
  "off": "",
20
20
  "multiplyfaktor": 60,
21
21
  "unit": "min",
22
- "crc":"noCrc"
22
+ "crc":"noCrc",
23
+ "limitMin": true,
24
+ "limitMinValue": 1
23
25
  },
24
26
  {
25
27
  "name": "Reboot",
@@ -37,7 +37,9 @@
37
37
  "onClick": "030111",
38
38
  "multiplyfaktor": "1",
39
39
  "unit": "Minuten",
40
- "crc":"noCrc"
40
+ "crc":"noCrc",
41
+ "limitMin": true,
42
+ "limitMinValue": 1
41
43
  },
42
44
  {
43
45
  "name": "Vicki_Target_Temperature",
@@ -13,9 +13,11 @@ class directorieshandlerClass {
13
13
 
14
14
  this.reachableSubfolders = {
15
15
  configuration: "configuration",
16
+ uplink: "uplink",
16
17
  uplinkDecoded: "uplink.decoded",
17
18
  uplinkRaw: "uplink.raw",
18
19
  uplinkRemaining: "uplink.remaining",
20
+ downlink: "downlink",
19
21
  downlinkRaw: "downlink.raw",
20
22
  downlinkControl: "downlink.control",
21
23
  downlinkRemaining: "downlink.remaining",
@@ -113,7 +113,7 @@ class messagehandlerClass {
113
113
  else if(stateCommonType === "number"){
114
114
  stateCommonMax = 1000000;
115
115
  }
116
- await this.adapter.extendObjectAsync(`${deviceStartdirectory}.downlink.control.${downlinkParameter.name}`,{
116
+ await this.adapter.extendObjectAsync(`${deviceStartdirectory}.${this.directoryhandler.reachableSubfolders.downlinkControl}.${downlinkParameter.name}`,{
117
117
  type: "state",
118
118
  common: {
119
119
  name: "",
package/main.js CHANGED
@@ -375,6 +375,20 @@ class Lorawan extends utils.Adapter {
375
375
  return id;
376
376
  }
377
377
 
378
+ // Get Changeinfo in case of device EUI (used more times in onMessage)
379
+ async getChangeInfoFromDeviceEUI(deviceUI,subId){
380
+ let changeInfo = undefined;
381
+ const adapterObjects = await this.getAdapterObjectsAsync();
382
+ for(const adapterObject of Object.values(adapterObjects)){
383
+ if(adapterObject.type === "device"){
384
+ if(adapterObject._id.indexOf(deviceUI) !== -1){
385
+ changeInfo = await this.getChangeInfo(`${adapterObject._id}.${subId}`);
386
+ break;
387
+ }
388
+ }
389
+ }
390
+ return changeInfo;
391
+ }
378
392
 
379
393
  // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor.
380
394
  // /**
@@ -382,25 +396,18 @@ class Lorawan extends utils.Adapter {
382
396
  // * Using this method requires "common.messagebox" property to be set to true in io-package.json
383
397
  // * @param {ioBroker.Message} obj
384
398
  // */
399
+
385
400
  async onMessage(obj){
386
401
  const activeFunction = "onMessage";
402
+ this.log.debug(`message recieved: command = ${obj.command} - message = ${JSON.stringify(obj.message)}`);
387
403
  try{
388
404
  if (typeof obj === "object" && obj.message){
389
405
  let result = {};
390
406
  if(obj.command === "getDeviceInfo"){
391
407
  if(obj.message.deviceEUI){
392
- let changeInfo = undefined;
393
- const adapterObjects = await this.getAdapterObjectsAsync();
394
- for(const adapterObject of Object.values(adapterObjects)){
395
- if(adapterObject.type === "device"){
396
- if(adapterObject._id.indexOf(obj.message.deviceEUI) !== -1){
397
- changeInfo = await this.getChangeInfo(`${adapterObject._id}.${this.messagehandler?.directoryhandler.reachableSubfolders.configuration}.devicetype`);
398
- break;
399
- }
400
- }
401
- }
408
+ const changeInfo = await this.getChangeInfoFromDeviceEUI(obj.message.deviceEUI,`${this.messagehandler?.directoryhandler.reachableSubfolders.configuration}.devicetype`);
402
409
  if(changeInfo){
403
- result = {applicationId: changeInfo.applicationId, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId};
410
+ result = {applicationId: changeInfo.applicationId, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, deviceType: changeInfo.deviceType};
404
411
  }
405
412
  else{
406
413
  result = {error:true, message:"No device found"};
@@ -412,38 +419,37 @@ class Lorawan extends utils.Adapter {
412
419
  // Send response
413
420
  if (obj.callback) this.sendTo(obj.from, obj.command, result, obj.callback);
414
421
  }
415
- else if (obj.command === "sendDownlink"){
422
+ else if (obj.command === "setDownlink"){
416
423
  if(obj.message.deviceEUI && obj.message.downlink && (obj.message.value || obj.message.value === false)){
417
- let changeInfo = undefined;
418
- const adapterObjects = await this.getAdapterObjectsAsync();
419
- for(const adapterObject of Object.values(adapterObjects)){
420
- if(adapterObject.type === "device"){
421
- if(adapterObject._id.indexOf(obj.message.deviceEUI) !== -1){
422
- changeInfo = await this.getChangeInfo(`${adapterObject._id}.${this.messagehandler?.directoryhandler.reachableSubfolders.downlinkControl}.${obj.message.downlink}`);
423
- break;
424
- }
425
- }
426
- }
424
+ const changeInfo = await this.getChangeInfoFromDeviceEUI(obj.message.deviceEUI,`${this.messagehandler?.directoryhandler.reachableSubfolders.downlinkControl}.${obj.message.downlink}`);
427
425
  if(changeInfo){
428
- const downlinkId = `${changeInfo.id}`;
426
+ const downlinkId = changeInfo.id;
429
427
  if(await this.objectExists(downlinkId)){
430
- const downlinkParameter = this.downlinkConfighandler?.getDownlinkParameter(changeInfo);
431
- // downlinkvalue is type number
432
- if(downlinkParameter.type === "number"){
433
- // Check limit
434
- if((!downlinkParameter.limitMin || obj.message.value >= downlinkParameter.limitMinValue) && (!downlinkParameter.limitMax || obj.message.value <= downlinkParameter.limitMaxValue)){
435
- await this.setStateAsync(downlinkId,obj.message.value);
436
- result = {applicationId: changeInfo.applicationId, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, downlink: obj.message.downlink, value: obj.message.value};
428
+ // get Object to decide min and max value
429
+ const downlinkObject = await this.getObjectAsync(downlinkId);
430
+ if(downlinkObject){
431
+ // check typ number
432
+ if(downlinkObject.common.type === "number"){
433
+ if(typeof obj.message.value === "number"){
434
+ // Check limit
435
+ if((!downlinkObject.common.min || obj.message.value >= downlinkObject.common.min) && (!downlinkObject.common.max || obj.message.value <= downlinkObject.common.max)){
436
+ await this.setStateAsync(downlinkId,obj.message.value);
437
+ result = {applicationId: changeInfo.applicationId, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, deviceType: changeInfo.deviceType,downlink: obj.message.downlink, value: obj.message.value};
438
+ }
439
+ else{
440
+ result = {error:true, message:"value is not in valid range"};
441
+ }
442
+ }
443
+ else{
444
+ result = {error:true, message: `downlink is type number, but recieved ${typeof obj.message.value}`};
445
+ }
437
446
  }
447
+ // downlinkobject is not a number
438
448
  else{
439
- result = {error:true, message:"value is not in valid range"};
449
+ await this.setStateAsync(downlinkId,obj.message.value);
450
+ result = {applicationId: changeInfo.applicationId, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, deviceType: changeInfo.deviceType, downlink: obj.message.downlink, value: obj.message.value};
440
451
  }
441
452
  }
442
- // downlinkvalue not a number
443
- else{
444
- await this.setStateAsync(downlinkId,obj.message.value);
445
- result = {applicationId: changeInfo.applicationId, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, downlink: obj.message.downlink, value: obj.message.value};
446
- }
447
453
  }
448
454
  else{
449
455
  result = {error:true, message:"No downlink matches"};
@@ -459,7 +465,34 @@ class Lorawan extends utils.Adapter {
459
465
  // Send response
460
466
  if (obj.callback) this.sendTo(obj.from, obj.command, result, obj.callback);
461
467
  }
462
- else{
468
+ else if (obj.command === "getUplink"){
469
+ if(obj.message.deviceEUI && obj.message.uplink){
470
+ const folderAndUplinkId = obj.message.subfolder? `${this.messagehandler?.directoryhandler.reachableSubfolders.uplink}.${obj.message.subfolder}.${obj.message.uplink}`: obj.message.uplink;
471
+ const changeInfo = await this.getChangeInfoFromDeviceEUI(obj.message.deviceEUI,folderAndUplinkId);
472
+ if(changeInfo){
473
+ const uplinkId = changeInfo.id;
474
+ if(await this.objectExists(uplinkId)){
475
+ const stateResult = await this.getStateAsync(changeInfo.id);
476
+ if(stateResult){
477
+ result = {applicationId: changeInfo.applicationId, deviceEUI: changeInfo.deviceEUI, deviceId: changeInfo.deviceId, deviceType: changeInfo.deviceType, value: stateResult.val};
478
+ }
479
+ }
480
+ else{
481
+ result = {error:true, message:"No uplink matches", changeInfo: changeInfo};
482
+ }
483
+ }
484
+ else{
485
+ result = {error:true, message:"No device found"};
486
+ }
487
+ }
488
+ else{
489
+ result = {error:true, message:"No deviceEUI & uplink found"};
490
+ }
491
+ // Send response
492
+ if (obj.callback) this.sendTo(obj.from, obj.command, result, obj.callback);
493
+ }
494
+ else
495
+ {
463
496
  const result = {error:true, message: "No message matched"};
464
497
  if (obj.callback) this.sendTo(obj.from, obj.command, result, obj.callback);
465
498
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.lorawan",
3
- "version": "0.1.13",
3
+ "version": "0.2.1",
4
4
  "description": "converts the desired lora gateway data to a ioBroker structure",
5
5
  "author": {
6
6
  "name": "BenAhrdt",