Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e30a8293ac | ||
|
|
174f8b360f | ||
|
|
d0389af061 | ||
|
|
7c8a52cafe | ||
|
|
b71e0c0f0c | ||
|
|
d2e4b81416 |
+22
-9
@@ -677,7 +677,7 @@ void StartNewIteration() {
|
||||
// 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
|
||||
// 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);
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("startSendingUplink(), my_position: %d, iteration: %d, package_counter: %d\n", my_position, iteration, package_counter);
|
||||
@@ -697,8 +697,16 @@ void StartNewIteration() {
|
||||
}
|
||||
while (send_in_progress && ((millis() - start_time) < 300000))
|
||||
{
|
||||
gCatena.poll();
|
||||
yield();
|
||||
os_runloop_once();
|
||||
// gCatena.poll();
|
||||
// yield();
|
||||
}
|
||||
// handle timeout...
|
||||
if (send_in_progress) {
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("looks like we timed out waiting for sending to finish...\n", wait_time);
|
||||
}
|
||||
send_in_progress = false;
|
||||
}
|
||||
wait_time = (uint32_t)((millis() - start_time) / 1000);
|
||||
if (config_data.debug_level > 0) {
|
||||
@@ -783,6 +791,9 @@ void startSendingUplink(bool firstTime)
|
||||
fConfirmed = true;
|
||||
}
|
||||
|
||||
os_runloop_once();
|
||||
//gCatena.poll();
|
||||
|
||||
if (firstTime) {
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("SendBuffer firstTime\n");
|
||||
@@ -813,6 +824,7 @@ static void sendBufferDoneCb(
|
||||
pFn = settleDoneCb;
|
||||
if (! fStatus)
|
||||
{
|
||||
send_in_progress = false;
|
||||
if (!gLoRaWAN.IsProvisioned())
|
||||
{
|
||||
// we'll talk about it at the callback.
|
||||
@@ -948,8 +960,9 @@ void doSleepAlert(const bool fDeepSleep)
|
||||
|
||||
while (uint32_t(millis() - tNow) < 1000)
|
||||
{
|
||||
gCatena.poll();
|
||||
yield();
|
||||
os_runloop_once();
|
||||
//gCatena.poll();
|
||||
//yield();
|
||||
}
|
||||
if (config_data.debug_level > 2) {
|
||||
gCatena.SafePrintf(".");
|
||||
@@ -961,8 +974,9 @@ void doSleepAlert(const bool fDeepSleep)
|
||||
uint32_t tNow = millis();
|
||||
while (uint32_t(millis() - tNow) < 100)
|
||||
{
|
||||
gCatena.poll();
|
||||
yield();
|
||||
os_runloop_once();
|
||||
//gCatena.poll();
|
||||
//yield();
|
||||
}
|
||||
}
|
||||
else if (config_data.debug_level > 2) {
|
||||
@@ -1023,6 +1037,7 @@ void doDeepSleep(osjob_t *pJob)
|
||||
void deepSleepPrepare(void)
|
||||
{
|
||||
Serial.end();
|
||||
Wire.endTransmission(true);
|
||||
Wire.end();
|
||||
SPI.end();
|
||||
if (fFlash)
|
||||
@@ -1112,8 +1127,6 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
|
||||
float fval;
|
||||
} u;
|
||||
|
||||
SENSOR_data temp_sensor_data;
|
||||
|
||||
if (config_data.debug_level > 0) {
|
||||
gCatena.SafePrintf("receiveMessage was called!!!\n");
|
||||
}
|
||||
|
||||
+2
-2
@@ -56,7 +56,7 @@ enum {
|
||||
|
|
||||
\****************************************************************************/
|
||||
|
||||
static const int32_t fwVersion = 20200525;
|
||||
static const int32_t fwVersion = 20200529;
|
||||
|
||||
static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages;
|
||||
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_FIRST_PACKAGE = 128;
|
||||
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 byte INIT_PACKETS = 5;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ NAU7802 myScale; //Create instance of the NAU7802 class
|
||||
|
||||
byte debug_level;
|
||||
|
||||
byte interruptPin = A0;
|
||||
//byte interruptPin = A0;
|
||||
|
||||
void SetScalesDebugLevel(byte dbg_level)
|
||||
{
|
||||
@@ -24,7 +24,7 @@ void SetScalesDebugLevel(byte dbg_level)
|
||||
bool InitializeScales()
|
||||
{
|
||||
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.setIntPolarityHigh();
|
||||
@@ -47,7 +47,7 @@ bool SetupScales(byte dbg_level)
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("SetupScales start\n");
|
||||
}
|
||||
pinMode(interruptPin, INPUT);
|
||||
// pinMode(interruptPin, INPUT);
|
||||
|
||||
if (!myScale.begin(Wire, false))
|
||||
{
|
||||
@@ -96,9 +96,12 @@ long ReadScale(char channel)
|
||||
long readings[num_scale_readings]; // create arry to hold readings
|
||||
for (int i = 0; i < num_scale_readings; i++) {
|
||||
//while (digitalRead(interruptPin) == LOW) {
|
||||
long mytimer = millis();
|
||||
while (! myScale.available()) {
|
||||
// we set a timeout of 60 seconds for the measurement...
|
||||
if ((millis() - startTime) > 60000) {
|
||||
// we set a timeout of 10 seconds for the measurement...
|
||||
if ((millis() - mytimer) > 10000) {
|
||||
// Timeout reading scale...
|
||||
Wire.endTransmission(true);
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("Timeout while reading scale...\n");
|
||||
}
|
||||
@@ -106,11 +109,14 @@ long ReadScale(char channel)
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
long reading = myScale.getReading();
|
||||
long reading;
|
||||
if (myScale.available()) {
|
||||
reading = myScale.getReading();
|
||||
readings[i] = reading;
|
||||
}
|
||||
if (debug_level > 0) {
|
||||
gCatena.SafePrintf("Reading: %d\n", reading);
|
||||
}
|
||||
readings[i] = reading; // fill the array with instantaneous readings from the scale
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user