iobroker.lorawan 0.0.11 → 0.0.12
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 +3 -0
- package/io-package.json +14 -14
- package/lib/modules/directorieshandler.js +6 -6
- package/lib/modules/downlinkConfighandler.js +30 -29
- package/lib/modules/messagehandler.js +9 -3
- package/main.js +27 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,9 @@ Adapter was created in collaboration with Joerg Froehner LoraWan@hafenmeister.co
|
|
|
19
19
|
Placeholder for the next version (at the beginning of the line):
|
|
20
20
|
### **WORK IN PROGRESS**
|
|
21
21
|
-->
|
|
22
|
+
### 0.0.12 (2024-01-21)
|
|
23
|
+
* (BenAhrdt) change flow of downlink
|
|
24
|
+
|
|
22
25
|
### 0.0.11 (2024-01-20)
|
|
23
26
|
* (BenAhrdt) toSend und lastSend added to folders
|
|
24
27
|
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "lorawan",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"news": {
|
|
6
|
+
"0.0.12": {
|
|
7
|
+
"en": "change flow of downlink",
|
|
8
|
+
"de": "wechselstrom von downlink",
|
|
9
|
+
"ru": "изменение потока обратных ссылок",
|
|
10
|
+
"pt": "fluxo de mudança de downlink",
|
|
11
|
+
"nl": "verandering stroom van downlink",
|
|
12
|
+
"fr": "changement de flux de liaison descendante",
|
|
13
|
+
"it": "cambiamento flusso di downlink",
|
|
14
|
+
"es": "flujo de cambio de enlace descendente",
|
|
15
|
+
"pl": "zmiana przepływu w dół",
|
|
16
|
+
"uk": "зміна потоку вниз",
|
|
17
|
+
"zh-cn": "下行链路的改变"
|
|
18
|
+
},
|
|
6
19
|
"0.0.11": {
|
|
7
20
|
"en": "toSend und lastSend added to folders",
|
|
8
21
|
"de": "toSend und lastSend in Ordnern hinzugefügt",
|
|
@@ -80,19 +93,6 @@
|
|
|
80
93
|
"pl": "wstaw całe tłumaczenie dla config i przesuń niektóre funkcje",
|
|
81
94
|
"uk": "вставити весь переклад для налаштування та переміщення деяких функцій",
|
|
82
95
|
"zh-cn": "插入配置的全部翻译并移动一些函数"
|
|
83
|
-
},
|
|
84
|
-
"0.0.5": {
|
|
85
|
-
"en": "delete not configed states at startup",
|
|
86
|
-
"de": "nicht konfiszierte staaten beim start löschen",
|
|
87
|
-
"ru": "удалить не настроенные состояния при запуске",
|
|
88
|
-
"pt": "excluir estados não configurados na inicialização",
|
|
89
|
-
"nl": "verwijderde niet-geconfigeerde toestanden bij opstarten",
|
|
90
|
-
"fr": "supprimer les états non configurés au démarrage",
|
|
91
|
-
"it": "delete not configed stati all'avvio",
|
|
92
|
-
"es": "eliminar estados no confiados al inicio",
|
|
93
|
-
"pl": "usuń nieskonfigurowane stany przy starcie",
|
|
94
|
-
"uk": "видалити не налаштовані стани при запуску",
|
|
95
|
-
"zh-cn": "删除启动时未配置状态"
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"title": "LoRaWAN",
|
|
@@ -19,13 +19,11 @@ class directorieshandlerClass {
|
|
|
19
19
|
downlinkRaw: "downlinkRaw",
|
|
20
20
|
downlinkConfiguration: "downlinkConfiguration",
|
|
21
21
|
downlinkControl: "downlinkControl",
|
|
22
|
-
downlinkToSend: "downlinkToSend",
|
|
23
|
-
downlinkLastSend: "downlinkLastSend",
|
|
24
22
|
downlinkRemaining: "downlinkRemaining"
|
|
25
23
|
};
|
|
26
24
|
|
|
27
25
|
this.directoryStructur = {
|
|
28
|
-
|
|
26
|
+
downlinkNextSend: "downlink.nextSend",
|
|
29
27
|
downlinkLastSend: "downlink.lastSend"
|
|
30
28
|
};
|
|
31
29
|
|
|
@@ -81,15 +79,17 @@ class directorieshandlerClass {
|
|
|
81
79
|
configuration:{
|
|
82
80
|
safeDirectory: this.safeableDirectories.downlinkConfiguration,
|
|
83
81
|
},
|
|
84
|
-
|
|
85
|
-
safeDirectory: this.safeableDirectories.downlinkToSend,
|
|
82
|
+
nextSend:{
|
|
86
83
|
hex:{
|
|
87
84
|
isState: true,
|
|
88
85
|
stateCommonType: "string"
|
|
89
86
|
}
|
|
90
87
|
},
|
|
91
88
|
lastSend:{
|
|
92
|
-
|
|
89
|
+
hex:{
|
|
90
|
+
isState: true,
|
|
91
|
+
stateCommonType: "string"
|
|
92
|
+
}
|
|
93
93
|
},
|
|
94
94
|
remaining:{
|
|
95
95
|
safeDirectory: this.safeableDirectories.downlinkRemaining
|
|
@@ -69,14 +69,32 @@ class downlinkConfighandlerClass {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
/*********************************************************************
|
|
73
|
+
* *********************** Downlinktopic *****************************
|
|
74
|
+
* ******************************************************************/
|
|
75
|
+
|
|
76
|
+
getDownlinkTopic(changeInfo,suffix){
|
|
77
|
+
// Select downlinktopic in case of origin
|
|
78
|
+
switch(this.adapter.config.origin){
|
|
79
|
+
case "ttn":
|
|
80
|
+
return this.getTtnDownlinkTopicFromDirektory(changeInfo,suffix);
|
|
81
|
+
case "chirpstack":
|
|
82
|
+
return this.getChirpstackDownlinkTopicFromDirektory(changeInfo,suffix);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/*********************************************************************
|
|
87
|
+
* ************************** Downlink *******************************
|
|
88
|
+
* ******************************************************************/
|
|
89
|
+
|
|
90
|
+
getDownlink(downlinkConfig,payloadInHex,changeInfo){
|
|
73
91
|
// Select downlink in case of origin
|
|
74
92
|
this.adapter.log.silly(`the downlink for the changeinfo ${JSON.stringify(changeInfo)} is requested`);
|
|
75
93
|
switch(this.adapter.config.origin){
|
|
76
94
|
case "ttn":
|
|
77
|
-
return
|
|
95
|
+
return this.getTtnDownlink(downlinkConfig,payloadInHex);
|
|
78
96
|
case "chirpstack":
|
|
79
|
-
return
|
|
97
|
+
return this.getChirpstackDownlink(downlinkConfig,payloadInHex,changeInfo);
|
|
80
98
|
}
|
|
81
99
|
}
|
|
82
100
|
|
|
@@ -84,7 +102,7 @@ class downlinkConfighandlerClass {
|
|
|
84
102
|
* ******************* Calculation of payload ************************
|
|
85
103
|
* ******************************************************************/
|
|
86
104
|
|
|
87
|
-
|
|
105
|
+
calculatePayloadInHex(downlinkConfig,state){
|
|
88
106
|
// declare pyaload variable
|
|
89
107
|
this.adapter.log.silly(`the payload will be calculated`);
|
|
90
108
|
let payloadInHex = "";
|
|
@@ -126,27 +144,7 @@ class downlinkConfighandlerClass {
|
|
|
126
144
|
break;
|
|
127
145
|
}
|
|
128
146
|
}
|
|
129
|
-
|
|
130
|
-
//write hex into toSend state
|
|
131
|
-
const idFolder = `${changeInfo.obectStartDirectory}.${this.adapter.messagehandler.directoryhandler.directoryStructur.downlinkToSend}`;
|
|
132
|
-
await this.adapter.setStateAsync(`${idFolder}.hex`,payloadInHex,true);
|
|
133
|
-
|
|
134
|
-
//convert hex in base64
|
|
135
|
-
return Buffer.from(payloadInHex, "hex").toString("base64");
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/*********************************************************************
|
|
139
|
-
* *********************** Downlinktopic *****************************
|
|
140
|
-
* ******************************************************************/
|
|
141
|
-
|
|
142
|
-
getDownlinkTopic(changeInfo,suffix){
|
|
143
|
-
// Select downlinktopic in case of origin
|
|
144
|
-
switch(this.adapter.config.origin){
|
|
145
|
-
case "ttn":
|
|
146
|
-
return this.getTtnDownlinkTopicFromDirektory(changeInfo,suffix);
|
|
147
|
-
case "chirpstack":
|
|
148
|
-
return this.getChirpstackDownlinkTopicFromDirektory(changeInfo,suffix);
|
|
149
|
-
}
|
|
147
|
+
return payloadInHex;
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
/*********************************************************************
|
|
@@ -178,9 +176,11 @@ class downlinkConfighandlerClass {
|
|
|
178
176
|
* ************************** Downlink ******************************
|
|
179
177
|
* ******************************************************************/
|
|
180
178
|
|
|
181
|
-
|
|
179
|
+
getTtnDownlink(downlinkConfig,payloadInHex){
|
|
182
180
|
this.adapter.log.silly(`the downlink for ttn is requested`);
|
|
183
|
-
|
|
181
|
+
|
|
182
|
+
//convert hex in base64
|
|
183
|
+
const payloadInBase64 = Buffer.from(payloadInHex, "hex").toString("base64");
|
|
184
184
|
// retun the whole downlink
|
|
185
185
|
return {downlinks:[{f_port:downlinkConfig.port,frm_payload:payloadInBase64,priority:downlinkConfig.priority,confirmed:downlinkConfig.confirmed}]};
|
|
186
186
|
}
|
|
@@ -217,9 +217,10 @@ class downlinkConfighandlerClass {
|
|
|
217
217
|
* ************************** Downlink ******************************
|
|
218
218
|
* ******************************************************************/
|
|
219
219
|
|
|
220
|
-
|
|
220
|
+
getChirpstackDownlink(downlinkConfig,payloadInHex,changeInfo){
|
|
221
221
|
this.adapter.log.silly(`the downlink for chirpstack is requested`);
|
|
222
|
-
|
|
222
|
+
|
|
223
|
+
const payloadInBase64 = Buffer.from(payloadInHex, "hex").toString("base64");
|
|
223
224
|
// retun the whole downlink
|
|
224
225
|
return {devEui:changeInfo.dev_uid,confirmed:downlinkConfig.confirmed,fPort:downlinkConfig.port,data:payloadInBase64};
|
|
225
226
|
}
|
|
@@ -29,8 +29,7 @@ class messagehandlerClass {
|
|
|
29
29
|
if(adapterObject.type === "channel" && adapterObject.common.name !== "Information"){
|
|
30
30
|
const stateId = this.adapter.removeNamespace(adapterObject._id);
|
|
31
31
|
await this.fillWithDownlinkConfig(stateId);
|
|
32
|
-
await this.addDirectoriesToPresentDirectory(`${stateId}
|
|
33
|
-
await this.addDirectoriesToPresentDirectory(`${stateId}.${this.directoryhandler.directoryStructur.downlinkLastSend}`);
|
|
32
|
+
await this.addDirectoriesToPresentDirectory(`${stateId}`);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
@@ -47,7 +46,8 @@ class messagehandlerClass {
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
async addDirectoriesToPresentDirectory(startDirectory){
|
|
50
|
-
this.directoryhandler.generateRekursivObjects(this.directoryhandler.directories.application.devices.deviceUid.deviceId.downlink.
|
|
49
|
+
this.directoryhandler.generateRekursivObjects(this.directoryhandler.directories.application.devices.deviceUid.deviceId.downlink.nextSend,`${startDirectory}.${this.directoryhandler.directoryStructur.downlinkNextSend}`,"","");
|
|
50
|
+
this.directoryhandler.generateRekursivObjects(this.directoryhandler.directories.application.devices.deviceUid.deviceId.downlink.lastSend,`${startDirectory}.${this.directoryhandler.directoryStructur.downlinkLastSend}`,"","");
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async fillWithDownlinkConfig(deviceStartdirectory){
|
|
@@ -119,6 +119,12 @@ class messagehandlerClass {
|
|
|
119
119
|
|
|
120
120
|
await this.directoryhandler.generateRekursivObjects(this.directoryhandler.directories,"",topic,message);
|
|
121
121
|
|
|
122
|
+
/*********************************************************************
|
|
123
|
+
* ******************* Check downlink at uplink **********************
|
|
124
|
+
* ******************************************************************/
|
|
125
|
+
|
|
126
|
+
//await this.adapter.checkSendDOwnlinkWithUplink(`${deviceStartdirectory}.mytest`);
|
|
127
|
+
|
|
122
128
|
/*********************************************************************
|
|
123
129
|
* ************************* Infodata ********************************
|
|
124
130
|
* ******************************************************************/
|
package/main.js
CHANGED
|
@@ -109,21 +109,23 @@ class Lorawan extends utils.Adapter {
|
|
|
109
109
|
if(this.config.origin === "ttn"){
|
|
110
110
|
let appending = "push";
|
|
111
111
|
if(changeInfo?.changedState === "push"){
|
|
112
|
-
const downlinkTopic =
|
|
112
|
+
const downlinkTopic = this.downlinkConfighandler?.getDownlinkTopic(changeInfo,`/down/${appending}`);
|
|
113
113
|
await this.sendDownlink(downlinkTopic,state.val);
|
|
114
114
|
this.setStateAsync(id,state.val,true);
|
|
115
115
|
}
|
|
116
116
|
else if(changeInfo?.changedState === "replace"){
|
|
117
117
|
appending = "replace";
|
|
118
|
-
const downlinkTopic =
|
|
118
|
+
const downlinkTopic = this.downlinkConfighandler?.getDownlinkTopic(changeInfo,`/down/${appending}`);
|
|
119
119
|
await this.sendDownlink(downlinkTopic,state.val,changeInfo);
|
|
120
120
|
this.setStateAsync(id,state.val,true);
|
|
121
121
|
}
|
|
122
122
|
else{
|
|
123
|
-
const downlinkTopic =
|
|
123
|
+
const downlinkTopic = this.downlinkConfighandler?.getDownlinkTopic(changeInfo,`/down/${appending}`);
|
|
124
124
|
const downlinkConfig = this.downlinkConfighandler?.getDownlinkConfig(changeInfo);
|
|
125
125
|
if(downlinkConfig !== undefined){
|
|
126
|
-
const
|
|
126
|
+
const payloadInHex = this.downlinkConfighandler?.calculatePayloadInHex(downlinkConfig,state);
|
|
127
|
+
await this.writeNextSend(changeInfo?.obectStartDirectory,payloadInHex);
|
|
128
|
+
const downlink = this.downlinkConfighandler?.getDownlink(downlinkConfig,payloadInHex,changeInfo);
|
|
127
129
|
if(downlink !== undefined){
|
|
128
130
|
await this.sendDownlink(downlinkTopic,JSON.stringify(downlink),changeInfo);
|
|
129
131
|
}
|
|
@@ -133,15 +135,17 @@ class Lorawan extends utils.Adapter {
|
|
|
133
135
|
}
|
|
134
136
|
else if(this.config.origin === "chirpstack"){
|
|
135
137
|
if(changeInfo?.changedState === "push"){
|
|
136
|
-
const downlinkTopic =
|
|
138
|
+
const downlinkTopic = this.downlinkConfighandler?.getDownlinkTopic(changeInfo,`/down`);
|
|
137
139
|
await this.sendDownlink(downlinkTopic,state.val,changeInfo);
|
|
138
140
|
this.setStateAsync(id,state.val,true);
|
|
139
141
|
}
|
|
140
142
|
else{
|
|
141
|
-
const downlinkTopic =
|
|
142
|
-
const downlinkConfig =
|
|
143
|
+
const downlinkTopic = this.downlinkConfighandler?.getDownlinkTopic(changeInfo,`/down`);
|
|
144
|
+
const downlinkConfig = this.downlinkConfighandler?.getDownlinkConfig(changeInfo);
|
|
143
145
|
if(downlinkConfig !== undefined){
|
|
144
|
-
const
|
|
146
|
+
const payloadInHex = this.downlinkConfighandler?.calculatePayloadInHex(downlinkConfig,state);
|
|
147
|
+
await this.writeNextSend(changeInfo?.obectStartDirectory,payloadInHex);
|
|
148
|
+
const downlink = this.downlinkConfighandler?.getDownlink(downlinkConfig,payloadInHex,changeInfo);
|
|
145
149
|
if(downlink !== undefined){
|
|
146
150
|
await this.sendDownlink(downlinkTopic,JSON.stringify(downlink),changeInfo);
|
|
147
151
|
}
|
|
@@ -165,15 +169,25 @@ class Lorawan extends utils.Adapter {
|
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
171
|
|
|
172
|
+
async checkSendDOwnlinkWithUplink(id){
|
|
173
|
+
const changeInfo = await this.getChangeInfo(id);
|
|
174
|
+
this.log.warn(JSON.stringify(changeInfo));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async writeNextSend(startDirectory,payloadInHex){
|
|
178
|
+
const idFolder = `${startDirectory}.${this.messagehandler?.directoryhandler.directoryStructur.downlinkNextSend}`;
|
|
179
|
+
await this.setStateAsync(`${idFolder}.hex`,payloadInHex,true);
|
|
180
|
+
}
|
|
181
|
+
|
|
168
182
|
async sendDownlink(topic,message,changeInfo){
|
|
169
|
-
this.mqttClient?.publish(topic,message);
|
|
170
|
-
const
|
|
183
|
+
await this.mqttClient?.publish(topic,message);
|
|
184
|
+
const idFolderNextSend = `${changeInfo.obectStartDirectory}.${this.messagehandler?.directoryhandler.directoryStructur.downlinkNextSend}`;
|
|
171
185
|
const idFolderLastSend = `${changeInfo.obectStartDirectory}.${this.messagehandler?.directoryhandler.directoryStructur.downlinkLastSend}`;
|
|
172
|
-
const
|
|
186
|
+
const nextSend = await this.getStateAsync(`${idFolderNextSend}.hex`);
|
|
173
187
|
const lastSend = this.getHexpayloadFromDownlink(message);
|
|
174
188
|
await this.setStateAsync(`${idFolderLastSend}.hex`,lastSend,true);
|
|
175
|
-
if(
|
|
176
|
-
await this.setStateAsync(`${
|
|
189
|
+
if(nextSend && lastSend === nextSend?.val){
|
|
190
|
+
await this.setStateAsync(`${idFolderNextSend}.hex`,0,true);
|
|
177
191
|
}
|
|
178
192
|
}
|
|
179
193
|
|