Compare commits

..
2 Commits
Author SHA1 Message Date
jlehmann d0389af061 try second time if first try fails (SendBuffer) 2020-05-28 20:08:21 +02:00
jlehmann 7c8a52cafe tune code 2020-05-28 13:27:19 +02:00
3 changed files with 31 additions and 6 deletions
+22 -2
View File
@@ -783,17 +783,37 @@ void startSendingUplink(bool firstTime)
fConfirmed = true; fConfirmed = true;
} }
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");
} }
gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort); bool success = 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");
} }
gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort); bool success = 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++;
} }
+1 -1
View File
@@ -56,7 +56,7 @@ enum {
| |
\****************************************************************************/ \****************************************************************************/
static const int32_t fwVersion = 20200527; static const int32_t fwVersion = 20200528;
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;
+8 -3
View File
@@ -96,9 +96,11 @@ long ReadScale(char channel)
long readings[num_scale_readings]; // create arry to hold readings long readings[num_scale_readings]; // create arry to hold readings
for (int i = 0; i < num_scale_readings; i++) { for (int i = 0; i < num_scale_readings; i++) {
//while (digitalRead(interruptPin) == LOW) { //while (digitalRead(interruptPin) == LOW) {
long mytimer = millis();
while (! myScale.available()) { while (! myScale.available()) {
// we set a timeout of 10 seconds for the measurement... // we set a timeout of 10 seconds for the measurement...
if ((millis() - startTime) > 10000) { if ((millis() - mytimer) > 10000) {
// Timeout reading scale...
Wire.endTransmission(true); Wire.endTransmission(true);
if (debug_level > 0) { if (debug_level > 0) {
gCatena.SafePrintf("Timeout while reading scale...\n"); gCatena.SafePrintf("Timeout while reading scale...\n");
@@ -107,11 +109,14 @@ long ReadScale(char channel)
} }
delay(1); delay(1);
} }
long reading = myScale.getReading(); long reading;
if (myScale.available()) {
reading = myScale.getReading();
readings[i] = reading;
}
if (debug_level > 0) { if (debug_level > 0) {
gCatena.SafePrintf("Reading: %d\n", reading); gCatena.SafePrintf("Reading: %d\n", reading);
} }
readings[i] = reading; // fill the array with instantaneous readings from the scale
delay(10); delay(10);
} }