I've tried a simple example with APB and sending one Packet. But I never receive a EV_TXCOMPLETE Event. I checked If I get a IRQ on DIO0 from the Modem and this is working. But somehow the Library never triggers the EV_TXCOMPLETE Event. Is this a known problem in this Library port?
Tested on a TTGO LORA32.
My example:
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#include <lmic.h>
static const u1_t NWKSKEY[16] = { };
static const u1_t APPSKEY[16] = { };
static const u4_t DEVADDR = ;
void os_getArtEui (u1_t* buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }
static uint8_t mydata[] = "1234";
static osjob_t sendjob;
const unsigned TX_INTERVAL = 1;
// Pin mapping
const lmic_pinmap lmic_pins = {
.nss = 18,
.rst = 14,
.dio = { 26, 34, 35 },
.spi = { /* MISO = */ 19, /* MOSI = */ 27, /* SCK = */ 5 },
.rxtx = LMIC_UNUSED_PIN,
};
void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
printf(("OP_TXRXPEND, not sending \n"));
} else {
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
printf(("Packet queued \n"));
}
// Next TX is scheduled after TX_COMPLETE event.
}
void onEvent (ev_t ev) {
printf(os_getTime());
printf(": ");
switch(ev) {
case EV_SCAN_TIMEOUT:
printf(("EV_SCAN_TIMEOUT"));
break;
case EV_BEACON_FOUND:
printf(("EV_BEACON_FOUND"));
break;
case EV_BEACON_MISSED:
printf(("EV_BEACON_MISSED"));
break;
case EV_BEACON_TRACKED:
printf(("EV_BEACON_TRACKED"));
break;
case EV_JOINING:
printf(("EV_JOINING"));
break;
case EV_JOINED:
printf(("EV_JOINED"));
break;
case EV_RFU1:
printf(("EV_RFU1"));
break;
case EV_JOIN_FAILED:
printf(("EV_JOIN_FAILED"));
break;
case EV_REJOIN_FAILED:
printf(("EV_REJOIN_FAILED"));
break;
case EV_TXCOMPLETE:
printf(("EV_TXCOMPLETE (includes waiting for RX windows)"));
if (LMIC.txrxFlags & TXRX_ACK)
printf(("Received ack"));
if (LMIC.dataLen) {
printf(("Received "));
printf(LMIC.dataLen);
printf((" bytes of payload"));
}
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
break;
case EV_LOST_TSYNC:
printf(("EV_LOST_TSYNC"));
break;
case EV_RESET:
printf(("EV_RESET"));
break;
case EV_RXCOMPLETE:
// data received in ping slot
printf(("EV_RXCOMPLETE"));
break;
case EV_LINK_DEAD:
printf(("EV_LINK_DEAD"));
break;
case EV_LINK_ALIVE:
printf(("EV_LINK_ALIVE"));
break;
default:
printf(("Unknown event"));
break;
}
}
void app_main(void)
{
os_init();
LMIC_reset();
LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
LMIC_setupChannel(0, 868100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(1, 868300000, DR_RANGE_MAP(DR_SF12, DR_SF7B), BAND_CENTI); // g-band
LMIC_setupChannel(2, 868500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(3, 867100000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(4, 867300000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(5, 867500000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(6, 867700000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(7, 867900000, DR_RANGE_MAP(DR_SF12, DR_SF7), BAND_CENTI); // g-band
LMIC_setupChannel(8, 868800000, DR_RANGE_MAP(DR_FSK, DR_FSK), BAND_MILLI); // g2-band
// Disable link check validation
LMIC_setLinkCheckMode(0);
// TTN uses SF9 for its RX2 window.
LMIC.dn2Dr = DR_SF9;
// Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
LMIC_setDrTxpow(DR_SF7,14);
// Start job
do_send(&sendjob);
while(1) {
os_runloop_once();
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
Console output (Sending IRQ for DIO 0 is from my debug Code to check if the IRQ is received):
I (327) lmic: Starting IO initialization
I (337) gpio: GPIO[14]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (337) gpio: GPIO[18]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (347) gpio: GPIO[26]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (357) gpio: GPIO[34]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (367) gpio: GPIO[35]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (377) lmic: Finished IO initialization
I (387) lmic: Starting SPI initialization
I (387) lmic: Finished SPI initialization
I (397) lmic: Starting initialisation of timer
I (397) lmic: Finished initalisation of timer
I (407) gpio: GPIO[14]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (407) lmic: Wait until
I (417) lmic: Done waiting until
I (417) gpio: GPIO[14]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (427) lmic: Wait until
I (517) lmic: Done waiting until
Packet queued
Sending IRQ for DIO 0
I (1787) lmic: Wait until
I (1787) lmic: Done waiting until
I've tried a simple example with APB and sending one Packet. But I never receive a EV_TXCOMPLETE Event. I checked If I get a IRQ on DIO0 from the Modem and this is working. But somehow the Library never triggers the EV_TXCOMPLETE Event. Is this a known problem in this Library port?
Tested on a TTGO LORA32.
My example:
Console output (
Sending IRQ for DIO 0
is from my debug Code to check if the IRQ is received):