From 59ce7ee44d116bc1ab88785faf525aab963cbf94 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Tue, 2 Jun 2020 21:21:05 +0200 Subject: [PATCH] 20200602 --- mini-beieli-node.ino | 51 +++++++++++++++++++++++++++----------------- mini_beieli_node.h | 2 +- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/mini-beieli-node.ino b/mini-beieli-node.ino index fc63a91..81aaade 100644 --- a/mini-beieli-node.ino +++ b/mini-beieli-node.ino @@ -704,6 +704,14 @@ void StartNewIteration() { gCatena.SafePrintf("looks like we timed out waiting for sending to finish...\n", wait_time); } LMIC_clrTxData(); + // we sleep 10 seconds... + start_time = millis(); + while (send_in_progress && ((millis() - start_time) < 10000)) + { + gCatena.poll(); + yield(); + } + send_in_progress = false; } wait_time = (uint32_t)((millis() - start_time) / 1000); @@ -765,13 +773,15 @@ void StartNewIteration() { } else { - if (config_data.debug_level > 0) { - gCatena.SafePrintf("light sleep; os_setTimedCallback for startNewIterationCb in %d...seconds\n", sleep_time_sec); + if (! stop_iterations) { + if (config_data.debug_level > 0) { + gCatena.SafePrintf("light sleep; os_setTimedCallback for startNewIterationCb in %d...seconds\n", sleep_time_sec); + } + os_setTimedCallback( + &iterationJob, + os_getTime() + sec2osticks(sleep_time_sec), + startNewIterationCb); } - os_setTimedCallback( - &iterationJob, - os_getTime() + sec2osticks(sleep_time_sec), - startNewIterationCb); } } @@ -803,15 +813,27 @@ void startSendingUplink(bool firstTime) if (config_data.debug_level > 0) { gCatena.SafePrintf("SendBuffer firstTime\n"); } - gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort); - package_counter++; + if (gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort)) { + package_counter++; + if (config_data.debug_level > 0) { + gCatena.SafePrintf("LMIC.opmode just after SendBuffer (successful): %#x\n", LMIC.opmode); + } else { + gCatena.SafePrintf("LMIC.opmode just before SendBuffer (failed): %#x\n", LMIC.opmode); + } + } } else { if (config_data.debug_level > 0) { gCatena.SafePrintf("LMIC.opmode just before SendBuffer: %#x\n", LMIC.opmode); gCatena.SafePrintf("SendBuffer not firstTime\n"); } - gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort); - package_counter++; + if (gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort)) { + package_counter++; + if (config_data.debug_level > 0) { + gCatena.SafePrintf("LMIC.opmode just after SendBuffer (successful): %#x\n", LMIC.opmode); + } else { + gCatena.SafePrintf("LMIC.opmode just before SendBuffer (failed): %#x\n", LMIC.opmode); + } + } } ClearLoraData(); @@ -890,15 +912,6 @@ void doSleepAlert(const bool fDeepSleep) } } - // we wait an extra five seconds... - //uint32_t tNow = millis(); - //while (uint32_t(millis() - tNow) < 5000) - //{ - // gCatena.poll(); - // yield(); - //} - - if (config_data.debug_level > 0) { gCatena.SafePrintf("Now it is safe to go to sleep\n"); } diff --git a/mini_beieli_node.h b/mini_beieli_node.h index c9018b5..d01e150 100644 --- a/mini_beieli_node.h +++ b/mini_beieli_node.h @@ -56,7 +56,7 @@ enum { | \****************************************************************************/ -static const int32_t fwVersion = 20200601; +static const int32_t fwVersion = 20200602; static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages; static const byte MAX_VALUES_TO_SEND = 8;