send sporadic init packets
This commit is contained in:
parent
a991af0cd3
commit
c13648ff6d
|
|
@ -92,8 +92,10 @@ LORA_data lora_data;
|
||||||
LORA_data_first lora_data_first;
|
LORA_data_first lora_data_first;
|
||||||
CONFIG_data config_data;
|
CONFIG_data config_data;
|
||||||
SENSOR_data last_sensor_reading;
|
SENSOR_data last_sensor_reading;
|
||||||
long iteration = 0; // what iteration number do we have, starts with 0
|
long iteration = 0; // what iteration number do we have, starts with 0
|
||||||
|
long package_counter = 0; // sent package counter
|
||||||
bool send_in_progress = false;
|
bool send_in_progress = false;
|
||||||
|
bool next_package_is_init_package = true;
|
||||||
|
|
||||||
// generic timer
|
// generic timer
|
||||||
long t_cur;
|
long t_cur;
|
||||||
|
|
@ -660,7 +662,7 @@ void StartNewIteration() {
|
||||||
}
|
}
|
||||||
fUsbPower = (vBus > 4.3) ? true : false;
|
fUsbPower = (vBus > 4.3) ? true : false;
|
||||||
|
|
||||||
if (iteration <= 3) {
|
if (next_package_is_init_package) {
|
||||||
lora_data_first.vbat = current_sensor_reading.vbat;
|
lora_data_first.vbat = current_sensor_reading.vbat;
|
||||||
lora_data_first.weight1 = current_sensor_reading.weight1;
|
lora_data_first.weight1 = current_sensor_reading.weight1;
|
||||||
lora_data_first.weight2 = current_sensor_reading.weight2;
|
lora_data_first.weight2 = current_sensor_reading.weight2;
|
||||||
|
|
@ -691,7 +693,7 @@ void StartNewIteration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_data.debug_level > 0) {
|
if (config_data.debug_level > 0) {
|
||||||
ShowLORAData(iteration <= 3);
|
ShowLORAData(next_package_is_init_package);
|
||||||
}
|
}
|
||||||
my_position++;
|
my_position++;
|
||||||
|
|
||||||
|
|
@ -699,13 +701,15 @@ 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 ( (iteration <= 3) || (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) || ((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("%010d - startSendingUplink(), my_position: %d, iteration: %d\n", millis(), my_position, iteration);
|
gCatena.SafePrintf("%010d - startSendingUplink(), my_position: %d, iteration: %d, package_counter: %d\n", millis(), my_position, iteration, package_counter);
|
||||||
}
|
}
|
||||||
// the first 3 packets are "Init-Packets"...
|
// the first 3 packets are "Init-Packets" or each INIT_PACKAGE_INTERVAL ...
|
||||||
startSendingUplink(iteration <= 3);
|
startSendingUplink(next_package_is_init_package);
|
||||||
|
next_package_is_init_package = ((iteration < 3) || ((package_counter % INIT_PACKAGE_INTERVAL) == 0));
|
||||||
|
|
||||||
if (config_data.debug_level > 1) {
|
if (config_data.debug_level > 1) {
|
||||||
gLed.Set(LedPattern::TwoShort);
|
gLed.Set(LedPattern::TwoShort);
|
||||||
}
|
}
|
||||||
|
|
@ -726,7 +730,7 @@ void StartNewIteration() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iteration > 3) {
|
if (not(next_package_is_init_package)) {
|
||||||
// we make the current sensor reading to the last one...
|
// we make the current sensor reading to the last one...
|
||||||
last_sensor_reading = current_sensor_reading;
|
last_sensor_reading = current_sensor_reading;
|
||||||
}
|
}
|
||||||
|
|
@ -804,12 +808,13 @@ 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);
|
||||||
|
package_counter++;
|
||||||
} 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);
|
||||||
|
package_counter++;
|
||||||
}
|
}
|
||||||
ClearLoraData();
|
ClearLoraData();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ enum {
|
||||||
|
|
|
|
||||||
\****************************************************************************/
|
\****************************************************************************/
|
||||||
|
|
||||||
static const int32_t fwVersion = 20191212;
|
static const int32_t fwVersion = 20191214;
|
||||||
|
|
||||||
// wait between samples
|
// wait between samples
|
||||||
// 3 sec is a good delay so that load cell did not warm up
|
// 3 sec is a good delay so that load cell did not warm up
|
||||||
|
|
@ -63,6 +63,7 @@ static const int32_t fwVersion = 20191212;
|
||||||
// to go so that the next sample is more valid
|
// to go so that the next sample is more valid
|
||||||
const int WAITTIMELOADSAMPLES = 3;
|
const int WAITTIMELOADSAMPLES = 3;
|
||||||
|
|
||||||
|
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;
|
||||||
//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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue