diff --git a/mini-beieli-node.ino b/mini-beieli-node.ino index 7d475cd..0612222 100644 --- a/mini-beieli-node.ino +++ b/mini-beieli-node.ino @@ -129,7 +129,7 @@ sMyExtraCommands_top( | \****************************************************************************/ -static const int32_t fwVersion = 20190926; +static const int32_t fwVersion = 20191003; static const byte MAX_VALUES_TO_SEND = 8; static const uint8_t LORA_DATA_VERSION = 1; static const uint8_t LORA_DATA_VERSION_FIRST_PACKAGE = 129; @@ -936,14 +936,26 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage if (port == 1 && nMessage == 1) { if (pMessage[0] == 0) { - gCatena.SafePrintf("reset both scales to zero\n"); + if (config_data.debug_level > 0) { + gCatena.SafePrintf("reset both scales to zero\n"); + } + ReadSensors(false, true); + config_data.cal_w1_0 = last_sensor_reading.weight1; + config_data.cal_w2_0 = last_sensor_reading.weight2; + gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data)); } } if (port == 1 && nMessage == 9) { if (pMessage[0] == 1) { memcpy(bytearray.buf, pMessage, 9); - gCatena.SafePrintf("tare scales, A: %d, B: %d\n", bytearray.value.gram_A, bytearray.value.gram_A); + if (config_data.debug_level > 0) { + gCatena.SafePrintf("tare scales, A: %d, B: %d\n", bytearray.value.gram_A, bytearray.value.gram_B); + } + ReadSensors(false, true); + config_data.cal_w1_factor = (((float)last_sensor_reading.weight1 - config_data.cal_w1_0) / bytearray.value.gram_A); + config_data.cal_w2_factor = (((float)last_sensor_reading.weight2 - config_data.cal_w2_0) / bytearray.value.gram_B); + gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data)); } }