Go Down

Topic: LoRaWAN event takes long to come (Read 96 times) previous topic - next topic

berkdo

Hi,
I am trying to implement a low power sensor node using an ATmega328p processor with Arduino bootloader. I call os_runloop_once in the loop once and acquiring the EV_TXCOMPLETE can take up to a few minutes, but usually around 20-30 seconds. Due to my application, I need to keep sensors on until I get the event and this violates my low power needs. Any help/idea is appreciated. Attached you can find my related code excerpt(of course not functional due to the deleted parts):

Code: [Select]

...
volatile boolean alarm = true;
...
void onEvent (ev_t ev) {
  if (ev == EV_TXCOMPLETE) {
    Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
    set_next_alarm();
    DS3231_clear_a2f();
    if(alarm == false){
    delay(100);
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  }
    // Schedule next transmission
    os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send);
  }
}

void do_send(osjob_t* j) {
  // Payload to send (uplink)
  alarm = false;
  digitalWrite(5, HIGH); // Turning on the mosfet the keep sensors alive
  ...
  ...
  uint8_t message[7];
  message [0] = temp >> 8;
  message [1] = temp;
  message [2] = econd >> 8;
  message [3] = econd;
  message [4] = pH;
  message [5] = random(0, 250);
  message [6] = random(0, 250);
  // Check if there is not a current TX/RX job running
  if (LMIC.opmode & OP_TXRXPEND) {
    Serial.println(F("OP_TXRXPEND, not sending"));
  } else {
    // Prepare upstream data transmission at the next possible time.
    LMIC_setTxData2(1, message, sizeof(message) - 1, 0);
    Serial.println(F("Sending uplink packet..."));
    digitalWrite(13, LOW);
  }
  // Next TX is scheduled after TX_COMPLETE event.
  digitalWrite(5, LOW); // shut the MOSFET
}

void setup() {
  pinMode(5, OUTPUT); // MOSFET Switch
  Serial.begin(115200);
  Serial.println(F("Starting..."));
  pinMode(ECPin, INPUT);
  pinMode(ECPower, OUTPUT); //Setting pin for sourcing current
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, CHANGE);

  Wire.begin();
  DS3231_init(DS3231_CONTROL_INTCN);
  DS3231_clear_a2f();
  set_next_alarm();
  sensors.begin();

  // LMIC init
  os_init();
  // Reset the MAC state. Session and pending data transfers will be discarded.
  LMIC_reset();
  // Set static session parameters.
  LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
  // Disable link check validation
  LMIC_setLinkCheckMode(0);
  // TTN uses SF9 for its RX2 window.
  LMIC.dn2Dr = DR_SF9;
  // Set data rate and transmit power for uplink (note: txpow seems to be ignored by the library)
  LMIC_setDrTxpow(DR_SF8, 14);
  // Start job
  do_send(&sendjob);
}
void loop() {
  if (alarm == true) {
    os_runloop_once();
  }
}
void handleInterrupt() {
  alarm = true;
}

jremington

Post ALL the code. The declarations, etc. are extremely important.

If all message bytes are important, I would suggest to send all of them.
Code: [Select]
    LMIC_setTxData2(1, message, sizeof(message) - 1, 0);

srnet

#2
Aug 23, 2019, 08:12 pm Last Edit: Aug 23, 2019, 08:14 pm by srnet
Due to my application, I need to keep sensors on until I get the event and this violates my low power needs. Any help/idea is appreciated.
The fragment of code you posted is just a small part of your code we presume, there is for instance no code in there that shows exactly how or when you are reading your sensors and we dont even know which sensors they are.

So yes you need to post all your code.

If you 'need' to keep the sensors powered it might also be useful to us to explain why.

Be aware that there fair access rules for TTN that limit you to 30seconds of air time per day and probably legal duty cycle limits restricting transmission to only 1% of the total time available. So sending data too often may not be possible.    
http://www.50dollarsat.info/
http://www.loratracker.uk/

Go Up