LowPowerLab Forum

Hardware support => Projects => Topic started by: someburner on October 29, 2015, 01:06:31 PM

Title: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner on October 29, 2015, 01:06:31 PM
Hello all,

I'm working for an IoT startup that is currently prototyping with Moteinos. The idea is a home base unit + Moteino outside the home. Anyways, we needed a low-cost WiFi unit that would interface well with a Moteino. So I've spent quite some time working out most of the kinks and can proudly say that I have a fully functioning base unit! To my knowledge, everything works like a normal Moteino should, minus implementation (different function names and different way of calling them). And it is written in C. I tried using the ESP8266-Arduino library at first, but it was too messy trying to use that and Hardware SPI on the ESP8266 at the same time.

Originally I started out by using the esp-link project, but have mostly moved away from it and just use esphttpd and done some modifications to various libraries here and there.

One of the major things I got working was OTA firmware updating. Right now the process goes: you compile your FW, use a program to convert it to a .bin file, then upload it through the web console, which copies it to SPI flash. Then you hit begin and it begins the process. It may be a bit buggy because SPI flash must be written to/from in 32 bit chunks, and I haven't thoroughly tested it. Also, this has all been cropped out from the project I'm working on so there may be a few orphaned things in there that need to be cleaned up.

But anyways, feel free to check it out. Any and all feedback, comments, suggestions, bugs are appreciated! I'm fairly busy most of the time, but I should be able to help here and there if people have issues. If you are having general ESP8266 troubles you should first try checking out the esp-link project, as it is a similar project and has more information on how to compile stuff.

https://github.com/someburner/esp-rfm69

I've also included a basic .ino that is loaded on the Moteino and just sends a test message every 10 seconds or so. And below are the screenshots of what you should see outputted.

https://github.com/someburner/esp-rfm69/blob/master/doc/SendTest.ino

