diff --git a/src/globals.h b/src/globals.h index cd45c995..1111476f 100644 --- a/src/globals.h +++ b/src/globals.h @@ -8,7 +8,7 @@ #include // attn: increment version after modifications to configData_t truct! -#define PROGVERSION "1.4.2" // use max 10 chars here! +#define PROGVERSION "1.4.21" // use max 10 chars here! #define PROGNAME "PAXCNT" // std::set for unified array functions diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 2337ec1f..7b6b3a74 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -172,8 +172,13 @@ void onEvent(ev_t ev) { strcpy_P(buff, PSTR("JOINED")); sprintf(display_line6, " "); // clear previous lmic status - // set data rate adaptation + // set cyclic lmic link check to off because is not supported by ttn + // (but enabled by lmic after join) + LMIC_setLinkCheckMode(0); + + // set data rate adaptation according to saved setting LMIC_setAdrMode(cfg.adrmode); + // Set data rate and transmit power (note: txpower seems to be ignored by // the library) switch_lora(cfg.lorasf, cfg.txpower); diff --git a/src/senddata.cpp b/src/senddata.cpp index d4bced41..0536a172 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -1,26 +1,26 @@ // Basic Config #include "globals.h" + MessageBuffer_t SendBuffer; + // put data to send in RTos Queues used for transmit over channels Lora and SPI void SendData(uint8_t port) { - MessageBuffer_t MySendBuffer; - - MySendBuffer.MessageSize = payload.getSize(); - MySendBuffer.MessagePort = PAYLOAD_ENCODER <= 2 + SendBuffer.MessageSize = payload.getSize(); + SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2 ? port : (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT); - memcpy(MySendBuffer.Message, payload.getBuffer(), payload.getSize()); + memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize()); // enqueue message in LoRa send queue #ifdef HAS_LORA - if (xQueueSendToBack(LoraSendQueue, (void *)&MySendBuffer, (TickType_t)0)) + if (xQueueSendToBack(LoraSendQueue, (void *)&SendBuffer, (TickType_t)0)) ESP_LOGI(TAG, "%d bytes enqueued to send on LoRa", payload.getSize()); #endif // enqueue message in SPI send queue #ifdef HAS_SPI - if (xQueueSendToBack(SPISendQueue, (void *)&MySendBuffer, (TickType_t)0)) + if (xQueueSendToBack(SPISendQueue, (void *)&SendBuffer, (TickType_t)0)) ESP_LOGI(TAG, "%d bytes enqueued to send on SPI", payload.getSize()); #endif @@ -77,26 +77,24 @@ void IRAM_ATTR SendCycleIRQ() { // cyclic called function to eat data from RTos send queues and transmit it void processSendBuffer() { - MessageBuffer_t RcvBuf; - #ifdef HAS_LORA // Check if there is a pending TX/RX job running if ((LMIC.opmode & (OP_JOINING | OP_REJOIN | OP_TXDATA | OP_POLL)) != 0) { // LoRa Busy -> don't eat data from queue, since it cannot be sent } else { - if (xQueueReceive(LoraSendQueue, &(RcvBuf), (TickType_t)10)) { - // xMsg now holds the struct MessageBuffer from queue - LMIC_setTxData2(RcvBuf.MessagePort, RcvBuf.Message, RcvBuf.MessageSize, + if (xQueueReceive(LoraSendQueue, &(SendBuffer), (TickType_t)10)) { + // SendBuffer now holds the struct MessageBuffer with next payload from queue + LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message, SendBuffer.MessageSize, (cfg.countermode & 0x02)); - ESP_LOGI(TAG, "%d bytes sent to LORA", RcvBuf.MessageSize); + ESP_LOGI(TAG, "%d bytes sent to LORA", SendBuffer.MessageSize); sprintf(display_line7, "PACKET QUEUED"); } } #endif #ifdef HAS_SPI - if (xQueueReceive(SPISendQueue, &(RcvBuf), (TickType_t)10)) { - ESP_LOGI(TAG, "%d bytes sent to SPI", RcvBuf.MessageSize); + if (xQueueReceive(SPISendQueue, &(SendBuffer), (TickType_t)10)) { + ESP_LOGI(TAG, "%d bytes sent to SPI", SendBuffer.MessageSize); } #endif