Author Topic: Any success with LoRa low-power listening..?  (Read 12580 times)

incognico

  • Newbie
  • *
  • Posts: 15
  • Country: au
Any success with LoRa low-power listening..?
« on: March 18, 2016, 12:42:46 AM »
Hi guys,

I have poked around a little but have not uncovered any code snippets for low-power listening on the LoRa devices. The "CAD mode" sounds promising too but I have not come across an example of that either.

Happy to explore this on my own, but if someone has gone before.... maybe they care to share their findings (or any links I've failed to stumble across)..?

--Nick

incognico

  • Newbie
  • *
  • Posts: 15
  • Country: au
Re: Any success with LoRa low-power listening..?
« Reply #1 on: March 18, 2016, 03:28:03 AM »
Had a quick play and it looks like CAD mode can be added easily enough -

After I added RHModeCad to the RHMode typedef enum (RHGenericDriver.h), and added a handler for the CadDone interrupt (RH_RF95::handleInterrupt(), RH_RF95.cpp), this seems to work -

Code: [Select]
void RH_RF95::setModeCad()
{
    if (_mode != RHModeCad)
    {
_mode = RHModeCad;
spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x80); // Interrupt on CadDone
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_CAD);
    }
}

Of course, you then need to check the CadDetected flag in the interrupt handler. It is a real shame that the CadDetected interrupt is only available on DIO1 or DIO4 (neither of which are connected on the MoteinoLR). I guess I will physically connect one of these to the AVR and see if that works as expected.

I hope this isn't something that is already well documented here, and I'm just not finding it....?!? :-[

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Any success with LoRa low-power listening..?
« Reply #2 on: March 18, 2016, 04:11:04 AM »
I hope this isn't something that is already well documented here, and I'm just not finding it....?!? :-[

I believe you're the first one to make any progress on it.   :)
« Last Edit: March 18, 2016, 04:13:06 AM by WhiteHare »

incognico

  • Newbie
  • *
  • Posts: 15
  • Country: au
Re: Any success with LoRa low-power listening..?
« Reply #3 on: March 20, 2016, 04:05:09 AM »
Cool, didn't want to think I was missing a whole LoRa Listen Mode sub forum or anything ;)

There seems to have been a fair number of people viewing this thread, so I will outline some of my initial findings here since others may be interested.

  • The RFM95 boasts a Top Level Sequencer to automatically do timed cyclic listening & address checking with external interrupt capability :)
  • This sequencer is not available in LoRa mode  :o
  • RSSI is not a practical indication of an incoming LoRa transmission, as LoRa can receive signals below the noise floor of the receiver ;D
  • There is built-in functionality to detect LoRa channel activity, called channel activity detection mode (CAD)
  • Activating CAD mode will trigger a hardware interrupt upon completion, and puts the LoRa modem back into standby/idle mode (note not sleep mode)
  • If the CAD process detects a LoRa preamble (activity) it also triggers a hardware CAD Detected interrupt
  • The CAD Complete hardware interrupt is connected to the AVR on the Moteino, however CAD Detected is not
  • The CAD process is fast and appears to be highly [power-consumption] optimized
  • Since the sequencer is not available, we need to trigger CAD mode from the microcontroller each cycle

In the absence of the sequencer, the uC needs to put the radio back into sleep mode after each CAD Complete interrupt. The overhead of checking the CAD Detected flag at this point seems like it may actually be quite low, so the non-connected CAD Detected hardware interrupt may not actually be a big deal. Wild guessing - measuring will tell the full story, of course. Later. For now on with the wild guessing!

I have been testing the following and it works just fine. Listening (ie CAD mode) every 500mS. The packet then needs to be read (and parsed for address matching unfortunately).

RH_RF95::cadDetected() was a quick addition to give me visibility into the CAD Detected interrupt flag, which I kept track of with an internal bool.

Code: [Select]
 while(!(rf95.cadDetected())) {

      rf95.sleep();
      LowPower.powerDown(SLEEP_500MS, ADC_OFF, BOD_OFF); // arbitrary sleep value for testing cyclic listen
      rf95.setModeCad();
      LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

      // CAD Complete interrupt will wake us

      // CAD Detected interrupt will drop us out of this loop

    }

    rf95.setModeRx(); // ok let's get the packet & check addressing

The oscilloscope is taunting me from across the bench but I will probably not get a change to have a play until later this coming week.

Anyway, hopefully this is interesting to at least one or two of you out there!  8)

