commit
08857b0ed2
@ -34,7 +34,7 @@ void os_getArtEui(u1_t *buf);
|
|||||||
void os_getDevEui(u1_t *buf);
|
void os_getDevEui(u1_t *buf);
|
||||||
void showLoraKeys(void);
|
void showLoraKeys(void);
|
||||||
void switch_lora(uint8_t sf, uint8_t tx);
|
void switch_lora(uint8_t sf, uint8_t tx);
|
||||||
void lora_send(osjob_t *job);
|
void lora_send(void *pvParameters);
|
||||||
void lora_enqueuedata(MessageBuffer_t *message);
|
void lora_enqueuedata(MessageBuffer_t *message);
|
||||||
void lora_queuereset(void);
|
void lora_queuereset(void);
|
||||||
#if (TIME_SYNC_LORAWAN)
|
#if (TIME_SYNC_LORAWAN)
|
||||||
|
@ -18,9 +18,8 @@ static const char TAG[] = "lora";
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
osjob_t sendjob;
|
|
||||||
QueueHandle_t LoraSendQueue;
|
QueueHandle_t LoraSendQueue;
|
||||||
TaskHandle_t lmicTask = NULL;
|
TaskHandle_t lmicTask = NULL, lorasendTask = NULL;
|
||||||
|
|
||||||
class MyHalConfig_t : public Arduino_LMIC::HalConfiguration_t {
|
class MyHalConfig_t : public Arduino_LMIC::HalConfiguration_t {
|
||||||
|
|
||||||
@ -218,8 +217,6 @@ void onEvent(ev_t ev) {
|
|||||||
// Set data rate and transmit power (note: txpower seems to be ignored by
|
// Set data rate and transmit power (note: txpower seems to be ignored by
|
||||||
// the library)
|
// the library)
|
||||||
switch_lora(cfg.lorasf, cfg.txpower);
|
switch_lora(cfg.lorasf, cfg.txpower);
|
||||||
// kickoff first send job
|
|
||||||
os_setCallback(&sendjob, lora_send);
|
|
||||||
// show effective LoRa parameters after join
|
// show effective LoRa parameters after join
|
||||||
ESP_LOGI(TAG, "DEVaddr=%08X", LMIC.devaddr);
|
ESP_LOGI(TAG, "DEVaddr=%08X", LMIC.devaddr);
|
||||||
break;
|
break;
|
||||||
@ -248,11 +245,6 @@ void onEvent(ev_t ev) {
|
|||||||
: PSTR("TX COMPLETE"));
|
: PSTR("TX COMPLETE"));
|
||||||
sprintf(display_line6, " "); // clear previous lmic status
|
sprintf(display_line6, " "); // clear previous lmic status
|
||||||
|
|
||||||
// schedule next transmission with some random delay to prevent systematic
|
|
||||||
// collisions
|
|
||||||
os_setTimedCallback(&sendjob, os_getTime() + ms2osticks(random(500)),
|
|
||||||
lora_send);
|
|
||||||
|
|
||||||
if (LMIC.dataLen) { // did we receive payload data -> display info
|
if (LMIC.dataLen) { // did we receive payload data -> display info
|
||||||
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d",
|
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d",
|
||||||
LMIC.dataLen, LMIC.rssi, LMIC.snr / 4);
|
LMIC.dataLen, LMIC.rssi, LMIC.snr / 4);
|
||||||
@ -313,13 +305,7 @@ void onEvent(ev_t ev) {
|
|||||||
|
|
||||||
case EV_TXSTART:
|
case EV_TXSTART:
|
||||||
if (!(LMIC.opmode & OP_JOINING)) {
|
if (!(LMIC.opmode & OP_JOINING)) {
|
||||||
#if (TIME_SYNC_LORASERVER)
|
strcpy_P(buff, PSTR("TX START"));
|
||||||
// if last packet sent was a timesync request, store TX time
|
|
||||||
if (LMIC.pendTxPort == TIMEPORT)
|
|
||||||
strcpy_P(buff, PSTR("TX TIMESYNC"));
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
strcpy_P(buff, PSTR("TX START"));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -394,23 +380,26 @@ void switch_lora(uint8_t sf, uint8_t tx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lora_send(osjob_t *job) {
|
// LMIC send task
|
||||||
|
void lora_send(void *pvParameters) {
|
||||||
|
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
||||||
|
|
||||||
MessageBuffer_t SendBuffer;
|
MessageBuffer_t SendBuffer;
|
||||||
|
|
||||||
// Check if there is not a current TX/RX job running
|
while (1) {
|
||||||
if (LMIC.opmode & OP_TXRXPEND) {
|
// fetch next or wait for payload to send from queue
|
||||||
ESP_LOGE(TAG, "LMIC busy, data not sent and lost");
|
if (xQueueReceive(LoraSendQueue, &SendBuffer, portMAX_DELAY) == pdTRUE) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetch next payload to send from queue or wait until new payload shows up in
|
if (LMIC.opmode & OP_TXRXPEND) // LMIC is busy, we can't send...
|
||||||
// queue
|
lora_enqueuedata(&SendBuffer); // ...so we re-enqueue the message
|
||||||
if (xQueueReceive(LoraSendQueue, &SendBuffer, portMAX_DELAY) == pdTRUE) {
|
else if (LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
|
||||||
if (LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
|
SendBuffer.MessageSize,
|
||||||
SendBuffer.MessageSize, (cfg.countermode & 0x02)) == 0)
|
(cfg.countermode & 0x02)) == 0)
|
||||||
ESP_LOGI(TAG, "%d byte(s) delivered to LMIC", SendBuffer.MessageSize);
|
ESP_LOGI(TAG, "%d byte(s) delivered to LMIC", SendBuffer.MessageSize);
|
||||||
else
|
else // LMIC stack denied tx ...
|
||||||
lora_enqueuedata(&SendBuffer); // re-enqueue unsent message
|
lora_enqueuedata(&SendBuffer); // ...so we re-enqueue the message
|
||||||
|
}
|
||||||
|
delay(2); // yield to CPU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +413,7 @@ esp_err_t lora_stack_init() {
|
|||||||
ESP_LOGI(TAG, "LORA send queue created, size %d Bytes",
|
ESP_LOGI(TAG, "LORA send queue created, size %d Bytes",
|
||||||
SEND_QUEUE_SIZE * sizeof(MessageBuffer_t));
|
SEND_QUEUE_SIZE * sizeof(MessageBuffer_t));
|
||||||
|
|
||||||
// starting lorawan stack
|
// start lorawan stack
|
||||||
ESP_LOGI(TAG, "Starting LMIC...");
|
ESP_LOGI(TAG, "Starting LMIC...");
|
||||||
xTaskCreatePinnedToCore(lmictask, // task function
|
xTaskCreatePinnedToCore(lmictask, // task function
|
||||||
"lmictask", // name of task
|
"lmictask", // name of task
|
||||||
@ -434,11 +423,20 @@ esp_err_t lora_stack_init() {
|
|||||||
&lmicTask, // task handle
|
&lmicTask, // task handle
|
||||||
1); // CPU core
|
1); // CPU core
|
||||||
|
|
||||||
|
// start lmic send task
|
||||||
|
xTaskCreatePinnedToCore(lora_send, // task function
|
||||||
|
"lorasendtask", // name of task
|
||||||
|
2048, // stack size of task
|
||||||
|
(void *)1, // parameter of the task
|
||||||
|
1, // priority of the task
|
||||||
|
&lorasendTask, // task handle
|
||||||
|
1); // CPU core
|
||||||
|
|
||||||
if (!LMIC_startJoining()) { // start joining
|
if (!LMIC_startJoining()) { // start joining
|
||||||
ESP_LOGI(TAG, "Already joined");
|
ESP_LOGI(TAG, "Already joined");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ESP_OK; // continue main program
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lora_enqueuedata(MessageBuffer_t *message) {
|
void lora_enqueuedata(MessageBuffer_t *message) {
|
||||||
|
@ -36,6 +36,7 @@ timesync_req 1 3 processes realtime time sync requests
|
|||||||
lmictask 1 2 MCCI LMiC LORAWAN stack
|
lmictask 1 2 MCCI LMiC LORAWAN stack
|
||||||
irqhandler 1 1 display, timesync, gps, etc. triggered by timers
|
irqhandler 1 1 display, timesync, gps, etc. triggered by timers
|
||||||
gpsloop 1 1 reads data from GPS via serial or i2c
|
gpsloop 1 1 reads data from GPS via serial or i2c
|
||||||
|
lorasendtask 1 1 feed data from lora sendqueue to lmcic
|
||||||
IDLE 1 0 ESP32 arduino scheduler -> runs wifi channel rotator
|
IDLE 1 0 ESP32 arduino scheduler -> runs wifi channel rotator
|
||||||
|
|
||||||
Low priority numbers denote low priority tasks.
|
Low priority numbers denote low priority tasks.
|
||||||
|
Loading…
Reference in New Issue
Block a user