ESP8266_NONOS_SDK-2.2.0,How to achieve sleep and button wake up

315002181huang
Posts: 4
Joined: Fri Nov 26, 2021 6:07 pm

ESP8266_NONOS_SDK-2.2.0,How to achieve sleep and button wake up

Postby 315002181huang » Fri Nov 26, 2021 7:10 pm

As mentioned, what I need to achieve is that ESP2866 can also wake up through GPIO at the same time.Whether only scheduled wake up and GPIO wake up can only be implemented in one way.
Wifi_fpm_do_sleep (0xFFFFFFF);wifi_enable_gpio_wakeup(GPIO_ID_PIN(4), GPIO_PIN_INTR_LOLEVEL);", you can go to sleep.When the button is pressed, the current changes from 0.92mA to 67mA, indicating that it has been awakened, but no action can be performed.
Therefore, after sending data to the cloud platform, how to wake up the chip after pressing four buttons and continue to send data to the cloud platform after connecting WiFi?

Her Mary
Posts: 537
Joined: Mon Oct 27, 2014 11:09 am

Re: ESP8266_NONOS_SDK-2.2.0,How to achieve sleep and button wake up

Postby Her Mary » Wed Dec 01, 2021 11:12 am

How about RTOS SDK? There is an example of power save, not sure if it can help. https://github.com/espressif/ESP8266_RT ... power_save

AgentSmithers
Posts: 195
Joined: Sat Apr 01, 2017 1:21 am
Contact:

Re: ESP8266_NONOS_SDK-2.2.0,How to achieve sleep and button wake up

Postby AgentSmithers » Thu Dec 09, 2021 4:42 pm

I'm back after a nice long needed vacation, I'm still chunking away in college for the next 3 years.
I am unsure if I understand your questions correctly but I'll give this one a go.

If I understand your questions correctly you want to act on a button press (or multiple on waking).
If you can provide a step by step example of what you are looking for I can indeed help :)

Here are some pieces anyways.

The first Snippet is how to read and write a counter to your SPI memory, this will survive any powerloss/reboot you have.
The second goes in your startup / main code that detects the reason for booting, Upon botting read the SPI, then sleep for about a second or so, As your pressing the button you can inc the SPI index value to +1 then after your sleep cycle on boot act on it or another method.

I personally use the following method below to have the chip detect that its in a crashing loop then to kick off a debug safe mode to report in if that were to ever happen so I have a chance for recover with FOTA.

I hope this points you in the correct direction, if not Ill be back this week and will watch for your reply.

Code: Select all

typedef   struct   {
   uint32   magic   ;
   uint32   rst_count;
   uint64  Reserved;
}RTC_RST_STRUCT;

bool ICACHE_FLASH_ATTR StoreRSTCount(uint32 Count)
{
   os_printf("[%s][%s][%d] - creating with: %u\r\n", __FILE__ ,__func__, __LINE__, Count);   
   //system_rtc_mem_write(68, &Count, sizeof(Count));      
   RTC_RST_STRUCT rtc_rst;
   rtc_rst.magic   = 0xDEADBEEF;
   rtc_rst.rst_count = Count;
   system_rtc_mem_write(72, &rtc_rst, sizeof(rtc_rst));      
}

uint32_t ICACHE_FLASH_ATTR GetRSTCount(void)
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);   
   uint32 count;
   //system_rtc_mem_read(68,   &count, sizeof(count));
   RTC_RST_STRUCT rtc_rst;
   system_rtc_mem_read(72,   &rtc_rst, sizeof(rtc_rst));
   if(rtc_rst.magic==0xDEADBEEF)
   {
      os_printf("[%s][%s][%d] - GET GetRSTCount %u\r\n", __FILE__ ,__func__, __LINE__, rtc_rst.rst_count);
      return rtc_rst.rst_count;
   }
   else
   {
      return NULL;
   }
}


Code: Select all

struct rst_info *rtc_info = system_get_rst_info();
   os_printf("reset reason: %x\n",   rtc_info->reason);

   switch (rtc_info->reason)
   {
      case REASON_DEFAULT_RST:
         os_printf("REASON_DEFAULT_RST\r\n");
      break;
      case REASON_WDT_RST:
         os_printf("REASON_WDT_RST\r\n");
      break;
      case REASON_SOFT_WDT_RST:
         os_printf("REASON_SOFT_WDT_RST\r\n");
      break;
      case REASON_SOFT_RESTART:
         os_printf("REASON_SOFT_RESTART\r\n");
      break;
      case REASON_EXCEPTION_RST:
         os_printf("REASON_EXCEPTION_RST (%d)\r\n", rtc_info->exccause); //Add recovery code logic here
         uint32_t EXC = GetEXCCount();
         if (EXC == NULL)
         {
            StoreEXCCount(1);
         }
         else
         {
            EXC++;
            StoreEXCCount(EXC);
         }
         //Add some Call back register here! =)
      break;
      case REASON_DEEP_SLEEP_AWAKE:
         os_printf("REASON_DEEP_SLEEP_AWAKE\r\n");
      break;
      case REASON_EXT_SYS_RST:
         os_printf("REASON_EXT_SYS_RST - Button Press\r\n"); //When freshly Flashed we get this or a Hard button Reset
         common_RSTCount = GetRSTCount();
         if (common_RSTCount == NULL)
         {
            os_printf("common_RSTCount == NULL / ZERO\r\n");
            StoreRSTCount(1);
         }
         else if(common_RSTCount == 9)
         {
            os_printf("common_RSTCount == %u, setting up WiFi\r\n", common_RSTCount);
         }
         else
         {
            os_printf("common_RSTCount == %u\r\n", common_RSTCount);
            common_RSTCount++;
            StoreRSTCount(common_RSTCount);
         }
         delay_5seconds(); //Give the user five seconds to reset once more to higher the count!
         //Add some Call back register here! =)
         if(common_RSTCount >= 3 || false) //true for debugging code
         {
            os_printf("Entering Debug Mode");
            FlickerLED(2, 30);
            FlickerLED(2, 60);
            FlickerLED(2, 30);
            FlickerLED(2, 60);
            //Add some debug code here
            spi_flash_read(WifiMemorySpace,(uint32 *)&GlobalFlashConfig,sizeof(GlobalFlashConfig));
            uart_init(BIT_RATE_115200, BIT_RATE_115200, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
            InDebugMode = true;
         }
         StoreRSTCount(0); //Reset value to zero
      break;
      default:
         os_printf("Some other REASON?!\r\n");
      break;
   }

   if (rtc_info->reason == REASON_WDT_RST || rtc_info->reason == REASON_EXCEPTION_RST || rtc_info->reason == REASON_SOFT_WDT_RST)
   {
      os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n", rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc);//debug   garbled   output.
      halt();
   }   

Who is online

Users browsing this forum: No registered users and 186 guests