Author Topic: [Update] RFM69 Library for ESP8266 - Moteino Compatible!  (Read 52154 times)

fgomes

  • Jr. Member
  • **
  • Posts: 65
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #75 on: June 12, 2016, 05:00:51 AM »
It was a mix of problems, I'll post here hoping it might be useful to others. My first observation with the sniffer is that each node transmits always the three retries, and only the last one was acknowledged, this is why the sketch 'sort of' worked, using all the retries. The problem was introduced by some code I added during the previous debug phase (when i had communication problems with the RFM69 module), logging the messages to a server before sending the acknowledge. Now I make a copy of the received message, send the ack and only then process the message and I'm observing the ack delay at about 10ms. As Joe said, there is some 'jitter' in this reply time probably due to the other activities (WiFi and TCP stack) running on the ESP, in a quick tet I have observed from 7ms up to 14ms, something that with the ATMEGA328 as gateway was much more deterministic, but nevertheless is ok, since the default timeout is 40ms. This reply time only worried me because I have to keep the node awake until it receives the acknowledge, so more than 100ms was bad, now with about 10ms it is ok! Thanks again for your help!

Best regards

Fernando

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #76 on: June 12, 2016, 08:10:33 AM »
It's one of the RFM69's shortcomings that it doesn't have "automatic ACK" and automatic retry built into the radio hardware like some other radios do (e.g. NRF24L01+).  I'd expect the ESP32, which has dual cores for exactly the reason you've identified, will help reduce, and possibly eliminate, any significant jitter.  One core will supposedly handle wi-fi, leaving the other core free to work without interruption.  If anything, given it's high speed, it should ACK a bit faster than an atmega328p.  So, although it's not an immediately available upgrade solution, at least it's in the pipeline.

You can, of course, use a Moteino to handle the receiving and ACKing, and use the ESP8266 just purely as either a gateway or a pipe to a gateway, or even just to facilitate wireless OTA programming over a wireless IP connection from a PC (which is what I used it for):  https://lowpowerlab.com/forum/index.php/topic,1056.msg12478.html#msg12478  MSJFB made a really nice GUI utility for wireless OTA programming which makes doing that both easy and simple.
« Last Edit: June 12, 2016, 09:01:10 AM by WhiteHare »

someburner

  • NewMember
  • *
  • Posts: 13
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #77 on: June 27, 2016, 09:54:31 AM »
To me that sounds more like an issue of having blocking code inside of a time-sensitive routine (such as an ACK). An ESP32 might solve the problem, but only because the code would have to be built on the RTOS sdk  ;D

In my implementation, if I want to do any net-related operations as a result of an RFM message, I post to a different system task at a higher priority level, so it gets executed a bit later. The Arduino version has a main loop scheduler (which is a bit over my head admittedly), but it makes it trickier to guarantee timing. See https://github.com/esp8266/Arduino/blob/master/cores/esp8266/core_esp8266_main.cpp

So I think the best think to do would be to handle RFM69 stuff with blocking code, and only do the bare minimum (send an ACK, set flags, copy a buffer, and so on) and then later in the loop do Serial prints, network I/O, etc based on the flags and/or buffer you copied. So same principles as on an ATMega.

And if you aren't already, definitely try overclocking to 160MHz. This will not affect the SPI Clock or any timers.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #78 on: June 27, 2016, 07:48:03 PM »

And if you aren't already, definitely try overclocking to 160MHz. This will not affect the SPI Clock or any timers.

Any notable downsides to overclocking to 160Mhz?

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #79 on: June 27, 2016, 08:34:35 PM »
Any notable downsides to overclocking to 160Mhz?
Maybe there is a reason they use the term overclocking...
or, maybe not.

someburner

  • NewMember
  • *
  • Posts: 13
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #80 on: August 02, 2016, 12:02:27 AM »
A bit late to answering, but not that I know of or have seen.

I've been using the 160MHz option for nearly a year without any issues. The only drawback would obviously be heat and/or power consumption. But I haven't witnessed any overheating type issues. I would think that if they were worried about it they wouldn't have made the function so easily accessible through the SDK.

As a comparison- theoretically Moteinos running at 3.3v on an ATMega328 are all "overclocked". The graph provided by Atmel shows that 16MHz operation should be run at ~3.8V.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #81 on: August 02, 2016, 08:25:56 AM »
What are the benefits?  Does it associate or connect faster?  This would be useful if it connected significantly faster on power up.  In this case, the metric I'd be interested in would be the total power needed (mAH) to connect on power up at 80 vs 160MHz - not necessarily measured numbers but relative magnitudes (which is less power).