Screenshots: (Rssi value is like it is because I didn't have an antenna attached for this!)
(https://raw.githubusercontent.com/someburner/esp-rfm69/master/doc/screen1.jpg)

(https://raw.githubusercontent.com/someburner/esp-rfm69/master/doc/txrxex.jpg)

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner on March 09, 2016, 01:35:05 AM
Howdy,

Just wanted to share that I've done a pretty major overhaul and you can find it at the same place: https://github.com/someburner/esp-rfm69 (https://github.com/someburner/esp-rfm69)

Mainly I switched over to a nginx-based HTTP server and am now using SPIFFS for all the SPI Flash stuff. So now it's much easier to upload firmware (drag-and-drop). I pretty much re-wrote the driver as well, and it should be more stable.

I saw that Felix made a post about the ESP8266. While I agree that sub-1GHz is better for low-power and range, I think it's unfair to completely dismiss the device and I think it has great potential as a Gateway device.

So why ESP8266?

Well, it's a WiFi-ready chip, with 4MB SPI Flash for $2.

Besides price, IMO it's overkill to be using a Raspberry Pi as a gateway device. Not to mention a lot less portable. The ESP8266 supports OTA updating and the compiled binaries total to less than 1MB. In contrast, to set up a RPi you have to purchase one for a minimum of $15 (A+), format an SD card, add a WiFi dongle, install Linux, and whatever else I'm forgetting. And unless you need your gateway to have video output for some reason, an ESP8266 gateway serving a small web app is just as good.

The downside is having to code in C, or perhaps C++. But the project to add MicroPython support to the ESP8266 looks promising so that may not be the case for much longer.

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 09, 2016, 05:32:09 AM
Hey burner,

so this spiked my interest since I'm currently evaluating a esp8266 based gateway. I looked at your stuff and then - just to make sure I don't invest too much time in the native esp8266 route if an Arduino approach might work - I compiled RFM69.cpp as is for the esp8266.

I wired a rfm69hw to the esp HSPI port and DIO0 to D2. Then in RFM69.cpp:

Code: [Select]
#define RF69_IRQ_PIN          D2
#define RF69_IRQ_NUM          D2

In select() instead of MODE0 I used: 

Code: [Select]
SPI.setDataMode(SPI_MODE0);

And finally I thew out the SPI config caching in select and unselect.

To my absolute astonishment with these three changes it just worked. I have a gateway sketch running and it's perfectly showing incoming packets. With an RSSI much better than I ever got on the Pi. Even though this is all on a breadboard.

So I guess this raises the question why a native port?

Joe
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 09, 2016, 05:40:08 AM
(http://i.imgur.com/6G1TG9B.jpg)

Pretty amazing that this setup results in an RSSI at least 10 better than a Moteino mounted on a Pi2 right next to it.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: Felix on March 09, 2016, 08:06:21 AM
Pretty amazing that this setup results in an RSSI at least 10 better than a Moteino mounted on a Pi2 right next to it.
Nice, what is the RSSI? Are all other things equal for comparison sake?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 09, 2016, 08:26:38 AM
Quote
Nice, what is the RSSI? Are all other things equal for comparison sake?

From the bathroom moteino I get an RSSI of ~58 from the ESP8266 and ~65 at best from the Pi. Of course as you remember I have the periodic RSSI impairment problem, so around half of all packets are received at the Pi at an RSSI of >80.

Haven't done much testing yet though. But I'm excited that your lib runs unchanged. Amazing. With 4MB of flash and a rfm69hw added the ESP8266 should make for a great boot server.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: john4444 on March 09, 2016, 03:36:04 PM
Quote
I still don't know of an alternate hypothesis to explain why RSSI would appear as less on the Pi, unless the Pi is somehow adversely changing something ...
The PI generates a lot of noise on the +5v/ground lines as well as emitted RF.
The effect of that noise is that the received RSSI levels appear weaker.
However, this effect is entirely due to the higher noise-floor at the receiver, not the actual transmitted signal level.

BTW the latest RasPi, model 3 has much less "noise" than earlier models.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: Felix on March 09, 2016, 04:35:24 PM
WHere did you order your Pi3 from?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner on March 10, 2016, 12:59:47 AM

So I guess this raises the question why a native port?


Good to know that it works natively with the Arduino port now!

As to your question, I am working towards designing a consumer product so reliability is important. The Arduino port code base is pretty large and it's easier to debug my own code that has the bare minimum of things my project requires. Besides that:

1. When I first got going with the ESP8266 the Arduino SPI libraries were pretty much non-existent so I didn't have a choice initially
2. Because of #1, I'm now very familiar with the Native SDK, so I can easily make any sort of customization and not have to worry about breaking Arduino code, or vice-vera.
3. I still don't trust the Arduino port with regards to handling interrupts, or long-term stability.
4. Overhead. I'm curious how much Arduino really adds, but since I've already written it in C I don't see the benefit of switching.
5. Code portability. ESP32 is on the way or I may switch to a different platform entirely.
6. Just the overall idea of using a setup(), and loop() running over an SDK that actually executes like an RTOS with callbacks seems counter intuitive to me.

To expand on #6, that is also why you can see I've implemented the driver more like a state machine. The original RFM69 driver has a number of blocking while loops which are dangerous to use with the ESP8266. A simple use case with a few send and receives here and there works fine, as you know. But try doing an OTA update or something with a high volume of packets and that will crash and burn. On the flip side, the ESP8266 is much faster than a Moteino, running at 80 MHz, so writing the driver in a way that 'makes sense' for the ESP8266's OS can give us a considerable performance boost.

With that said, I'll definitely consider switching over to Micropython when a stable port becomes available.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on March 10, 2016, 09:30:34 AM

In select() instead of MODE0 I used: 

Code: [Select]
SPI.setDataMode(SPI_MODE0);

"SPI.setDataMode(SPI_MODE0);" is the code that's already there.  Did you mean SPI_MODE1?  I have confirmed (https://github.com/esp8266/Arduino/blob/master/libraries/SPI/SPI.h) that:
Code: [Select]
const uint8_t SPI_MODE0 = 0x00; ///<  CPOL: 0  CPHA: 0
const uint8_t SPI_MODE1 = 0x01; ///<  CPOL: 0  CPHA: 1
const uint8_t SPI_MODE2 = 0x10; ///<  CPOL: 1  CPHA: 0
const uint8_t SPI_MODE3 = 0x11; ///<  CPOL: 1  CPHA: 1

That is the same as Table 19-2 (SPI Modes) in the atmega328p datasheet. However, the SX1231H datasheet (page 44) says, "The SPI interface gives access to the configuration register via a synchronous full-duplex protocol corresponding to CPOL = 0 and CPHA = 0 in Motorola/Freescale nomenclature. "  Therefore, isn't the existing SPI_MODE0 parameter used in SetDataMode already correct?




And finally I thew out the SPI config caching in select and unselect.


By that, do you mean deleting
Code: [Select]
  _SPCR = SPCR;
  _SPSR = SPSR;
from select(), and deleting
Code: [Select]
  SPCR = _SPCR;
  SPSR = _SPSR;
from unselect()?  I guess those were there to handle interrupt contention between the RFM69 and the SPI flash memory, which no longer exists.

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: john4444 on March 10, 2016, 12:00:57 PM
Quote
WHere did you order your Pi3 from?
Adafruit
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: Felix on March 10, 2016, 12:04:11 PM
Yup, I was looking to get one too but I was too late, out of stock now.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: jra on March 10, 2016, 03:51:15 PM
This seems to happen every time a new Pi flavor comes out.  Adafruit, Element14 and the usual suspects have them for $35, they sell out in 4 hours, someone starts selling the few they managed to scarf up for $60 on Amazon and everyone gives it a 1 star review because of the price.  While waiting a month or so for stock to be replenished there will be a flurry of articles stating that Odroid or Orange or Banana or Beagle has a better/faster/cheaper solution.  Attaching an RFM69 directly to a ESP8266 opens up a whole range of intriguing inexpensive possibilities independent of the better noise immunity.  If Joe's patch makes it into github my one request would be to #if defined(ESP8266) the patch so the same code can be compiled on ATmega328 and ATmega1284 as well.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 10, 2016, 05:18:54 PM
Quote
Attaching an RFM69 directly to a ESP8266 opens up a whole range of intriguing inexpensive possibilities independent of the better noise immunity.

I'm still working on getting comfortable with the ESP8266. The documentation is just so horrible if you're used to normal datasheets and it feels a bit like a waste of time to search around for basic info that could easily been written up in a decent datasheet.

On the other hand I completely agree cutting out the 328p is not only intriguingly inexpensive but also so much simpler. I have a whole encoding scheme to ensure failsafe and recoverable serial communication between Pi and 328p without ack latency. As soon as you speak SPI that just goes completely away.

And having a reasonably powered mcu as gateway gives you the flexibility to really get creative on the network protocol side. I mean just think about it: 255 nodes and 2048 byte RAM. That gives you 8 byte per node. Not much if you want negotiated bitrates, rx time windows etc. And doing it on the Pi creates all kinds of timing issues.

Definitely worth a bit more experimenting.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 11, 2016, 06:12:07 AM
Quote
"SPI.setDataMode(SPI_MODE0);" is the code that's already there

True, just verified the diff. Sorry I can't remember what bit me there.

Quote
By that, do you mean deleting
Code: [Select]
  _SPCR = SPCR;
  _SPSR = SPSR;
from select(), and deleting
Code: [Select]
  SPCR = _SPCR;
  SPSR = _SPSR;
from unselect()?  I guess those were there to handle interrupt contention between the RFM69 and the SPI flash memory, which no longer exists.

Yes.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: jra on March 11, 2016, 12:10:02 PM
@joelucid it's not just the documentation, using the SDK itself can be a bit, um, challenging. One can only hope that Espressif applies some of the lessons learned with the ESP8266 to the ESP32 whenever it goes to production.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 12, 2016, 05:58:36 AM
Yeah - it does have its challenges. It took some time to even find a way to reliably flash from the mac. Any bitrate higher than 115200 often ended in corrupted flash - without error message of course, it just wouldn't boot. And the Arduino IDE was dog slow and insisted on essentially always rebuilding everything.

I now build using make with makeEspArduino.mk and deploy with espota.py and this seems to be a pretty reasonable setup. Compiles are very fast. Uploads take around 15-20s giving me bearable turnaround times.

The radio code works fine and I now also have my bootserver code partially ported. Takes under a second to push a binary 328p image to the bootserver via curl/wifi and less than 2s to transfer a 18k image to a Moteino. Not too bad.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: executivul on March 12, 2016, 06:13:10 AM
So we can now see some of your bootloader code joe? (I keep bugging you, sorry about that, but you asked for it ;) )
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 12, 2016, 06:16:04 AM
Quote
So we can now see some of your bootloader code joe? (I keep bugging you, sorry about that, but you asked for it ;) )

While I'm working on it no need to bug me  ;)
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: executivul on March 12, 2016, 06:21:31 AM
Ssshhh I keep quiet than :P
My ESP8266 is still on the airplane from China, hope to be here in time.
Good luck with the coding!
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: jra on March 12, 2016, 09:01:18 AM
+1 using makeEspArduino.mk instead of the Arduino IDE, there is also https://github.com/sudar/Arduino-Makefile.git for AVR-based boards.  I made two small local changes to make my life a lot easier (on linux, might work on OSX, don't know about Windows).  First I removed the hardwired ck upload option and made it a variable so the makefile works with a variety of boards

Code: [Select]
#
# UPLOAD_BOARD choices are none|ck|wifio|nodemcu
#
UPLOAD_BOARD ?= ck
...
upload: all
        $(ESP_TOOL) $(UPLOAD_VERB) -cd $(UPLOAD_BOARD) -cb $(UPLOAD_SPEED) -cp $(UPLOAD_PORT) -ca 0x00000 -cf $(MAIN_EXE)

Second is I determine the appropriate USB port dynamically:

Code: [Select]
UPLOAD_PORT ?= $(shell lastusb)

Here is the lastusb script.  This is the part that is linux specific for now:

Code: [Select]
#!/bin/bash
ls -1tr /dev/ttyUSB* | tail -1

I tend to have lots of Moteinos, Arduinos, ESP8266's and STM32's all plugged in at once.  Keeping track of which was associated with which USB port was a real headache until Steve Childress pointed me to a powered USB hub with switchable ports.  This is the one I've been using, I'm sure there are others that work just as well http://www.amazon.com/gp/product/B007WTHGL8 . When you want to upload to a particular device just toggle the associated switch, wait a couple of seconds for udev to do its thing and run "make upload" to upload to the most recently power cycled device.  One of the biggest timesavers I've found.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: TomWS on March 12, 2016, 11:01:14 AM
Keeping track of which was associated with which USB port was a real headache until Steve Childress pointed me to a powered USB hub with switchable ports.  This is the one I've been using, I'm sure there are others that work just as well http://www.amazon.com/gp/product/B007WTHGL8 . When you want to upload to a particular device just toggle the associated switch, wait a couple of seconds for udev to do its thing and run "make upload" to upload to the most recently power cycled device.  One of the biggest timesavers I've found.
Whoa! That's a cool thing!  Thanks for posting!
Tom
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: jra on March 12, 2016, 11:29:49 AM
Forgot to mention that if you are using a Moteino or other Arduino with built-in USB that implements a modem interface the following should work with those devices as well:

Code: [Select]
#!/bin/bash
ls -1tr /dev/tty{ACM,USB}* 2>/dev/null | tail -1
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner on March 12, 2016, 05:38:30 PM
On the note of multiple FTDI devices, I generally have an ESP8266 and Moteino hooked up at the same time. I made some documentation for symbolically linking a given FTDI adapter to a chosen name in Linux. So whenever I use /dev/ftdi_esp or /dev/ftdi_uno it always goes to the right spot regardless of what port its on. This is good if you have 2+ FTDI devices and can dedicate each to a certain type of device.

Also if you're on Linux I highly recommend using Atom and installing the platformio addon. Build and upload to an attached Moteino is as easy as Cmd+Shift+B and Cmd+Shift+U

Also if people are looking for more resources for an Esp8266 Arduino programmer, check out the Esp-link project. https://github.com/jeelabs/esp-link
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: TomWS on March 12, 2016, 10:05:28 PM
Forgot to mention that if you are using a Moteino or other Arduino with built-in USB that implements a modem interface the following should work with those devices as well:

Code: [Select]
#!/bin/bash
ls -1tr /dev/tty{ACM,USB}* 2>/dev/null | tail -1
I tried that on my Windows 7 system and all it said was "Huh?".  ;)
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on March 12, 2016, 10:59:44 PM

Also if you're on Linux I highly recommend using Atom....


Are you referring to Atom the text editor (https://atom.io/ )?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 13, 2016, 01:46:42 AM
Quote
Also if people are looking for more resources for an Esp8266 Arduino programmer, check out the Esp-link project. https://github.com/jeelabs/esp-link

Thanks for the link, that's an interesting project.

Quote
. I made some documentation for symbolically linking a given FTDI adapter to a chosen name in Linux. So whenever I use /dev/ftdi_esp or /dev/ftdi_uno it always goes to the right spot regardless of what port its on. This is good if you have 2+ FTDI devices and can dedicate each to a certain type of device.

On the Mac you can configure the FTDI driver to use fixed names as well as alias lower bitrates to higher ones. I use this (https://spin.atomicobject.com/2013/06/23/baud-rates-ftdi-driver-mac/) to alias 300baud to 1Mbaud and it works ok. In general though the ftdi driver is pretty unstable on the Mac.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on March 13, 2016, 01:48:45 AM
Quote
Also if you're on Linux I highly recommend using Atom and installing the platformio addon. Build and upload to an attached Moteino is as easy as Cmd+Shift+B and Cmd+Shift+U

I never feel quite at home until I can compile from emacs using a makefile. All that muscle memory at work  ;)
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner on March 15, 2016, 06:33:04 PM
Are you referring to Atom the text editor (https://atom.io/ )?

Yup! The plugins are awesome. Mainly the platformio integration I mentioned and the built-in git integration. If your project uses git it highlights which files have been modified since the last commit. There's also shortcuts for all the git commands but I prefer to take care of that stuff in terminal. For web stuff I still prefer Brackets.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: thebillplease on March 25, 2016, 04:00:43 PM
@joelucid, this is awesome! I've been looking for this all over! Do you happen to have the sketches you used to make it work? Any help is much appreciated it.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on April 07, 2016, 11:40:27 AM
For those who aren't yet aware of it, you can update your ESP8266 "arduino" sketches OTA directly from the Arduino IDE.  Instead of specifying a serial link in the port selector, I simply pick which ESP8266 I want to upload to and then specify "Upload using: OTA" in the sketch Tools menu.  Pretty cool.    Once set, I don't even need to think about it anymore, and it just happens automatically thereafter on each compile+upload iteration.  :)

[Edit:  Note that to make this work, you need to include some boilerplate code in your sketches.  If you're running the current IDE, you already have an OTA sketch as one of the built-in examples.  Here's a link that explains how to get started with it:  http://esp8266.github.io/Arduino/versions/2.0.0/doc/ota_updates/ota_updates.html]
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on April 09, 2016, 09:24:46 AM

I wired a rfm69hw to the esp HSPI port and DIO0 to D2.

By that, do you mean the following?
pin  function
== ======
12. SPI_MISO
13. SPI_MOSI
14. SPI_CLK
15. SPI_SS

However, did you have to do something to activate the SPI functionality of the HSPI pins?  Are you doing
pinMode(12, SPECIAL);
pinMode(13, SPECIAL);
pinMode(14, SPECIAL);
pinMode(15, SPECIAL);
or something else?

It looks as though someburner connected DIO0 to GPIO5.  I think I may try doing the same, with the hope of leaving GPIO2 as a secondary serial Tx in case it's beneficial to have for debugging.

Someburner's approach was quite sophisticated (amazing work!), and one of the benefits of that was the OTA updating.  However, I'm hoping the OTA that one can get for little effort within the Arduino framework (see post immediately above) will do the job, especially since it's already so well integrated with the Arduino IDE.  So, at the moment I'm trying to mash the ESP8266 Arduino OTA with the Arduino LPL  RFM69 library, with the hope that the two will dance together without stepping on each other's toes.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on April 09, 2016, 12:36:10 PM
I wired it up with the above using the RFM69 example node code, but although the ArduinoOTA part appears as though it may be working, it's getting stuck in the RFM69 part.  After a while, the WDT times out, causing a reboot loop:

Code: [Select]
Ready
IP address: 192.168.3.244

Transmitting at 915 Mhz...

Sending[1]: 1
Soft WDT reset

ctx: cont
sp: 3ffeff50 end: 3fff0210 offset: 01b0

>>>stack>>>
3fff0100:  00000001 3ffef038 3ffeeebc 00000001 
3fff0110:  00000027 3ffef038 3ffeeebc 402052cd 
3fff0120:  00000000 3ffeeebc 00000001 402054af 
3fff0130:  3ffe8370 00000001 3ffeeebc 402058f0 
3fff0140:  0000003d 00000001 3ffeeebc 000003e7 
3fff0150:  3ffe8370 00000001 3ffeeebc 40205b85 
3fff0160:  00000546 00000001 00000001 402076b0 
3fff0170:  00000009 40105c5f 3ffef1f0 00000001 
3fff0180:  00000001 3ffeeebc 00000000 4020521f 
3fff0190:  3ffe8370 00000001 00000002 00000028 
3fff01a0:  3ffeeed4 3ffeeebc 3ffef120 00000001 
3fff01b0:  3ffeeec8 3ffeeebc 3ffef120 40202984 
3fff01c0:  3ffe8370 7a684d20 002e2e2e feefeffe 
3fff01d0:  feefeffe feefeffe feefeffe 3ffef1dc 
3fff01e0:  3fffdad0 00000000 3ffef1d5 402029d7 
3fff01f0:  3fffdad0 00000000 3ffef1d5 40206cb4 
3fff0200:  feefeffe feefeffe 3ffef1f0 40100958 
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld
Booting
Ready
IP address: 192.168.3.244

Transmitting at 915 Mhz...

Sending[1]: 1
Soft WDT reset

Maybe I'm missing a pull-up or a pull-down resistor somewhere...?

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on April 09, 2016, 01:16:06 PM
Quote
12. SPI_MISO
13. SPI_MOSI
14. SPI_CLK
15. SPI_SS

You've got to use the HSPI port. It's D5-D8 on NodeMCU 1.0.

Other than that I'm not doing anything special. I initialize the SPI bus with

Code: [Select]
  SPI.begin();
  SPI.setDataMode( SPI_MODE0);
  SPI.setBitOrder( MSBFIRST );
  SPI.setClockDivider( SPI_CLOCK_DIV2 );

But that's it. Works amazingly well.


Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on April 25, 2016, 03:39:58 AM

I wired a rfm69hw to the esp HSPI port and DIO0 to D2. Then in RFM69.cpp:

Code: [Select]
#define RF69_IRQ_PIN          D2
#define RF69_IRQ_NUM          D2


I tried  connecting an RFM69 to an esp8266 nodemcu version 1, and although I can talk over the SPI just fine with the RFM69, DIO0 doesn't seem to be triggering any interrupts, despite the above settings using #define.  The D2 silkscreened onto the nodemcu corresponds to the GPIO4 pin on the esp8266.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on April 25, 2016, 05:02:41 AM
Quote
I tried  connecting an RFM69 to an esp8266 nodemcu version 1, and although I can talk over the SPI just fine with the RFM69, DIO0 doesn't seem to be triggering any interrupts, despite the above settings using #define.  The D2 silkscreened onto the nodemcu corresponds to the GPIO4 pin on the esp8266.

Can you try just reading dio0 with a digitalRead() to see if the mapping works? This works fine for me so I guess it's probably the wrong pin? Maybe wrong variant?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on April 25, 2016, 03:23:51 PM
Fixed it.  It turned out to be a configuration error on my part.

I have it working on three different platforms: an  ESP13, a WeMos, and now a NodeMCU v1.0.

I like a lot of things about the WeMos. However, even without an RFM69HW, I had doubts as to whether its tiny voltage regulator was truly adequate for supplying the currents needed by the ESP8266, and adding the RFM69HW seemed to push it over the edge to failure.  So I replaced its voltage regulator with an LD1117-3.3 that I had laying around, and now it seems solid.

[Edit: "Witty Cloud," which is yet another platform, comes with a much beefier voltage regulator than the WeMos, and so it may be worth considering as well.   ]

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on April 26, 2016, 08:34:30 PM
I hooked up an RFM69HW to an ESP8266 "witty cloud" today.  Now that I've got four different platforms working, I can see a definite pattern to most of them: they receive great, but they transmit horribly.  Most of the Tx power just doesn't seem to get converted to RF.  It's the classic case of "If I touch the antenna, then the Rx transmission improves tremendously."  I know that because I can see it on an RTL-SDR running C#.  I'm guessing it's the near lack of ground plane that's to blame, so I'm going to add that and see if it fixes it.  Still, even though these are just some lash-ups, I didn't have this problem when I  similarly lashed-up RFM69HW's with Pro Mini's during prior experimentation, so I'm puzzled as to why now if not before.   :o
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on April 27, 2016, 07:17:26 AM
Finally, success with this issue.  Just now I wired up an Adafruit ESP8266 Huzzah to an RFM69HW, but this time I also attached a small ground plane--not much bigger than the RFM69HW itself--to the RFM69HW.  Bingo.  Now the Huzzah-RFM69HW both Rx's and Tx's beautifully.

If time allows I'll make and test a dipole antenna on the RFM69HW  and see how that compares.  Assuming I've read John K2ox's postings correctly, it should perform even better.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on May 12, 2016, 12:24:29 AM
Attached is a photo of a dipole version of an esp8266-RFM69HW gateway that I threw together today.  Center frequency ist 915Mhz.  I made both the antenna (white) and the ground wire (black) of the dipole be 5/8 wavelength long.  This was my first attempt at a dipole.  From a quick, very preliminary comparison of RSSI numbers, it appears to perform  significantly better (head and shoulders better) than any  monopole RFM69HW system that I've thus far tried. 

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 12, 2016, 08:25:21 AM
Quote
From a quick, very preliminary comparison of RSSI numbers, it appears to perform  significantly better (head and shoulders better) than any  monopole RFM69HW system that I've thus far tried. 

Cool! A word of caution though: I've done a lot of testing using RSSI measurements (both signal and noise floor). Today I ran a battery of tests measuring actual rx success rates. Let's just say one isn't a good substitute for the other:

For example I measured a noise floor a bit higher with my gw on an iPhone power supply than with batteries. Turns out rx success rates are about identical, but with the iPhone power supply I measure a higher RSSI of packets sent with the same TX power. So the gw on a iPhone power supply will generally just measure higher RSSI.

Overall I'm pretty happy though: The espgw running from iPhone supply does not affect rx success. With a stock moteino you need to increase TX power by >10dBm to get the same success rate as with batteries when running from iPhone supply.

 
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 12, 2016, 08:29:00 AM
Quote
I made both the antenna (white) and the ground wire (black) of the dipole be 5/8 wavelength long.

Why?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on May 12, 2016, 11:04:06 AM
Quote
I made both the antenna (white) and the ground wire (black) of the dipole be 5/8 wavelength long.

Why?
Uh, because any longer and it would wobble too much and maybe fall over under its own weight?   ;)   

More seriously, though, when it comes to whip antennas, I do get the impression that theory quickly takes a back seat to simply trying all the possibilities.    It's easy enough to simply measure, then reduce the antenna length with a snip and measure again.  Repeat until done.  In fact, I was reading some Nordic Semiconductor material regarding trace antenna design that more or less prescribed exactly that as its official way to "tune" an antenna.  It even suggested starting 30% longer than you might think you'll need and then iteratively cutting back from there.



Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 14, 2016, 12:40:07 PM
Quote
From a quick, very preliminary comparison of RSSI numbers, it appears to perform  significantly better (head and shoulders better) than any  monopole RFM69HW system that I've thus far tried. 

I tested an espgw against a moteino today (300kbit, measurement is TX dBm required for lossless transmission). With the typical attached monopole they performed identically when the Moteino was on battery. Moteino on iPhone power supply caused a degradation again which wasn't seen with the espgw.

But now and confirming your results: using a lamda/2 dipole improved sensitivity by 16dBm. Not too shabby. I doubt it's the dipole vs monopole. It's probably the inadequate ground plane which causes these issues. In theory a monopole should perform even better since it doesn't radiate into the floor.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 14, 2016, 01:04:51 PM
Quote
It even suggested starting 30% longer than you might think you'll need and then iteratively cutting back from there.

I've definitely found longer antennas necessary in particular for my smaller motes. I'm using about 22cm for Tino and TH motes.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on May 14, 2016, 01:17:23 PM
Quote
From a quick, very preliminary comparison of RSSI numbers, it appears to perform  significantly better (head and shoulders better) than any  monopole RFM69HW system that I've thus far tried. 

But now and confirming your results: using a lamda/2 dipole improved sensitivity by 16dBm.

I'm really glad you did an independent measurement. That's about what I'm seeing as well.  "Not too shabby," really understates it.  It was such a vast improvement that I had trouble believing it.

The attached photo shows a different, more compact monopole configuration.  I load the ESP8266 with software and do a simple standalone test before attaching the radio board, so in theory I don't need the FTDI header afterward (or I could just relocate it further underneath), which could make it even more compact.

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 14, 2016, 01:39:07 PM
Quote
It was such a vast improvement that I had trouble believing it.

AC powered Moteino vs espgw on dipole I measure a difference of 24dBm!!!

Of course at some point you realize that the moteino just has a very much preferred rx direction. When pointing the ftdi header into the direction of the sender the difference melts down to 3-4dBm. That's a difference of 19dBm for a 180 degrees turn on a plane that supposedly does not affect gain. Pretty stunning ...

Black magic as they say.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 15, 2016, 07:55:28 AM
Given these results: Has anybody tried pcb-etched dipoles yet? Any monopole with a ground plane worth its name will be huge. But I could imagine a 25mm * 180mm PCB containing esp12e, rfm69hw and the 866mhz dipole antenna being pretty useful and living room compatible.

Maybe it could directly plug into a AC outlet - though that's probably asking for EMI again. Or you connect a usb power supply and mount it on a wall.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on May 15, 2016, 08:23:32 PM
More good news:  apparently there's a theory which says that a 1/2 lambda dipole (with each leg being 1/4 lambda) is the most efficient:

So, if that bears out, it will be easier to manage, and perhaps we'll see even more improvement.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 16, 2016, 02:48:28 AM
Mine is lambda/2. And yes, that's why I asked about your choice of 2 x 5/8 lambda. I haven't tried other lengths yet.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 16, 2016, 03:17:23 AM
Quote
It's probably the inadequate ground plane which causes these issues. In theory a monopole should perform even better since it doesn't radiate into the floor.

https://www.researchgate.net/profile/Hao_Ling/publication/4198932_Ground_plane_size_reduction_in_monopole_antennas_for_ground_wave_transmission/links/02e7e51f91fbf1fe93000000.pdf

Interesting paper on the impact of a reduced ground plane.

Quote
It is well known that most monopole antennas need a ground plane with a diameter on the order of λ/2 to perform well [2]. The transmission loss increases rapidly if the diameter of the ground plane is reduced to below λ/10.

There is a nice graph showing transmission loss vs ground plane size at the end. Based on this the 16dBm improvement I've seen from a dipole over a Moteino is entirely plausible.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on May 16, 2016, 11:29:49 AM
Quote
It's probably the inadequate ground plane which causes these issues. In theory a monopole should perform even better since it doesn't radiate into the floor.

https://www.researchgate.net/profile/Hao_Ling/publication/4198932_Ground_plane_size_reduction_in_monopole_antennas_for_ground_wave_transmission/links/02e7e51f91fbf1fe93000000.pdf

Interesting paper on the impact of a reduced ground plane.

Quote
It is well known that most monopole antennas need a ground plane with a diameter on the order of λ/2 to perform well [2]. The transmission loss increases rapidly if the diameter of the ground plane is reduced to below λ/10.

There is a nice graph showing transmission loss vs ground plane size at the end. Based on this the 16dBm improvement I've seen from a dipole over a Moteino is entirely plausible.

Yup.

Quote
It is well known that most monopole antennas need a ground plane with a
diameter on the order of λ/2 to perform well.

I have seen on some home automation forums where some people do use a monopole with a large ground plane, but they hang it upside down from their attic rafters in order to maximize the antenna gain into the house. 
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on May 16, 2016, 03:56:51 PM
Quote
I have seen on some home automation forums where some people do use a monopole with a large ground plane, but they hang it upside down from their attic rafters in order to maximize the antenna gain into the house.

That sounds like a very sensible approach. Unfortunately also one you can't probably convince the general public to take. Although a wireless gw might help. The monopole has a null straight up - or down in this case. But reflections would likely fix that.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on May 31, 2016, 06:57:08 PM
Hi joelucid, WhiteHare,

I'm trying to use NodeMCU with RFM69HW and even the initialization seems to fail, I've just introduced some debug after writing the RFM69 registers (RFM69::initialize) and I'm reading all zeros. I've started making only the changes you suggested, then added also this:

  pinMode(12, FUNCTION_2); //MISO
  pinMode(13, FUNCTION_2); //MOSI
  pinMode(14, FUNCTION_2); //SCLK

but still get the same results. Also tried with the SPI clock divider at SPI_CLOCK_DIV2 and SPI_CLOCK_DIV4, but had the same results,

Do you have any tip? Or can you share the code you are using in order to verify my hardware setup? The RFM69HW module works when connected to an ATMEGA328 MCU. It is currently being powered by the 3.3V output on the NodeMCU.

The connections used are the following (no other connections are made to any of the modules except the USB able to the NodeMCU):

Node ESP            RFM69HW
D2     GPIO04     DIO0 (interrupt)
D5     GPIO14     SCK (spi clock)
D6     GPIO12     MISO (spi miso)
D7     GPIO13     MOSI (spi mosi)
D8     GPIO15     NSS (spi ss)
+3V                    3.3V
G                        GND

Thanks in advance

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on June 01, 2016, 03:00:52 AM
Fernando,

it looks to me like you've done everything correctly. RFM69::initialize waits for the radio to become available by writing some registers and checking if it sticks. If initialize returns RFM69 was successful to write these registers. You'd want to have any code that checks for the same thing after the code that waits for the radio to become available.

If write/read never works it could be that you're not using the correct slave select pin in RFM69::select. If you are I'd probably just try to scope out the MISO/MOSI/SCLK/SS pins to see if everything is connected correctly electrically.

Joe
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 01, 2016, 06:03:59 AM
HI Joe, thanks for your feedback. The example doesn't test the return code from the  initialize function, it returns always false. I'll test it later with an oscilloscope,  to check MOSI. MISO, CLK and SS, and will post here my feedback.

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on June 01, 2016, 12:41:32 PM
Not sure if it applies to your situation, but I've found that very often mysterious failures disappear if you use an alternate 3.3v power source that you can be certain is capable of delivering ample current on demand, and then run wire from that directly to the points of large current consumption (of which the RFM69HW would certainly be one) rather than rely on just traces.  I'd start with that, at least until after you get it working. 

[Edit: Having said that, though, I don't believe I needed to do so on an "official" NodeMCU, which comes with an AMS1117-3.3V converter.  If you're driving that from a good enough 5v USB source (say, a 500ma capable one, which is fairly typical), that should be sufficient, and IIRC it worked OK for me without needing an auxillary power source.  I tried a number of the different off-the-shelf ESP8266 platforms, and I do recollect that not all of them came equipped with enough power to handle the current requirements of both the ESP8266 and the RFM69HW.  For instance, at least in my case, the WeMo D1 Mini couldn't supply enough juice on its own.]
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 01, 2016, 08:14:11 PM
Hi, thanks for your replies! I was checking with an oscilloscope but didn't find many differences from the library running on an ATMEGA328. What I found is that MISO has no activity on the ESP8266, so it seems that the RFM69 never noticed it was addressed, and never reply, but the other signals seems similar to the ATMEGA (in the SDS00001 image the yellow line is the MOSI for the ESP8266, in the SDS00011 is for the ATMEGA). The main difference is that with the ESP8266 there is an extra lag between the SS fall and the clock start (about 1,5us) , with the ATMEGA it is almost immediate (not mensurable in the same scale) - in SDS00007 image the yellow line is the SS of the ESP8266, in the SDS00009 the yellow line is the SS from the ATMEGA.
The NodeMCU I'm using uses also an AMS1117, I'll try it tomorow powered by a lab power supply to see if makes some difference. Do you have any other suggestion? Can you share the exact RFM69.cpp/RFM69.h that you are using with the ESP8266 in order to be sure I'm not missing anything else?

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on June 02, 2016, 04:55:20 PM
I made this as a handy tool for both powering and communicating at 3.3v.  The CP2102 can level shift the logic signals just fine but otherwise lacks enough oomph to power both an esp8266 and an RFM69HW together just by itself.  It's nothing grand, but this simple tool fixes that.  Also, I find the CP2102 easily supports 921600 baud communications.

I also use it on Moteino's which have had their voltage regulator removed, because it can handle any load I'm likely to encounter.  Again, convenience.  To enable that, when I remove the moteino's voltage regulator I do a solder bridge across where the voltage regulator used to be so that the header pins can still power the Moteino.   

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 02, 2016, 07:20:00 PM
Hi WhiteHare,

Thanks for the tip,it is convenient, really!

In the meantime I tested with a lab power supply (30W) and the results are the same. I said before that the MISO didn't change, but I have now placed a pull-up resistor and now it moves almost together with the SS signal, as can bee seen in the attached picture. So now MISO goes low and stays low while the SS is low, but during that period it doesn't move, so it is replying with all zeros to the master. With the ATMEGA I don't have any pull-up and the MISO signal works, is the pull-up necessary with the ESP8266? What SPI frequency are you using, are you using the SPI clock divider as SPI_CLOCK_DIV2, SPI_CLOCK_DIV4,...? I've tested with different clock dividers but the result were similar. I'm getting out of ideas...

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on June 02, 2016, 11:54:26 PM
@fgomes
Strange.  Is your setup any different than the photo Joe posted in reply #3?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 03, 2016, 02:21:02 AM
@WhiteHare

As far as I can see in the photo Joe posted, the setup is similar, but in my case the module is the RFM69HW, so the pinout is not the same. Nevertheless,  if I change the MCU to an atmega, it works, and the signals look OK on the oscilloscope.  I will try a few more variants powering both modules with separate power supplies.

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on June 03, 2016, 02:58:48 AM
Quote
Can you share the exact RFM69.cpp/RFM69.h that you are using with the ESP8266 in order to be sure I'm not missing anything else?

I think the attached files worked for me. I'm using a different library now, but this should work.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 03, 2016, 09:19:06 AM
@Joe Lucid

Thank you very much for the sources. i have compared them with the ones I'm using and they are the same (so they are the RFM69 last version from GitHub). In your version I didn't saw the correction you said is necessary,

#define RF69_IRQ_PIN          D2
#define RF69_IRQ_NUM          D2

Can you confirm that this is the good version?

Thanks again for your help

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on June 03, 2016, 09:24:35 AM
Quote
Can you confirm that this is the good version?

Very weird. You're right this is the wrong version. I must have made an error, let me try again.

Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 03, 2016, 10:11:13 AM
@Joe Lucid

Thanks again :-)

This version has many differences, so it should be some versions earlier. Now I understand what you said about the code that swill block if the RFM69 didn't answer :-), in the recent versions it has a timeout, and it continue even if the RFM69 is not there, so the sketch should test the initialize return code (and in the examples it doesn't). I'll test it later, but since the problem in my setup occurs in the initialization, I don't see any major difference between the one you are using and what I'm using, but I'll post here the results.

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on June 03, 2016, 10:33:17 AM
@Fernando
If you continue to remain stuck, I suggest you post photos of your setup.  If it's just plain vanilla, it should be working, and if it isn't plain vanilla, you might want to start with that.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on June 03, 2016, 01:01:19 PM
Hi WhiteHare,

Thanks for the tip,it is convenient, really!

In the meantime I tested with a lab power supply (30W) and the results are the same. I said before that the MISO didn't change, but I have now placed a pull-up resistor and now it moves almost together with the SS signal, as can bee seen in the attached picture. So now MISO goes low and stays low while the SS is low, but during that period it doesn't move, so it is replying with all zeros to the master. With the ATMEGA I don't have any pull-up and the MISO signal works, is the pull-up necessary with the ESP8266? What SPI frequency are you using, are you using the SPI clock divider as SPI_CLOCK_DIV2, SPI_CLOCK_DIV4,...? I've tested with different clock dividers but the result were similar. I'm getting out of ideas...

Best regards

Fernando

I suggest you add a 10K or greater pullup on your MISO line and re-run your test.  If it stays LOW, then you may have a short.  If it stays HIGH, it may not be connected all the way through to your ESP8266 (maybe a faulty solder joint).  If you're using the v1.0 nodemcu, you shouldn't need it though. 

Also, MISO is GPIO12, so maybe you're connected to the wrong pin.  e.g. if you're connecting to SD0, thinking that it's MISO (and I can understand why because of the pinout labelling), it won't work.  The MISO you want is HMISO.  I haven't looked into it, but I suspect SDO may be a distinctly different MISO, for its flash memory or something.   Again, this is where photos of your setup would maybe reveal a faulty assumption.

Here's a pinout for nodemcu v1.0:
https://arduining.files.wordpress.com/2015/08/nodemcudevkit_v1-0_io.jpg

I'm mostly using ESP13's.  I tell the Arduino IDE that it's a WeMo D1 Mini, however, so that the IDE uploads at 921600 baud using my CP2102 handy tool (above).  After the initial upload, though, all it requires is 3.3V power, because the ESP8266 can subsequently update wirelessly and transparently directly from the Arduino IDE.  I haven't yet gotten the wireless serial debug working  (I didn't try very hard, so I'm not sure if it isn't yet fully implemented or if I'm just not doing it right), so for now I do still connect using my handy tool for serial debugging purposes.  Eventually, though, I'd expect the wireless debug console will work, and that will be very nice indeed.  The ESP8266 doesn't seem to have as many free pins as a Photon would, but for $2 I'm not complaining.   

Of course, it goes without saying that Moteino's are still the winning choice for low power battery applications.  :)  In that context, the ESP8266 is just a gateway or a pipe to a gateway.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 05, 2016, 02:14:05 PM
@WhiteHare, I'm using moteino and other similar nodes with the RFM69HW due to their power consumption and range characteristics, I just want to add the ESP8266 (that I'm using in other projects), as gateway, as you said.

