Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0389af061 | ||
|
|
7c8a52cafe | ||
|
|
b71e0c0f0c | ||
|
|
d2e4b81416 |
+22
-3
@@ -677,7 +677,7 @@ 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 ( (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)) {
|
if ( (next_package_is_init_package) || (my_position >= MAX_VALUES_TO_SEND) || (abs(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("startSendingUplink(), my_position: %d, iteration: %d, package_counter: %d\n", my_position, iteration, package_counter);
|
gCatena.SafePrintf("startSendingUplink(), my_position: %d, iteration: %d, package_counter: %d\n", my_position, iteration, package_counter);
|
||||||
@@ -783,17 +783,37 @@ void startSendingUplink(bool firstTime)
|
|||||||
fConfirmed = true;
|
fConfirmed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gCatena.poll();
|
||||||
|
|
||||||
if (firstTime) {
|
if (firstTime) {
|
||||||
if (config_data.debug_level > 0) {
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("SendBuffer firstTime\n");
|
gCatena.SafePrintf("SendBuffer firstTime\n");
|
||||||
}
|
}
|
||||||
|
bool success = gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
|
||||||
|
// we try a second time if not successful...
|
||||||
|
if (! success) {
|
||||||
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("SendBuffer was not successful, we try a second time...\n");
|
||||||
|
}
|
||||||
|
gCatena.poll();
|
||||||
|
delay(500);
|
||||||
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++;
|
package_counter++;
|
||||||
} else {
|
} else {
|
||||||
if (config_data.debug_level > 0) {
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("SendBuffer not firstTime\n");
|
gCatena.SafePrintf("SendBuffer not firstTime\n");
|
||||||
}
|
}
|
||||||
|
bool success = gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
|
||||||
|
// we try a second time if not successful...
|
||||||
|
if (! success) {
|
||||||
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("SendBuffer was not successful, we try a second time...\n");
|
||||||
|
}
|
||||||
|
gCatena.poll();
|
||||||
|
delay(500);
|
||||||
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++;
|
package_counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1023,6 +1043,7 @@ void doDeepSleep(osjob_t *pJob)
|
|||||||
void deepSleepPrepare(void)
|
void deepSleepPrepare(void)
|
||||||
{
|
{
|
||||||
Serial.end();
|
Serial.end();
|
||||||
|
Wire.endTransmission(true);
|
||||||
Wire.end();
|
Wire.end();
|
||||||
SPI.end();
|
SPI.end();
|
||||||
if (fFlash)
|
if (fFlash)
|
||||||
@@ -1112,8 +1133,6 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
|
|||||||
float fval;
|
float fval;
|
||||||
} u;
|
} u;
|
||||||
|
|
||||||
SENSOR_data temp_sensor_data;
|
|
||||||
|
|
||||||
if (config_data.debug_level > 0) {
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("receiveMessage was called!!!\n");
|
gCatena.SafePrintf("receiveMessage was called!!!\n");
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -56,7 +56,7 @@ enum {
|
|||||||
|
|
|
|
||||||
\****************************************************************************/
|
\****************************************************************************/
|
||||||
|
|
||||||
static const int32_t fwVersion = 20200525;
|
static const int32_t fwVersion = 20200528;
|
||||||
|
|
||||||
static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages;
|
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;
|
||||||
@@ -64,7 +64,7 @@ static const byte MAX_VALUES_TO_SEND = 8;
|
|||||||
static const uint8_t LORA_DATA_VERSION = 1;
|
static const uint8_t LORA_DATA_VERSION = 1;
|
||||||
static const uint8_t LORA_DATA_VERSION_FIRST_PACKAGE = 128;
|
static const uint8_t LORA_DATA_VERSION_FIRST_PACKAGE = 128;
|
||||||
static const uint32_t PRESSURE_OFFSET = 825;
|
static const uint32_t PRESSURE_OFFSET = 825;
|
||||||
static const uint16_t SEND_DIFF_THRESHOLD_5GRAMS = 10; // when weight value drops by 50g, then send data
|
static const uint16_t SEND_DIFF_THRESHOLD_5GRAMS = 20; // when weight changes by 100g, then send data
|
||||||
static const long NOT_ATTACHED = -2147483648;
|
static const long NOT_ATTACHED = -2147483648;
|
||||||
static const byte INIT_PACKETS = 5;
|
static const byte INIT_PACKETS = 5;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ void SetScalesDebugLevel(byte dbg_level)
|
|||||||
bool InitializeScales()
|
bool InitializeScales()
|
||||||
{
|
{
|
||||||
bool result;
|
bool result;
|
||||||
result &= myScale.reset(); //Reset all registers
|
result = myScale.reset(); //Reset all registers
|
||||||
result &= myScale.powerUp(); //Power on analog and digital sections of the scale
|
result &= myScale.powerUp(); //Power on analog and digital sections of the scale
|
||||||
|
|
||||||
result &= myScale.setIntPolarityHigh();
|
result &= myScale.setIntPolarityHigh();
|
||||||
@@ -96,9 +96,12 @@ long ReadScale(char channel)
|
|||||||
long readings[num_scale_readings]; // create arry to hold readings
|
long readings[num_scale_readings]; // create arry to hold readings
|
||||||
for (int i = 0; i < num_scale_readings; i++) {
|
for (int i = 0; i < num_scale_readings; i++) {
|
||||||
//while (digitalRead(interruptPin) == LOW) {
|
//while (digitalRead(interruptPin) == LOW) {
|
||||||
|
long mytimer = millis();
|
||||||
while (! myScale.available()) {
|
while (! myScale.available()) {
|
||||||
// we set a timeout of 60 seconds for the measurement...
|
// we set a timeout of 10 seconds for the measurement...
|
||||||
if ((millis() - startTime) > 60000) {
|
if ((millis() - mytimer) > 10000) {
|
||||||
|
// Timeout reading scale...
|
||||||
|
Wire.endTransmission(true);
|
||||||
if (debug_level > 0) {
|
if (debug_level > 0) {
|
||||||
gCatena.SafePrintf("Timeout while reading scale...\n");
|
gCatena.SafePrintf("Timeout while reading scale...\n");
|
||||||
}
|
}
|
||||||
@@ -106,11 +109,14 @@ long ReadScale(char channel)
|
|||||||
}
|
}
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
long reading = myScale.getReading();
|
long reading;
|
||||||
|
if (myScale.available()) {
|
||||||
|
reading = myScale.getReading();
|
||||||
|
readings[i] = reading;
|
||||||
|
}
|
||||||
if (debug_level > 0) {
|
if (debug_level > 0) {
|
||||||
gCatena.SafePrintf("Reading: %d\n", reading);
|
gCatena.SafePrintf("Reading: %d\n", reading);
|
||||||
}
|
}
|
||||||
readings[i] = reading; // fill the array with instantaneous readings from the scale
|
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user