joelucid

  • Hero Member
  • *****
  • Posts: 869
Re: Any success with LoRa low-power listening..?
« Reply #4 on: March 20, 2016, 12:25:09 PM »
Quote
This sequencer is not available in LoRa mode  :o

That's a shame. With your proposed solution you spend 4uA for the watchdog timer which is pretty prohibitive. Maybe you could use the top level sequencer to regularly wake the 328p up and then switch to LoRa and do CAD?

Sort of like this: https://lowpowerlab.com/forum/index.php/topic,1325.0.html?

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Any success with LoRa low-power listening..?
« Reply #5 on: March 20, 2016, 12:36:57 PM »
@incognico:  Excellent post.  Glad you have the gumption.  I definitely look forward to more.  This is definitely an area where even a single person can have a great impact on expanding the collective understanding.

For this type of LoRa listen mode to be attractive, a key question will be how long it takes for the CAD. With that information, and the current drain incurred during CAD (is it the same as during regular Rx?), and the current drain while sleeping (from the datasheet), one can start to estimate the average current drain, and hence battery life.

For comparison, on the RFM69, at 200Kbps, without much effort one can receive a packet with a listen window of less than 1ms or, alternately, detect a high RSSI (which could denote "an intent to transmit" in Joe's approach to Listen Mode) in even less time than that. The guiding principle is, of course, to spend the least amount of time drawing high currents and the most time possible in deep sleep, drawing nano currents.

For those reasons, I'm guessing you'll probably want to do at least your initial LoRa experimentation using the highest speeds that the LoRa will allow, which, IIRC, will be around 37Kbps.

There has been a significant collective learning curve on how to use the RFM69 efficiently (with more ways still being uncovered/discovered/developed).  Partly that's because the available documentation was mostly limited to a fairly dense, sometimes sketchy, datasheet that in many instances has required a lot of unpacking and interpretation and experimentation just to figure out what it even means.  I think there will likely be some kind of learning curve for the LoRa aspects of the RFM95, but straight out of the box the RFM95 does seem to come with more app notes and a somewhat better calculator.


incognico

  • Newbie
  • *
  • Posts: 15
  • Country: au
Re: Any success with LoRa low-power listening..?
« Reply #6 on: March 21, 2016, 03:34:06 AM »
Quick scope capture of the power draw:
  • AVR waking up
  • Set CAD Mode
  • AVR to sleep (SLEEP_FOREVER)
  • Wake on the CAD Complete interrupt
  • Put radio into Sleep mode

Measured at VIN to MoteinoLR, across 1R0 metal film resistor, 1%. (ie mV = mA, close enough). 4xAA power.

Radiohead_LowPowerLabs library with default speed settings ("Bw125Cr45Sf128", Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on).



So it looks like CAD's RX/listening process appears to take ~1.25mS @ 10mA, then ~0.5mS of processing time (@ 5mA) to look at the captured data.
Of course, there are also the spikes either end from the AVR having to wake up and talk to the radio - the "sequencer" would help a lot in minimizing these spikes.


Thanks very much for the comments/interest so far!
@WhiteHare: Hopefully this addresses a couple of the key outstanding "unknowns" you mention. Be good to see if/how this can be reduced with the faster data rates, but I think this default is a good place to start (fast = shorter range). Thanks I really appreciate your supportive comments.
@joelucid: I will have a play with the sequencer and try to capture some mode changes to see if this might be worth exploring - great suggestion thanks!

incognico

  • Newbie
  • *
  • Posts: 15
  • Country: au
Re: Any success with LoRa low-power listening..?
« Reply #7 on: March 21, 2016, 04:03:50 AM »
The same capture but with the radio using the standard "fast" RadioHead settings ("Bw500Cr45Sf128", Bw = 500 kHz, Cr = 4/5, Sf = 128 chips/symbol, CRC on)


WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Any success with LoRa low-power listening..?
« Reply #8 on: March 21, 2016, 12:50:01 PM »
I would guess the second plateau in your scope capture is the radio's idle current consumption while it waits for your AVR to wake up.

Also, IIRC, the default speed setting is medium speed.  So, though I'm speaking out of school, I'm guessing (?) the CAD will get shorter if you were to use the highest speed setting. 

So, all in all, it's a great beginning, and it looks very promising! I'm even more interested now than I was before.

----
[Edit:  Whoops!  Didn't notice the second scope capture until just now, so I'll have to eat my words: looks as though the second plateau really was "processing" rather than AVR wake-up.   Speaking of which, your AVR seems to wake up *very* quickly from a sleep_forever, if in fact it did go into a full powerdown sleep.  My Nick Gammon sleep code is nowhere near that fast.  Anyhow, the whole schebang in the second scope shot happens in about a millisecond, so this seems quite viable for fairly long-lived battery operation.

Nice work!]
« Last Edit: March 21, 2016, 01:46:24 PM by WhiteHare »

WhiteHare

  • Hero Member
  • *****
  • Posts: 1298
  • Country: us
Re: Any success with LoRa low-power listening..?
« Reply #9 on: March 21, 2016, 10:29:55 PM »
@incognico  Which AVR sleep library are you using?  I'd like to try it out and compare against the one that I've been using (which at 16mhz takes more than a millisecond to wakeup the atmega328p from powerdown sleep).

incognico

  • Newbie
  • *
  • Posts: 15
  • Country: au
Re: Any success with LoRa low-power listening..?
« Reply #10 on: March 21, 2016, 10:55:35 PM »
Ah yes, sorry - I should have mentioned that CAD Mode includes an Rx stage and a processing stage. Deep in the datasheet it explains:

"The receiver is in full receiver mode for just over half of the activity detection, followed by a reduced consumption processing phase where the consumption varies with LoRa bandwidth..."

Figure 12. Consumption Profile of the LoRa CAD Process



There is also a table of CAD consumption figures, which pleasingly appear to closely align with the values captured in my scope images.




@WhiteHare - I'm using the RocketScream library, https://github.com/rocketscream/Low-Power

dave_sausages

  • Newbie
  • *
  • Posts: 49
Re: Any success with LoRa low-power listening..?
« Reply #11 on: September 02, 2016, 11:39:29 PM »
Just wondering if the progress continued on this low power listen function? It could really help the LoRa modules pull ahead from the rest in terms and range and power consumption.

incognico

  • Newbie
  • *
  • Posts: 15
  • Country: au
Re: Any success with LoRa low-power listening..?
« Reply #12 on: September 07, 2016, 11:07:15 PM »
This thread got distracted by trying to wake up faster - the discussion was broken off into the shortest wakeup thread - https://lowpowerlab.com/forum/low-power-techniques/moteino-shortest-wakeup-time/

Personally, I have not looked into the LoRa low-power listening stuff any further. It is something I have to get back to, but have had other priorities unfortunately.

Post up anything you find and maybe spark up some more interest!  :)

stigso

  • Newbie
  • *
  • Posts: 1
  • Country: no
Re: Any success with LoRa low-power listening..?
« Reply #13 on: January 12, 2017, 12:16:51 PM »
Hi!

I've tried to make this work on an Arduino Miniwireless LORA, but no sucess so far. Is it possible to see your RH_RF95.cpp and RH_RF95.h?

My CadDetected never detects any high cad detected irq flag..


Russ Hedger

  • Newbie
  • *
  • Posts: 7
  • Country: gb
Re: Any success with LoRa low-power listening..?
« Reply #14 on: April 14, 2017, 06:31:32 AM »
There is support for Channel Activity Detection in the current Radiohead libraries for RFM95W. The function isChannelActive() places the module into CAD mode and returns true if activity is detected. Set the transmit preamble length to match the duration of the receiver sleep cycle. From my understanding of the datasheet, preamble length in symbols = cycletime * BW / 2^SF. So, for 1 second cycle at 500 kHz and SF7, preamble = 1 * 500000 / 128 = 3906 symbols.