@JoeLucid and @WhiteHare, let me thank you again by your support, the mystery is solved. In order to figure out what was going on I replaced again the ESP by an Atmega, and started having intermittent results also with the ATMEGA, so it was easier to figure out that the problem was a bad contact, on the MOSI connection to the RFM69 module. Solving that (almost all) the problem were solved. I started using the latest RFM69 lib, just with this small change in the .h file in order to introduce Joe change for the ESP:

// INT0 on AVRs should be connected to RFM69's DIO0 (ex on ATmega328 it's D2, on ATmega644/1284 it's D2)
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          0
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          2
#elif defined(__AVR_ATmega32U4__)
  #define RF69_IRQ_PIN          3
  #define RF69_IRQ_NUM          0
#elif defined(__arm__)//Use pin 10 or any pin you want
  #define RF69_IRQ_PIN          10
  #define RF69_IRQ_NUM          10
#elif defined(ESP8266)
  #define RF69_IRQ_PIN          D2
  #define RF69_IRQ_NUM          D2
#else
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          0 
#endif

But even then I had intermittent problems that disappear if I put my hand around the cables between the ESP and the RFM modules (I was using long dupont cables, about 15cm long). It seems that the problem is EMC, since they are long cables and SPI is running at some speed, and also there is some RF around from ESP and RFM modules. I was only able to solve this second issue in two ways, shielding the cables, or slowing down the SPI, so now I am using the SPI with the clock divided by 8 instead of divided by 4, replaced

