Author Topic: ListenMode with ESP32, issues.  (Read 11385 times)

ReNNo

  • NewMember
  • *
  • Posts: 4
ListenMode with ESP32, issues.
« on: June 19, 2020, 12:06:17 PM »
Hello all,

I'm using this library to enable communication between AVR and ESP32. It currently works as following:

NODE (can be multiple devices):
  • AtMega328 wakes up every 60 minutes and reads sensors data
  • AtMega328 sends data over RFM69HW and goes to sleep

GATWAY:
  • ESP32 is in light sleep and RFM69HW is in Rx mode
  • If data is received by RFM69, ESP32 will wake up by DIO0 pin and received data will be stored in ESP32

This works very reliably but I want to make gateway to be solar powered. If RFM69 consumes 16mA all the time it will require pretty large solar panel and multiple 18650 batteries. My goal is to modify current project to work in "Listen mode". This will greatly reduce power consumption.

In this approach everything should be working as described previously. Only difference is that node will send data by "listenModeSendBurst" method and gateway will go to Listen Mode before ESP32 goes to sleep (by calling listenModeStart).

Thanks to @Felix for merging "ListenMode" branch to "master" branch. I successfully tested this approach between two ATMEGA328 boards and it is working properly.
But when I use ESP32 as gateway it is not working as it should. When node sends data by "listenModeSendBurst" ESP32 wakes up correctly but data is not received.
For testing purposes I'm using ListenMode_Master and ListenMode_Node sketches.

Any idea what can cause these problems?

ReNNo

  • NewMember
  • *
  • Posts: 4
Re: ListenMode with ESP32, issues.
« Reply #1 on: June 22, 2020, 05:42:29 PM »
UPDATE:
Looks like "Light Sleep" of ESP32 is causing this problem. If I don't put ESP32 in "Light Sleep" and do something like following:
Code: [Select]
radio.listenModeStart();    
delay(5000);

If burst is sent during this delay I can successfully receive message in "Listen Mode".

Any ideas what can go wrong after ESP32 wakes up from light sleep?


ReNNo

  • NewMember
  • *
  • Posts: 4
Re: ListenMode with ESP32, issues.
« Reply #2 on: July 24, 2020, 02:46:06 AM »
UPDATE2:
Looks like ESP32 never triggers interrupt after it wakes up from LightSleep.
To solve this, I'm calling "listenModeIrq" manually just after it wakes up from sleep and it is working fine.

Fran13

  • NewMember
  • *
  • Posts: 2
Re: ListenMode with ESP32, issues.
« Reply #3 on: May 12, 2021, 08:23:57 PM »
Hi, it's been a long time since you posted this post. I hope you have solved the problems you had.

I write here because I'm in the same situation:

I'm using the RadioHead RFM library and RH_RF69 library to enable communication between Atmega32u4 and ESP32.

As node:

1- Atmega32u4 wakes up every 60 seconds and reads sensors data.
2- Atmega32u4 sends data over RFM69HCW and goes to sleep again.

As Gateway:

1- Esp32 is in deep sleep mode and the setup for RFM69HCW is done.
2- If data is received by RFM69, then ESP32 will wake up by DIO0 connected to GPIO27 pin from ESP32 and received data will be stored in ESP32.

When using energy saving mode, the frames are sent but not processed by ESP32 (server). Sometimes when I restart esp32 server i can see the first frame received (using a Logic Analyzer and Logi 2 - Saleae) but ESP32 never wake up again. But normally, if esp32 is not in an eternal sleep, the ESP32 wakes up caused from ext0 wakeup when I receive a message it wakes up but then the  condition if(rf69.available ()) is always false and I am not able to read the message from the buffer.

In the sketch of the gateway, I have all the code in setup () and nothing in the loop (). I cannot read the frame correctly because of the problems described above.

The RFM69 module does not have a built-in buffer to save the data itself, therefore the only method I can think of is to send esp32 to sleep in the loop () after reading if there is any data available using radio.available ( ).
Finally what you get is to wake up the microcontroller and run the loop normally. When you have received the expected data, you send it to sleep.

The problem that I have encountered here is that I need to send from the node a message to wake up the esp and then send the desired message. If I don't do this and I only send the message once, the esp32 will wake up and as soon as it wakes up I receive the buffer, but since I haven't read it yet, this buffer is lost.
For this reason, I need to send an "awake" message so that the loop is executed with the available () and to be able to correctly read the following message. After reading the message, I send the microcontroller to sleep again.

Could someone say if this is a good method to solve the problem? Does anyone know of any method to read the message just when esp32 wakes up without having to send 2 messages and having the loop () empty?

ReNNo

  • NewMember
  • *
  • Posts: 4
Re: ListenMode with ESP32, issues.
« Reply #4 on: May 27, 2021, 08:27:38 AM »
Hi Fran13

You can do the same as I did.

In RFM69.cpp add this method:
Code: [Select]
void RFM69::setHasData(){listenModeIrq();}
Also, don't forget to declare it as public in "RFM69.h"
Code: [Select]
class RFM69 {
  public:
    void setHasData();
    static uint8_t DATA[RF69_MAX_DATA_LEN+1]; // RX/TX payload buffer, including end of string NULL char
    static uint8_t DATALEN;

And just when your ESP32 wakes up by DIO0 call this method:
Code: [Select]
radio.setHasData();

This solved my problem.
« Last Edit: May 27, 2021, 05:08:04 PM by ReNNo »