Skip to content

Commit 1c01e2b

Browse files
- Processing of LoRaWAN configuration parameters revised
- Time synchronization via LoRaWAN revised - The LoRaWAN interface can now also be configured via the web interface
1 parent 0db11a0 commit 1c01e2b

File tree

5 files changed

+589
-61
lines changed

5 files changed

+589
-61
lines changed

code/components/jomjol_flowcontroll/ClassFlowLoRaWAN.cpp

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -215,48 +215,88 @@ bool ClassFlowLoRaWAN::ReadParameter(FILE* pfile, string& aktparamgraph)
215215
// OTAA parameters
216216
if ((toUpper(_param) == "JOINEUI") && (splitted.size() > 1))
217217
{
218-
this->joinEUI = std::strtoull(splitted[1].c_str(),NULL,16);
218+
if (splitted[1] != "undefined") {
219+
this->joinEUI = std::strtoull(splitted[1].c_str(),NULL,16);
220+
} else {
221+
this->joinEUI = NULL;
222+
}
219223
}
220224
if ((toUpper(_param) == "DEVEUI") && (splitted.size() > 1))
221225
{
222-
this->devEUI = std::strtoull(splitted[1].c_str(),NULL,16);
226+
if (splitted[1] != "undefined") {
227+
this->devEUI = std::strtoull(splitted[1].c_str(),NULL,16);
228+
} else {
229+
this->devEUI = NULL;
230+
}
223231
}
224232
if ((toUpper(_param) == "NWKKEY") && (splitted.size() > 1))
225-
{
226-
std::vector<uint8_t> nwkKeyVector = hexStringToByteArray(splitted[1]);
227-
this->nwkKey = new uint8_t[16];
228-
copy(nwkKeyVector.begin(), nwkKeyVector.end(), this->nwkKey);
233+
{
234+
if (splitted[1] != "undefined") {
235+
this->nwkKey = new uint8_t[16];
236+
std::vector<uint8_t> nwkKeyVector = hexStringToByteArray(splitted[1]);
237+
copy(nwkKeyVector.begin(), nwkKeyVector.end(), this->nwkKey);
238+
} else {
239+
this->nwkKey = NULL;
240+
}
229241
}
230242
if ((toUpper(_param) == "APPKEY") && (splitted.size() > 1))
231-
{
232-
std::vector<uint8_t> appKeyVector = hexStringToByteArray(splitted[1]);
233-
this->appKey = new uint8_t[16];
234-
copy(appKeyVector.begin(), appKeyVector.end(), this->appKey);
243+
{
244+
if (splitted[1] != "undefined") {
245+
this->appKey = new uint8_t[16];
246+
std::vector<uint8_t> appKeyVector = hexStringToByteArray(splitted[1]);
247+
copy(appKeyVector.begin(), appKeyVector.end(), this->appKey);
248+
} else {
249+
this->appKey = NULL;
250+
}
235251
}
236252
// ABP parameters
237253
if ((toUpper(_param) == "DEVADDR") && (splitted.size() > 1))
238254
{
239-
this->devAddr = std::strtoull(splitted[1].c_str(),NULL,16);
255+
if (splitted[1] != "undefined") {
256+
this->devAddr = std::strtoull(splitted[1].c_str(),NULL,16);
257+
} else {
258+
this->devAddr = NULL;
259+
}
240260
}
241261
if ((toUpper(_param) == "FNWKSINTKEY") && (splitted.size() > 1))
242262
{
243-
std::vector<uint8_t> fNwkSIntKeyVector = hexStringToByteArray(splitted[1]);
244-
copy(fNwkSIntKeyVector.begin(), fNwkSIntKeyVector.end(), this->fNwkSIntKey);
263+
if (splitted[1] != "undefined") {
264+
this->fNwkSIntKey = new uint8_t[16];
265+
std::vector<uint8_t> fNwkSIntKeyVector = hexStringToByteArray(splitted[1]);
266+
copy(fNwkSIntKeyVector.begin(), fNwkSIntKeyVector.end(), this->fNwkSIntKey);
267+
} else {
268+
this->fNwkSIntKey = NULL;
269+
}
245270
}
246271
if ((toUpper(_param) == "SNWKSINTKEY") && (splitted.size() > 1))
247-
{
248-
std::vector<uint8_t> sNwkSIntKeyVector = hexStringToByteArray(splitted[1]);
249-
copy(sNwkSIntKeyVector.begin(), sNwkSIntKeyVector.end(), this->sNwkSIntKey);
272+
{
273+
if (splitted[1] != "undefined") {
274+
this->sNwkSIntKey = new uint8_t[16];
275+
std::vector<uint8_t> sNwkSIntKeyVector = hexStringToByteArray(splitted[1]);
276+
copy(sNwkSIntKeyVector.begin(), sNwkSIntKeyVector.end(), this->sNwkSIntKey);
277+
} else {
278+
this->sNwkSIntKey = NULL;
279+
}
250280
}
251281
if ((toUpper(_param) == "NWKSENCKEY") && (splitted.size() > 1))
252-
{
253-
std::vector<uint8_t> nwkSEncKeyVector = hexStringToByteArray(splitted[1]);
254-
copy(nwkSEncKeyVector.begin(), nwkSEncKeyVector.end(), this->nwkSEncKey);
282+
{
283+
if (splitted[1] != "undefined") {
284+
this->nwkSEncKey = new uint8_t[16];
285+
std::vector<uint8_t> nwkSEncKeyVector = hexStringToByteArray(splitted[1]);
286+
copy(nwkSEncKeyVector.begin(), nwkSEncKeyVector.end(), this->nwkSEncKey);
287+
} else {
288+
this->nwkSEncKey = NULL;
289+
}
255290
}
256291
if ((toUpper(_param) == "APPSKEY") && (splitted.size() > 1))
257-
{
258-
std::vector<uint8_t> appSKeyVector = hexStringToByteArray(splitted[1]);
259-
copy(appSKeyVector.begin(), appSKeyVector.end(), this->appSKey);
292+
{
293+
if (splitted[1] != "undefined") {
294+
this->appSKey = new uint8_t[16];
295+
std::vector<uint8_t> appSKeyVector = hexStringToByteArray(splitted[1]);
296+
copy(appSKeyVector.begin(), appSKeyVector.end(), this->appSKey);
297+
} else {
298+
this->appSKey = NULL;
299+
}
260300
}
261301
}
262302

code/components/jomjol_lorawan/interface_lorawan.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,25 @@ void task_lorawan_communication(void *pvParameter) {
172172
// Check if a downlink was received
173173
// (state 0 = no downlink, state 1/2 = downlink in window Rx1/Rx2)
174174
if(state > 0) {
175-
if (downlinkSize > 0){
176-
uint32_t networkTime = 0;
177-
uint8_t fracSecond = 0;
178-
if(node->getMacDeviceTimeAns(&networkTime, &fracSecond, true) == RADIOLIB_ERR_NONE) {
179-
ESP_LOGE(LORAWAN_LOG_TAG, "DeviceTime Unix:\t%lu", networkTime);
180-
ESP_LOGE(LORAWAN_LOG_TAG, "DeviceTime second:\t1/%u", fracSecond);
181-
struct timeval now;
182-
now.tv_sec = networkTime;
183-
now.tv_usec = static_cast<long>(fracSecond / 256 * 1000000);
184-
settimeofday(&now, NULL);
185-
}
175+
uint32_t networkTime = 0;
176+
uint8_t fracSecond = 0;
177+
if(node->getMacDeviceTimeAns(&networkTime, &fracSecond, true) == RADIOLIB_ERR_NONE) {
178+
ESP_LOGE(LORAWAN_LOG_TAG, "DeviceTime Unix:\t%lu", networkTime);
179+
ESP_LOGE(LORAWAN_LOG_TAG, "DeviceTime second:\t1/%u", fracSecond);
180+
struct timeval now;
181+
now.tv_sec = networkTime;
182+
now.tv_usec = static_cast<long>(fracSecond / 256 * 1000000);
183+
settimeofday(&now, NULL);
184+
}
185+
186+
uint8_t margin = 0;
187+
uint8_t gwCnt = 0;
188+
if(node->getMacLinkCheckAns(&margin, &gwCnt) == RADIOLIB_ERR_NONE) {
189+
ESP_LOGE(LORAWAN_LOG_TAG, "LinkCheck margin:\t%u",margin);
190+
ESP_LOGE(LORAWAN_LOG_TAG, "LinkCheck count:\t%u", gwCnt);
191+
}
186192

193+
if (downlinkSize > 0){
187194
//check if it is a wifi toggle command
188195
if (downlinkDetails.fPort == 1 ) {
189196
if (downlinkPayload[0] == 1){
@@ -237,13 +244,6 @@ void task_lorawan_communication(void *pvParameter) {
237244
ESP_LOGE(LORAWAN_LOG_TAG, "Port:\t\t%u",downlinkDetails.fPort);
238245
ESP_LOGE(LORAWAN_LOG_TAG, "Time-on-air:\t\t%lu ms",node->getLastToA());
239246
ESP_LOGE(LORAWAN_LOG_TAG, "Rx window:\t\t%u",state);
240-
241-
uint8_t margin = 0;
242-
uint8_t gwCnt = 0;
243-
if(node->getMacLinkCheckAns(&margin, &gwCnt) == RADIOLIB_ERR_NONE) {
244-
ESP_LOGE(LORAWAN_LOG_TAG, "LinkCheck margin:\t%u",margin);
245-
ESP_LOGE(LORAWAN_LOG_TAG, "LinkCheck count:\t%u", gwCnt);
246-
}
247247
} else {
248248
ESP_LOGE(LORAWAN_LOG_TAG, "No downlink received");
249249
}
@@ -422,7 +422,6 @@ int16_t LoRaWAN_Init(LoRaWANBand_t _region, uint8_t _subBand, float _roundInterv
422422
LoRaWANNode node(&radio, &US915, 2);
423423
*/
424424
node = new LoRaWANNode(&radio, &region, subBand);
425-
426425

427426
int16_t state = 0; // return value for calls to RadioLib
428427

sd-card/config/config.ini

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,30 @@ HomeassistantDiscovery = false
112112
;ApiKey = undefined
113113
;UploadImg = 0
114114

115-
[LoRaWAN]
115+
;[LoRaWAN]
116116
Region = EU868
117-
SubBand = 0
117+
;SubBand = 0
118118
UplinkInterval = 60
119-
InitialDatarate = 255
119+
;InitialDatarate = 255
120120
ADRActive = true
121121
CSMAActive = true
122-
CSMAMaxChanges = 4
123-
CSMABackoffMax = 0
124-
CSMADifsSlots = 2
122+
;CSMAMaxChanges = 4
123+
;CSMABackoffMax = 0
124+
;CSMADifsSlots = 2
125125
DutyCycleLimitsActive = true
126-
DutyCycleMsPerHour = 0
126+
;DutyCycleMsPerHour = 0
127127
DwellTimeLimitsActive = true
128-
DwellTimeMsPerUplink = 0
128+
;DwellTimeMsPerUplink = 0
129129
DeviceActivationMethod = OTAA
130-
;OTAA parameters
131-
JoinEUI = 0000000000000000
132-
DevEUI = 0000000000000000
133-
NwkKey = 00000000000000000000000000000000
134-
AppKey = 00000000000000000000000000000000
135-
;ABP parameters
136-
;DevAddr = 00000000
137-
;FNwkSIntKey = 00000000000000000000000000000000
138-
;SNwkSIntKey = 00000000000000000000000000000000
139-
;NwkSEncKey = 00000000000000000000000000000000
140-
;AppSKey = 00000000000000000000000000000000
130+
JoinEUI = undefined
131+
DevEUI = undefined
132+
;NwkKey = undefined
133+
AppKey = undefined
134+
DevAddr = undefined
135+
;FNwkSIntKey = undefined
136+
;SNwkSIntKey = undefined
137+
NwkSEncKey = undefined
138+
AppSKey = undefined
141139

142140
;[GPIO]
143141
;MainTopicMQTT = wasserzaehler/GPIO

0 commit comments

Comments
 (0)