fix bug with last_values

This commit is contained in:
Joerg Lehmann 2020-06-29 20:10:04 +02:00
parent 2ebcac04b7
commit ddec85f57e
1 changed files with 22 additions and 20 deletions

View File

@ -156,7 +156,7 @@ void setup(void)
setup_platform(); setup_platform();
SetupScales(config_data.debug_level); SetupScales(config_data.debug_level);
ClearLoraData(); ClearLoraData(true);
setup_bme280(); setup_bme280();
setup_flash(); setup_flash();
@ -382,7 +382,7 @@ void loop()
} }
} }
void ClearLoraData(void) void ClearLoraData(bool clearLastValues)
{ {
lora_data.version = LORA_DATA_VERSION; lora_data.version = LORA_DATA_VERSION;
lora_data.vbat = 0; lora_data.vbat = 0;
@ -412,13 +412,15 @@ void ClearLoraData(void)
my_position = 0; my_position = 0;
// We initialize last_sensor_reading // We initialize last_sensor_reading
last_sensor_reading.vbat = 0; if (clearLastValues) {
last_sensor_reading.weight1 = 0; last_sensor_reading.vbat = 0;
last_sensor_reading.weight2 = 0; last_sensor_reading.weight1 = 0;
last_sensor_reading.weight = 0; last_sensor_reading.weight2 = 0;
last_sensor_reading.temperature = 0; last_sensor_reading.weight = 0;
last_sensor_reading.humidity = 0; last_sensor_reading.temperature = 0;
last_sensor_reading.pressure = 0; last_sensor_reading.humidity = 0;
last_sensor_reading.pressure = 0;
}
} }
void ShowLORAData(bool firstTime) void ShowLORAData(bool firstTime)
@ -504,7 +506,7 @@ uint8_t GetVBatValue(int millivolts)
void DoDeepSleep(uint32_t sleep_time) void DoDeepSleep(uint32_t sleep_time)
{ {
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("DoDeepSleep, now going to deep sleep, millis: %d\n",millis()); gCatena.SafePrintf("DoDeepSleep, now going to deep sleep, millis: %d\n", millis());
} }
// Prepare Deep Sleep // Prepare Deep Sleep
@ -521,7 +523,7 @@ void DoDeepSleep(uint32_t sleep_time)
deepSleepRecovery(); deepSleepRecovery();
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("done with deep sleep, millis: %d\n",millis()); gCatena.SafePrintf("done with deep sleep, millis: %d\n", millis());
} }
} }
@ -769,7 +771,7 @@ void StartNewIteration() {
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode just before Sleeping: %#x\n", LMIC.opmode); gCatena.SafePrintf("LMIC.opmode just before Sleeping: %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime()); gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime());
gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n",LMIC.seqnoUp, LMIC.seqnoDn); gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n", LMIC.seqnoUp, LMIC.seqnoDn);
} }
if (!fUsbPower && !stop_iterations) { if (!fUsbPower && !stop_iterations) {
@ -830,19 +832,19 @@ void startSendingUplink(bool firstTime, bool confirmed)
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode just after SendBuffer (successful): %#x\n", LMIC.opmode); gCatena.SafePrintf("LMIC.opmode just after SendBuffer (successful): %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime()); gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime());
gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n",LMIC.seqnoUp, LMIC.seqnoDn); gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n", LMIC.seqnoUp, LMIC.seqnoDn);
} }
} }
else { else {
gCatena.SafePrintf("LMIC.opmode just before SendBuffer (failed): %#x\n", LMIC.opmode); gCatena.SafePrintf("LMIC.opmode just before SendBuffer (failed): %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime()); gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime());
gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n",LMIC.seqnoUp, LMIC.seqnoDn); gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n", LMIC.seqnoUp, LMIC.seqnoDn);
} }
} else { } else {
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode just before SendBuffer: %#x\n", LMIC.opmode); gCatena.SafePrintf("LMIC.opmode just before SendBuffer: %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime()); gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime());
gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n",LMIC.seqnoUp, LMIC.seqnoDn); gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n", LMIC.seqnoUp, LMIC.seqnoDn);
gCatena.SafePrintf("SendBuffer not firstTime\n"); gCatena.SafePrintf("SendBuffer not firstTime\n");
} }
if (gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort)) { if (gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort)) {
@ -850,16 +852,16 @@ void startSendingUplink(bool firstTime, bool confirmed)
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("LMIC.opmode just after SendBuffer (successful): %#x\n", LMIC.opmode); gCatena.SafePrintf("LMIC.opmode just after SendBuffer (successful): %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime()); gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime());
gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n",LMIC.seqnoUp, LMIC.seqnoDn); gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n", LMIC.seqnoUp, LMIC.seqnoDn);
} }
} else { } else {
gCatena.SafePrintf("LMIC.opmode just before SendBuffer (failed): %#x\n", LMIC.opmode); gCatena.SafePrintf("LMIC.opmode just before SendBuffer (failed): %#x\n", LMIC.opmode);
gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime()); gCatena.SafePrintf("LMIC.globalDutyRate: %d, LMIC.globalDutyAvail: %d, os_getTime: %d\n", LMIC.globalDutyRate, LMIC.globalDutyAvail, os_getTime());
gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n",LMIC.seqnoUp, LMIC.seqnoDn); gCatena.SafePrintf("LMIC.seqnoUp: %d, LMIC.seqnoDn: %d\n", LMIC.seqnoUp, LMIC.seqnoDn);
} }
} }
ClearLoraData(); ClearLoraData(false);
} }
static void sendBufferDoneCb( static void sendBufferDoneCb(