diff --git a/README.md b/README.md index 8ca9325..525020d 100644 --- a/README.md +++ b/README.md @@ -938,51 +938,62 @@ LMIC library: MCCI Activation: OTAA Interval: 60 seconds -000000087349: doWork job started -000000090391: Input data collected - COUNTER value: 1 -000000091107: Packet queued -000000092608: Event: EV_JOINING -000000478864: Event: EV_TXSTART -000000801406: Event: EV_JOINED +000000087328: Event: EV_JOINING + +000000088779: doWork job started +000000115173: Event: EV_TXSTART +000000437671: Event: EV_JOINED Network Id: 19 - Device Address: 260BB630 - Application Session Key: D0-24-1D-E6-CE-7B-8B-24-4B-B3-92-D9-83-59-B8-F8 - Network Session Key: 9F-39-29-CE-14-FE-C1-53-63-32-4A-3E-D7-8B-5C-5B -000000803598: Event: EV_TXSTART -000001184741: Event: EV_TXCOMPLETE + Device Address: 260B9BA3 + Application Session Key: BD-40-9E-1F-9C-36-BC-1C-0F-ED-A9-4C-90-27-84-8A + Network Session Key: 80-FC-6E-99-9C-67-63-3F-4D-61-70-E1-2C-1D-D6-8E + +000003838779: doWork job started +000003841831: Input data collected + COUNTER value: 1 +000003842567: Packet queued +000003844154: Event: EV_TXSTART +000004225330: Event: EV_TXCOMPLETE Up: 1, Down: 0 -000003837350: doWork job started -000003840391: Input data collected +000007588779: doWork job started +000007591830: Input data collected COUNTER value: 2 -000003841129: Packet queued -000003842736: Event: EV_TXSTART -000004223911: Event: EV_TXCOMPLETE +000007592585: Packet queued +000007594181: Event: EV_TXSTART +000007975350: Event: EV_TXCOMPLETE Up: 2, Down: 0 -000007587350: doWork job started -000007590391: Input data collected +000011338779: doWork job started +000011341830: Input data collected COUNTER value: 3 -000007591099: Packet queued -000007592698: Event: EV_TXSTART -000007912325: Event: EV_TXCOMPLETE - Up: 3, Down: 2 +000011342539: Packet queued +000011344159: Event: EV_TXSTART +000011725339: Event: EV_TXCOMPLETE + Up: 3, Down: 0 + +000015088780: doWork job started +000015091771: Input data collected + COUNTER value: 4 +000015092467: Packet queued +000015094084: Event: EV_TXSTART +000015413725: Event: EV_TXCOMPLETE + Up: 4, Down: 2 Downlink received - RSSI: -79 dBm, SNR: 6.2 dB + RSSI: -68 dBm, SNR: 7.2 dB Port: 100 Length: 1 Data: C0 Reset cmd received -000007916349: Counter reset +000015417949: Counter reset -000011337351: doWork job started -000011340391: Input data collected +000018838781: doWork job started +000018841831: Input data collected COUNTER value: 1 -000011341136: Packet queued -000011342754: Event: EV_TXSTART -000011723944: Event: EV_TXCOMPLETE - Up: 4, Down: 2 +000018842563: Packet queued +000018844177: Event: EV_TXSTART +000019225356: Event: EV_TXCOMPLETE + Up: 5, Down: 2 ``` ### 8.2 Display diff --git a/src/LMIC-node.cpp b/src/LMIC-node.cpp index 2b179a2..381d1e2 100644 --- a/src/LMIC-node.cpp +++ b/src/LMIC-node.cpp @@ -376,6 +376,10 @@ void printHeader(void) serial.print(F("Interval: ")); serial.print(doWorkIntervalSeconds); serial.println(F(" seconds")); + if (activationMode == ActivationMode::OTAA) + { + serial.println(); + } #endif } @@ -486,7 +490,7 @@ void initLmic(bit_t adrEnabled = 1, // 1 is on, 0 is off. LMIC_setAdrMode(adrEnabled); - if (activationType == ActivationType::OTAA) + if (activationMode == ActivationMode::OTAA) { #if defined(CFG_us915) || defined(CFG_au915) // NA-US and AU channels 0-71 are configured automatically @@ -706,60 +710,63 @@ void processWork(ostime_t doWorkJobTimeStamp) // Uses globals: payloadBuffer and LMIC data structure. // This is where the main work is performed like - // reading sensor, GPS data and schedule - // uplink messages is anything needs to be transmitted. + // reading sensor and GPS data and schedule uplink + // messages if anything needs to be transmitted. - // Gather data. - // For simplicity LMIC-node uses a counter to simulate a sensor. - // The counter is increased automatically by getCounterValue() - // and can be reset with a 'reset counter' command downlink message. - - // Collect input data - uint16_t counterValue = getCounterValue(); - ostime_t timestamp = os_getTime(); - - #ifdef USE_DISPLAY - // Interval and Counter values are combined on a single row. - // This allows to keep the 3rd row empty which makes the - // information better readable on the small display. - display.clearLine(INTERVAL_ROW); - display.setCursor(COL_0, INTERVAL_ROW); - display.print("I:"); - display.print(doWorkIntervalSeconds); - display.print("s"); - display.print(" Ctr:"); - display.print(counterValue); - #endif - #ifdef USE_SERIAL - printEvent(timestamp, "Input data collected", PrintTarget::Serial); - printSpaces(serial, MESSAGE_INDENT); - serial.print(F("COUNTER value: ")); - serial.println(counterValue); - #endif - - // For simplicity LMIC-node will try to send an uplink - // message every time processWork() is executed. - - // Schedule uplink message if possible - if (LMIC.opmode & OP_TXRXPEND) + // Skip processWork if using OTAA and still joining. + if (LMIC.devaddr != 0) { - // TxRx is currently pending, do not send. - #ifdef USE_SERIAL - printEvent(timestamp, "Uplink not scheduled because TxRx pending", PrintTarget::Serial); - #endif + // Collect input data. + // For simplicity LMIC-node uses a counter to simulate a sensor. + // The counter is increased automatically by getCounterValue() + // and can be reset with a 'reset counter' command downlink message. + + uint16_t counterValue = getCounterValue(); + ostime_t timestamp = os_getTime(); + #ifdef USE_DISPLAY - printEvent(timestamp, "UL not scheduled", PrintTarget::Display); + // Interval and Counter values are combined on a single row. + // This allows to keep the 3rd row empty which makes the + // information better readable on the small display. + display.clearLine(INTERVAL_ROW); + display.setCursor(COL_0, INTERVAL_ROW); + display.print("I:"); + display.print(doWorkIntervalSeconds); + display.print("s"); + display.print(" Ctr:"); + display.print(counterValue); #endif - } - else - { - // Prepare uplink payload. - uint8_t fPort = 10; - payloadBuffer[0] = counterValue >> 8; - payloadBuffer[1] = counterValue & 0xFF; - uint8_t payloadLength = 2; + #ifdef USE_SERIAL + printEvent(timestamp, "Input data collected", PrintTarget::Serial); + printSpaces(serial, MESSAGE_INDENT); + serial.print(F("COUNTER value: ")); + serial.println(counterValue); + #endif - scheduleUplink(fPort, payloadBuffer, payloadLength); + // For simplicity LMIC-node will try to send an uplink + // message every time processWork() is executed. + + // Schedule uplink message if possible + if (LMIC.opmode & OP_TXRXPEND) + { + // TxRx is currently pending, do not send. + #ifdef USE_SERIAL + printEvent(timestamp, "Uplink not scheduled because TxRx pending", PrintTarget::Serial); + #endif + #ifdef USE_DISPLAY + printEvent(timestamp, "UL not scheduled", PrintTarget::Display); + #endif + } + else + { + // Prepare uplink payload. + uint8_t fPort = 10; + payloadBuffer[0] = counterValue >> 8; + payloadBuffer[1] = counterValue & 0xFF; + uint8_t payloadLength = 2; + + scheduleUplink(fPort, payloadBuffer, payloadLength); + } } } @@ -839,6 +846,11 @@ void setup() // █ █ ▀▀█ █▀▀ █▀▄ █ █ █ █ █ █▀▀ █▀▀ █ █ █ █ // ▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀ ▀▀▀ ▀▀ ▀▀▀ ▀▀▀ ▀ ▀ ▀▀ + if (activationMode == ActivationMode::OTAA) + { + LMIC_startJoining(); + } + // Schedule initial doWork job for immediate execution. os_setCallback(&doWorkJob, doWorkCallback); } diff --git a/src/LMIC-node.h b/src/LMIC-node.h index a6eeeac..d77abcf 100644 --- a/src/LMIC-node.h +++ b/src/LMIC-node.h @@ -67,11 +67,11 @@ void displayTxSymbol(bool visible); #define OTAA_ACTIVATION #endif -enum class ActivationType {OTAA, ABP}; +enum class ActivationMode {OTAA, ABP}; #ifdef OTAA_ACTIVATION - const ActivationType activationType = ActivationType::OTAA; + const ActivationMode activationMode = ActivationMode::OTAA; #else - const ActivationType activationType = ActivationType::ABP; + const ActivationMode activationMode = ActivationMode::ABP; #endif