SPI.setClockDivider(SPI_CLOCK_DIV4)

by

SPI.setClockDivider(SPI_CLOCK_DIV8)

So now it is running, once again thanks for your help!

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on June 05, 2016, 03:42:23 PM
Great that you got it to work! Btw I've found that this setup works progressively better as you move from breadboard via perfboard to custom pcb.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 05, 2016, 05:00:15 PM
@Joe, I'm sure you are right about that, I have noticed a change in its behavior only by changing the length of the SPI wires, but of course I'm stretching it a bit over the edge, using 15cm wires at a frequency of 2MHz or 4MHz, in the middle of two RF transmitters :-)

We should consider short connections and good ground planes, so a PCB is a must for reliable communications... But at least for a quick prototype the wires are enough, now I'll add the remaining functionality before designing the PCB :-)

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on June 05, 2016, 06:38:07 PM
The nice thing about a dipole is that, AFAIK, there's no ground plane requirement.  If you plug it into a wall outlet as wart for power, then the ground antenna (is there a more proper name for it?) can hang below while the regular wire antenna rises in the usual way.  It's not intrusive, though, because the footprint is small.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes on June 10, 2016, 06:54:38 PM
After solving the previous issues with your help, I have sensors reporting to a gateway node running the RFM69 library on the ESP8266. In the meantime I have made a sniffer sketch to monitor the 'air' traffic, and noticed that the ACK from the ESP8266 takes about 140ms after the message from the sensor. As the sensors are battery powered, this means they must be awake more 100ms with the radio listeningg when compared to the gateway running on an ATMEGA328 chip (with the ATMEGA328 running the gateway I see less than 40ms for the ACK, with the ESP I get between 140 and 150ms). Did you saw a similar delay in your setup? My ESP is based on a nodeMCU (has a ESP12E module).

