This commit is contained in:
Joerg Lehmann 2019-11-22 21:22:33 +01:00
parent 0b493ffa56
commit 116e92496e
2 changed files with 25 additions and 21 deletions

View File

@ -179,9 +179,6 @@ void setup_platform(void)
gCatena.SafePrintf("cal_w1_factor: %d.%03d\n", (int)config_data.cal_w1_factor, (int)(config_data.cal_w1_factor * 1000) % 1000); gCatena.SafePrintf("cal_w1_factor: %d.%03d\n", (int)config_data.cal_w1_factor, (int)(config_data.cal_w1_factor * 1000) % 1000);
gCatena.SafePrintf("cal_w2_factor: %d.%03d\n", (int)config_data.cal_w2_factor, (int)(config_data.cal_w2_factor * 1000) % 1000); gCatena.SafePrintf("cal_w2_factor: %d.%03d\n", (int)config_data.cal_w2_factor, (int)(config_data.cal_w2_factor * 1000) % 1000);
gCatena.SafePrintf("debug_level: %d\n", (int)config_data.debug_level); gCatena.SafePrintf("debug_level: %d\n", (int)config_data.debug_level);
gCatena.SafePrintf("Size of config_data: %d\n", sizeof(config_data));
gCatena.SafePrintf("Size of lora_data_first: %d\n", sizeof(lora_data_first));
gCatena.SafePrintf("Size of lora_data: %d\n", sizeof(lora_data));
} }
@ -415,6 +412,8 @@ void ClearLoraData(void)
void ShowLORAData(bool firstTime) void ShowLORAData(bool firstTime)
{ {
gCatena.SafePrintf("%010d - ShowLORAData\n", millis());
if (firstTime) { if (firstTime) {
gCatena.SafePrintf("{\n"); gCatena.SafePrintf("{\n");
@ -528,7 +527,7 @@ void ReadSensors(SENSOR_data &sensor_data) {
int vbat_mv = (int)(gCatena.ReadVbat() * 1000.0f); int vbat_mv = (int)(gCatena.ReadVbat() * 1000.0f);
res.vbat = GetVBatValue(vbat_mv); res.vbat = GetVBatValue(vbat_mv);
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("vBat: %d mV\n", vbat_mv); gCatena.SafePrintf("%010d - vBat: %d mV\n", vbat_mv);
} }
// Read Scales // Read Scales
@ -685,18 +684,6 @@ void StartNewIteration() {
last_sensor_reading = current_sensor_reading; last_sensor_reading = current_sensor_reading;
} }
if (config_data.debug_level > 0) {
gCatena.SafePrintf("%010d - now going to sleep for %d seconds...\n", millis(), CATCFG_T_INTERVAL);
if (fUsbPower) {
gCatena.SafePrintf("USB Power is on\n");
} else {
gCatena.SafePrintf("USB Power is off\n");
}
//Serial.flush();
if (config_data.debug_level > 1) {
gLed.Set(LedPattern::Sleeping);
}
}
uint32_t sleep_time_sec; uint32_t sleep_time_sec;
if (wait_time < CATCFG_T_INTERVAL) { if (wait_time < CATCFG_T_INTERVAL) {
sleep_time_sec = CATCFG_T_INTERVAL - wait_time; sleep_time_sec = CATCFG_T_INTERVAL - wait_time;
@ -704,6 +691,20 @@ void StartNewIteration() {
// minimal sleep time is 5 seconds // minimal sleep time is 5 seconds
sleep_time_sec = 5; sleep_time_sec = 5;
} }
if (config_data.debug_level > 0) {
gCatena.SafePrintf("%010d - now going to sleep for %d seconds...\n", millis(), sleep_time_sec);
if (fUsbPower) {
gCatena.SafePrintf("%010d - USB Power is on\n", millis());
} else {
gCatena.SafePrintf("%010d - USB Power is off\n", millis());
}
//Serial.flush();
if (config_data.debug_level > 1) {
gLed.Set(LedPattern::Sleeping);
}
}
if (!fUsbPower) { if (!fUsbPower) {
DoDeepSleep(sleep_time_sec); DoDeepSleep(sleep_time_sec);
os_setTimedCallback( os_setTimedCallback(
@ -712,7 +713,7 @@ void StartNewIteration() {
startNewIterationCb); startNewIterationCb);
} }
else { else {
gCatena.SafePrintf("%010d - light sleep; os_setTimedCallback for startNewIterationCb in %d...\n", millis(), sleep_time_sec); gCatena.SafePrintf("%010d - light sleep; os_setTimedCallback for startNewIterationCb in %d...seconds\n", millis(), sleep_time_sec);
os_setTimedCallback( os_setTimedCallback(
&iterationJob, &iterationJob,
os_getTime() + sec2osticks(sleep_time_sec), os_getTime() + sec2osticks(sleep_time_sec),
@ -722,6 +723,8 @@ void StartNewIteration() {
void startSendingUplink(bool firstTime) void startSendingUplink(bool firstTime)
{ {
send_in_progress = true;
LedPattern savedLed; LedPattern savedLed;
if (config_data.debug_level > 1) { if (config_data.debug_level > 1) {
savedLed = gLed.Set(LedPattern::Measuring); savedLed = gLed.Set(LedPattern::Measuring);
@ -747,14 +750,12 @@ void startSendingUplink(bool firstTime)
gCatena.SafePrintf("%010d - SendBuffer firstTime\n", millis()); gCatena.SafePrintf("%010d - SendBuffer firstTime\n", millis());
} }
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);
send_in_progress = true;
} else { } else {
if (config_data.debug_level > 0) { if (config_data.debug_level > 0) {
gCatena.SafePrintf("%010d - SendBuffer not firstTime\n", millis()); gCatena.SafePrintf("%010d - SendBuffer not firstTime\n", millis());
} }
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);
send_in_progress = true;
} }
ClearLoraData(); ClearLoraData();
} }
@ -851,7 +852,10 @@ static void warmupDoneCb(osjob_t* pJob)
static void startNewIterationCb(osjob_t* pJob) static void startNewIterationCb(osjob_t* pJob)
{ {
gCatena.SafePrintf("%010d - startNewIterationCb\n", millis()); if (config_data.debug_level > 0) {
gCatena.SafePrintf("%010d - startNewIterationCb\n", millis());
}
StartNewIteration(); StartNewIteration();
} }

View File

@ -55,7 +55,7 @@ enum {
| |
\****************************************************************************/ \****************************************************************************/
static const int32_t fwVersion = 20191121; static const int32_t fwVersion = 20191122;
static const byte MAX_VALUES_TO_SEND = 8; static const byte MAX_VALUES_TO_SEND = 8;
//static const byte MAX_VALUES_TO_SEND = 1; // Testing //static const byte MAX_VALUES_TO_SEND = 1; // Testing
static const uint8_t LORA_DATA_VERSION = 1; static const uint8_t LORA_DATA_VERSION = 1;