Tom

someburner

  • NewMember
  • *
  • Posts: 13
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #82 on: August 20, 2016, 05:10:58 PM »
Tom,

I haven't done any specific time measurements or power measurements, but anecdotally things definitely appear to run faster. Power consumption would be interesting, but for my application the ESP gateway is plugged in so I'm more concerned with performance. For me the only negative effect would be overheating which I have not witnessed. One of these days I'll do a more concrete test, maybe recording init times for 80 vs 160 just to see.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #83 on: August 20, 2016, 11:15:04 PM »
Tom,

I haven't done any specific time measurements or power measurements, but anecdotally things definitely appear to run faster. Power consumption would be interesting, but for my application the ESP gateway is plugged in so I'm more concerned with performance. For me the only negative effect would be overheating which I have not witnessed. One of these days I'll do a more concrete test, maybe recording init times for 80 vs 160 just to see.
I understand.  Reasonable position, but since I'm looking at the case where ESP would be a node periodically turned on to report findings, the 80 vs 160 power result would be very important.   Maybe I'll mess with this when I get some 'spare' time  ;)
We'll see who reports on this first...  :)

If ESP appears to run reliably at 160 then I can see why you'd run at that speed for a mains powered gateway, especially if it's an HTTP server.

Tom
« Last Edit: August 21, 2016, 08:19:18 AM by TomWS »

someburner

  • NewMember
  • *
  • Posts: 13
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #84 on: August 23, 2016, 11:47:42 PM »
Ah I think I see your dilemma now (and correct me if I'm wrong) - you're wondering if the increase in speed (and thus, perhaps, less on-time) might outweigh the negative of higher cpu power consumption?

I suppose if you're waking up really quickly and then going back to sleep right away, that could be the case. Also, it doesn't say anywhere that you can't call system_update_cpu_freq() again later to go back down to 80MHz.

I got a bit curious and did some googling and found this link:
http://www.espruino.com/EspruinoESP8266

Check out the bottom of the page. From there you just need to measure current for each I suppose. They say there power differences are "unconfirmed". I don't know if that means they tried or what, but interesting.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #85 on: August 24, 2016, 06:50:10 AM »
Ah I think I see your dilemma now (and correct me if I'm wrong) - you're wondering if the increase in speed (and thus, perhaps, less on-time) might outweigh the negative of higher cpu power consumption?
Exactly.  In my usage model, the shorter I can power up, reconnect to the AP, and send off my packet, the sooner I can return to a power off state.  I'll work on it this Fall and publish my results.  Right now I've got other work to attend to.

Thanks for the head's up on the API to change clock speed, that will be useful in the tests.

Tom

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #86 on: August 24, 2016, 11:55:35 PM »
FWIW, I've read (but haven't confirmed) that if you assign a static IP address to the esp8266, then the time required to establish a connection after waking up is reduced.

Xose

  • NewMember
  • *
  • Posts: 3
  • Country: es
    • Tinkerman
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #87 on: August 26, 2016, 09:34:58 AM »
It was a mix of problems, I'll post here hoping it might be useful to others. My first observation with the sniffer is that each node transmits always the three retries, and only the last one was acknowledged, this is why the sketch 'sort of' worked, using all the retries. The problem was introduced by some code I added during the previous debug phase (when i had communication problems with the RFM69 module), logging the messages to a server before sending the acknowledge. Now I make a copy of the received message, send the ack and only then process the message and I'm observing the ack delay at about 10ms. (...)

I also noted this problem but even after moving all the code I could after the sendACK I had timeout issues in the original sender. After some testing I found that changing the SPI clock divider to SPI_CLOCK_DIV2 (line 453 in RFM69.cpp) speeding it up 2 times issues completely disappeared and now my ESP8266-based gateway works just great.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #88 on: January 21, 2017, 09:51:07 PM »
I've found that a clean way to modify the rfm69.h file for the ESP8266 pin definitions is to couch it this way:

Code: [Select]
#elif defined(ESP8266)
  #define RF69_IRQ_PIN           D2  // needed for esp8266
  #define RF69_IRQ_NUM          D2  // needed for esp8266
  #define LED 2                              // LED on ESP12F is on GPIO2
« Last Edit: January 22, 2017, 07:57:47 AM by WhiteHare »

Fernando Garcia

  • NewMember
  • *
  • Posts: 6
Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
« Reply #89 on: February 21, 2017, 09:13:57 AM »
Hi!

There another pin on ESP8266 to be used as interrupt?

I'm asking because the GPIO4 is used for I2C and it is needed to a RTC.

Best regards.