Best regards

Fernando
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: joelucid on June 11, 2016, 09:19:35 AM
The esp8266 definitely does have some latency sometimes since it manages the wifi connection in the background. But not this order of magnitude. I'd recommend measuring millis on the gw between receiving the packet and sending the ack to see where exactly you lose the time.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare on June 11, 2016, 11:30:40 AM
After solving the previous issues with your help, I have sensors reporting to a gateway node running the RFM69 library on the ESP8266. In the meantime I have made a sniffer sketch to monitor the 'air' traffic, and noticed that the ACK from the ESP8266 takes about 140ms after the message from the sensor. As the sensors are battery powered, this means they must be awake more 100ms with the radio listeningg when compared to the gateway running on an ATMEGA328 chip (with the ATMEGA328 running the gateway I see less than 40ms for the ACK, with the ESP I get between 140 and 150ms). Did you saw a similar delay in your setup? My ESP is based on a nodeMCU (has a ESP12E module).

Best regards

Fernando

That doesn't sound right.  IIRC, the example gateway and node sketches that accompany the library would timeout long before 140ms  and say "Nothing..." rather than "OK!" for the ACK reception.  Yet, I didn't see that.  All I saw were  "OK!"'s.  What is it that you're seeing when you try running those example sketches?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: fgomes 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
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare 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?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: TomWS 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: TomWS 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
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: TomWS 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
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: someburner 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: TomWS 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
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: Xose 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: WhiteHare 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
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: Fernando Garcia 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.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: archeocomp on March 16, 2017, 03:03:03 PM
Hi folks, I am becoming little discouraged. Been experimenting since three days with two RFM69 modules, one connected to Arduino Mini 3V and the other to Wemos Mini. I can see read radios temeprature on both modules, but I can not receive on any of them. I tried send from Arduino to Wemos and reverse but no luck.
My two questions. Is the library here https://github.com/LowPowerLab/RFM69 (https://github.com/LowPowerLab/RFM69) suitable for both platforms? Is the receivng done via interrupt or not?
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: Felix on March 17, 2017, 10:18:22 AM
Maybe try a board that is known to work out of box? Like a Moteino :P ?
Sorry for the shameless plug but if this is a hardware problem you'd be much better off to start with what works then optimize.
If it's software then usually its always mismatched settings, especially the IS_RFM69HW directive.
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: Miked82 on April 24, 2017, 03:39:46 PM
Having issues compiling. Ideas?
EDIT:
I am trying 1.5.2


