Compare commits

..
2 Commits
Author SHA1 Message Date
jlehmann e30a8293ac do not try a second time to use SendBuffer at failure 2020-05-29 17:12:20 +02:00
jlehmann 174f8b360f refactor a bit 2020-05-29 16:16:12 +02:00
3 changed files with 24 additions and 30 deletions
+21 -27
View File
@@ -697,8 +697,16 @@ void StartNewIteration() {
} }
while (send_in_progress && ((millis() - start_time) < 300000)) while (send_in_progress && ((millis() - start_time) < 300000))
{ {
gCatena.poll(); os_runloop_once();
yield(); // gCatena.poll();
// yield();
}
// handle timeout...
if (send_in_progress) {
if (config_data.debug_level > 0) {
gCatena.SafePrintf("looks like we timed out waiting for sending to finish...\n", wait_time);
}
send_in_progress = false;
} }
wait_time = (uint32_t)((millis() - start_time) / 1000); wait_time = (uint32_t)((millis() - start_time) / 1000);
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
@@ -783,37 +791,20 @@ void startSendingUplink(bool firstTime)
fConfirmed = true; fConfirmed = true;
} }
gCatena.poll(); os_runloop_once();
//gCatena.poll();
if (firstTime) { if (firstTime) {
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("SendBuffer firstTime\n"); gCatena.SafePrintf("SendBuffer firstTime\n");
} }
bool success = gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort); gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
// we try a second time if not successful...
if (! success) {
if (config_data.debug_level > 0) {
gCatena.SafePrintf("SendBuffer was not successful, we try a second time...\n");
}
gCatena.poll();
delay(500);
gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
}
package_counter++; package_counter++;
} else { } else {
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("SendBuffer not firstTime\n"); gCatena.SafePrintf("SendBuffer not firstTime\n");
} }
bool success = gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort); gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
// we try a second time if not successful...
if (! success) {
if (config_data.debug_level > 0) {
gCatena.SafePrintf("SendBuffer was not successful, we try a second time...\n");
}
gCatena.poll();
delay(500);
gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
}
package_counter++; package_counter++;
} }
@@ -833,6 +824,7 @@ static void sendBufferDoneCb(
pFn = settleDoneCb; pFn = settleDoneCb;
if (! fStatus) if (! fStatus)
{ {
send_in_progress = false;
if (!gLoRaWAN.IsProvisioned()) if (!gLoRaWAN.IsProvisioned())
{ {
// we'll talk about it at the callback. // we'll talk about it at the callback.
@@ -968,8 +960,9 @@ void doSleepAlert(const bool fDeepSleep)
while (uint32_t(millis() - tNow) < 1000) while (uint32_t(millis() - tNow) < 1000)
{ {
gCatena.poll(); os_runloop_once();
yield(); //gCatena.poll();
//yield();
} }
if (config_data.debug_level > 2) { if (config_data.debug_level > 2) {
gCatena.SafePrintf("."); gCatena.SafePrintf(".");
@@ -981,8 +974,9 @@ void doSleepAlert(const bool fDeepSleep)
uint32_t tNow = millis(); uint32_t tNow = millis();
while (uint32_t(millis() - tNow) < 100) while (uint32_t(millis() - tNow) < 100)
{ {
gCatena.poll(); os_runloop_once();
yield(); //gCatena.poll();
//yield();
} }
} }
else if (config_data.debug_level > 2) { else if (config_data.debug_level > 2) {
+1 -1
View File
@@ -56,7 +56,7 @@ enum {
| |
\****************************************************************************/ \****************************************************************************/
static const int32_t fwVersion = 20200528; static const int32_t fwVersion = 20200529;
static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages; static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages;
static const byte MAX_VALUES_TO_SEND = 8; static const byte MAX_VALUES_TO_SEND = 8;
+2 -2
View File
@@ -14,7 +14,7 @@ NAU7802 myScale; //Create instance of the NAU7802 class
byte debug_level; byte debug_level;
byte interruptPin = A0; //byte interruptPin = A0;
void SetScalesDebugLevel(byte dbg_level) void SetScalesDebugLevel(byte dbg_level)
{ {
@@ -47,7 +47,7 @@ bool SetupScales(byte dbg_level)
if (debug_level > 0) { if (debug_level > 0) {
gCatena.SafePrintf("SetupScales start\n"); gCatena.SafePrintf("SetupScales start\n");
} }
pinMode(interruptPin, INPUT); // pinMode(interruptPin, INPUT);
if (!myScale.begin(Wire, false)) if (!myScale.begin(Wire, false))
{ {