new Heltec Library, send confirmed data when necessary, FW-Version 20240622

This commit is contained in:
2024-06-22 09:35:37 +02:00
parent 384d262905
commit ec7a10f5ff
2 changed files with 38 additions and 10 deletions
+20 -6
View File
@@ -12,7 +12,7 @@ BME280 bme280;
/******************************************************************************/
/* Firmware Version */
/******************************************************************************/
static const int32_t fwVersion = 20220930;
static const int32_t fwVersion = 20240622;
/******************************************************************************/
/* LoraWAN Settings */
@@ -225,6 +225,7 @@ bool stop_iterations = false;
bool start_new_iteration = false;
bool next_package_is_init_package = true;
uint32_t gRebootMs;
char last_channel = 'X';
/******************************************************************************/
/* Functions for Global Data Structures */
@@ -404,6 +405,9 @@ bool InitializeScales()
result &= nau7802.setSampleRate(NAU7802_SPS_40); //Set samples per second to 40
result &= nau7802.setRegister(NAU7802_ADC, 0x30); //Turn off CLK_CHP. From 9.1 power on sequencing.
// see https://github.com/sparkfun/SparkFun_Qwiic_Scale_NAU7802_Arduino_Library/issues/7
//result &= nau7802.clearBit(NAU7802_PGA_PWR_PGA_CAP_EN, NAU7802_PGA_PWR);
return result;
}
@@ -446,14 +450,22 @@ long ReadScale(char channel)
channelNumber = NAU7802_CHANNEL_2;
}
unsigned long startTime = millis();
nau7802.setChannel(channelNumber);
bool calibrate_success = nau7802.calibrateAFE();
if (! calibrate_success) {
if (channel != last_channel) {
last_channel = channel;
nau7802.setChannel(channelNumber);
bool calibrate_success = nau7802.calibrateAFE();
if (! calibrate_success) {
if (config_data.debug_level > 0) {
Serial.printf("Error: Calibration not successful!\n");
}
}
if (config_data.debug_level > 0) {
Serial.printf("Error: Calibration not successful!\n");
Serial.printf("getChannel1Gain: %d\n", nau7802.getChannel1Gain());
Serial.printf("getChannel1Offset: %d\n", nau7802.getChannel1Offset());
Serial.printf("NAU7802_GCAL2_B3: %d\n", nau7802.get32BitRegister(NAU7802_GCAL2_B3));
Serial.printf("NAU7802_OCAL2_B2: %d\n", nau7802.get32BitRegister(NAU7802_OCAL2_B2));
}
}
if (nau7802.available()) {
long dummy = nau7802.getReading();
}
@@ -967,6 +979,8 @@ void loop()
case DEVICE_STATE_SEND:
{
if (ReadSensors(false)) {
// we send confirmed packages when weight change is too big or for every init package
isTxConfirmed = (TooBigWeightChange()) || (iteration <= INIT_PACKETS) || (iteration % INIT_PACKAGE_INTERVAL == 0);
prepareTxFrame(appPort);
LoRaWAN.send();
package_counter++;