Code: [Select]
make[2]: Leaving directory '/opt/esp-rfm69/app/spiffs'
/opt/esp-open-sdk/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -I/opt/esp-rfm69/sdk-overrides/include -I/opt/esp-open-sdk/sdk/include  -Wl,--gc-sections -Wl,-Map=mapfile -nostdlib -T/opt/esp-rfm69//ld/eagle.app.v6.ld -Wl,@/opt/esp-rfm69//ld/defsym.rom -Wl,--no-check-sections -Wl,--wrap=_xtos_set_exception_handler -Wl,-static -Wl,--start-group -lc -lgcc -lhal -lphy -lpp -lnet80211 -lwpa -lwpa2 -lmain -ljson -lsmartconfig -lssl -lcrypto user/.output/eagle/debug/lib/libuser.a json/.output/eagle/debug/lib/libjson.a platform/.output/eagle/debug/lib/libplatform.a libc/.output/eagle/debug/lib/liblibc.a http/.output/eagle/debug/lib/http.a dns/.output/eagle/debug/lib/dns.a driver/.output/eagle/debug/lib/libdriver.a lwip/.output/eagle/debug/lib/liblwip.a mqtt/.output/eagle/debug/lib/mqtt.a rfm/.output/eagle/debug/lib/rfm.a smart/.output/eagle/debug/lib/smart.a util/.output/eagle/debug/lib/util.a spiffs/.output/eagle/debug/lib/spiffs.a -Wl,--end-group -lm -o .output/eagle/debug/image/eagle.app.v6.out
/opt/esp-open-sdk/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/4.8.5/../../../../xtensa-lx106-elf/bin/ld: .output/eagle/debug/image/eagle.app.v6.out section `.text' will not fit in region `iram1_0_seg'
collect2: error: ld returned 1 exit status
../Makefile:332: recipe for target '.output/eagle/debug/image/eagle.app.v6.out' failed
make[1]: *** [.output/eagle/debug/image/eagle.app.v6.out] Error 1
make[1]: Leaving directory '/opt/esp-rfm69/app'
Makefile:284: recipe for target '.subdirs' failed
make: *** [.subdirs] Error 2
Title: Re: [Update] RFM69 Library for ESP8266 - Moteino Compatible!
Post by: Kylix on December 14, 2017, 07:17:01 AM
try to use this branch: https://github.com/someburner/esp-rfm69/tree/sdk-1.5.3%2B