Compare commits

..
6 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
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
jlehmann b71e0c0f0c make it more stable 2020-05-27 15:10:40 +02:00
jlehmann d2e4b81416 remove unused variable 2020-05-27 10:20:45 +02:00
3 changed files with 37 additions and 18 deletions
+22 -9
View File
@@ -677,7 +677,7 @@ void StartNewIteration() {
// we send data the first time the system is started, when the array is full // we send data the first time the system is started, when the array is full
// or when the weight has fallen more than threshold or the first measurement is // or when the weight has fallen more than threshold or the first measurement is
// more than one hour old (which should not happen :-) ) // more than one hour old (which should not happen :-) )
if ( (next_package_is_init_package) || (my_position >= MAX_VALUES_TO_SEND) || ((last_sensor_reading.weight - current_sensor_reading.weight) > SEND_DIFF_THRESHOLD_5GRAMS) || ((millis() - timer_pos0) > 3600000)) { if ( (next_package_is_init_package) || (my_position >= MAX_VALUES_TO_SEND) || (abs(last_sensor_reading.weight - current_sensor_reading.weight) > SEND_DIFF_THRESHOLD_5GRAMS) || ((millis() - timer_pos0) > 3600000)) {
lora_data.offset_last_reading = (uint8_t)((millis() - timer_pos0) / 1000 / 60); lora_data.offset_last_reading = (uint8_t)((millis() - timer_pos0) / 1000 / 60);
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("startSendingUplink(), my_position: %d, iteration: %d, package_counter: %d\n", my_position, iteration, package_counter); gCatena.SafePrintf("startSendingUplink(), my_position: %d, iteration: %d, package_counter: %d\n", my_position, iteration, package_counter);
@@ -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,6 +791,9 @@ void startSendingUplink(bool firstTime)
fConfirmed = true; fConfirmed = true;
} }
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");
@@ -813,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.
@@ -948,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(".");
@@ -961,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) {
@@ -1023,6 +1037,7 @@ void doDeepSleep(osjob_t *pJob)
void deepSleepPrepare(void) void deepSleepPrepare(void)
{ {
Serial.end(); Serial.end();
Wire.endTransmission(true);
Wire.end(); Wire.end();
SPI.end(); SPI.end();
if (fFlash) if (fFlash)
@@ -1112,8 +1127,6 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
float fval; float fval;
} u; } u;
SENSOR_data temp_sensor_data;
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("receiveMessage was called!!!\n"); gCatena.SafePrintf("receiveMessage was called!!!\n");
} }
+2 -2
View File
@@ -56,7 +56,7 @@ enum {
| |
\****************************************************************************/ \****************************************************************************/
static const int32_t fwVersion = 20200525; 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;
@@ -64,7 +64,7 @@ static const byte MAX_VALUES_TO_SEND = 8;
static const uint8_t LORA_DATA_VERSION = 1; static const uint8_t LORA_DATA_VERSION = 1;
static const uint8_t LORA_DATA_VERSION_FIRST_PACKAGE = 128; static const uint8_t LORA_DATA_VERSION_FIRST_PACKAGE = 128;
static const uint32_t PRESSURE_OFFSET = 825; static const uint32_t PRESSURE_OFFSET = 825;
static const uint16_t SEND_DIFF_THRESHOLD_5GRAMS = 10; // when weight value drops by 50g, then send data static const uint16_t SEND_DIFF_THRESHOLD_5GRAMS = 20; // when weight changes by 100g, then send data
static const long NOT_ATTACHED = -2147483648; static const long NOT_ATTACHED = -2147483648;
static const byte INIT_PACKETS = 5; static const byte INIT_PACKETS = 5;
+13 -7
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)
{ {
@@ -24,7 +24,7 @@ void SetScalesDebugLevel(byte dbg_level)
bool InitializeScales() bool InitializeScales()
{ {
bool result; bool result;
result &= myScale.reset(); //Reset all registers result = myScale.reset(); //Reset all registers
result &= myScale.powerUp(); //Power on analog and digital sections of the scale result &= myScale.powerUp(); //Power on analog and digital sections of the scale
result &= myScale.setIntPolarityHigh(); result &= myScale.setIntPolarityHigh();
@@ -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))
{ {
@@ -96,9 +96,12 @@ 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 60 seconds for the measurement... // we set a timeout of 10 seconds for the measurement...
if ((millis() - startTime) > 60000) { if ((millis() - mytimer) > 10000) {
// Timeout reading scale...
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");
} }
@@ -106,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);
} }