• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Hey Random Nerd

Q&A Forum › Category: ESP32 › Hey Random Nerd
0 Vote Up Vote Down
Stig Lindberg asked 6 years ago

Hey.

I´m looking for a mqtt button script for Nodemcu esp32, there connects to mqtt broker and post the topic and the payload and after goes to deep sleep mode, and first wakes up then the button got push.

Can you please help me to create a script like that.

Best regards
Stig Lindberg

3 Answers
0 Vote Up Vote Down
Stig Lindberg answered 6 years ago

I have here a link for a script for esp8266 there works like I want to have it but without deepsleep mode.
How can I convert it for esp32 and add deepsleep mode for the script.

Link to script: https://github.com/davolesh/mqtt_pushbutton/blob/master/mqtt_button_basement.ino?fbclid=IwAR3B8iLZdNf16XgTiUE6NKHuppoTlJSq4NfY747nNRQofyYWjomnEpMlOF4

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi.

That example uses the PubSubClient library that should be compatible with the ESP32. So, I think you don’t need to change anything about that.

I recommend you test that script with the ESP32 and see if it works.

Then, because you want to put the ESP32 in deep sleep and wake it up with a button, you need to add an external wake-up.

Move all the code to the setup() function.

Then, enable external wake up with the following:

esp_sleep_enable_ext0_wakeup(GPIO_NUM_X, level)

This function accepts as first argument the pin you want to use, in this format GPIO_NUM_X, in which X represents the GPIO number of that pin.

The second argument, level, can be either 1 or 0. This represents the state of the GPIO that will trigger wake-up.

Note: you can only use pins that are RTC GPIOs with this wake-up source.

Finally, call the following function to start deep sleep:

esp_deep_sleep_start();

All of this is explained in this unit: https://rntlab.com/module-3/deep-sleep-external-wake-up/

Regards,

Sara

0 Vote Up Vote Down
Stig Lindberg answered 6 years ago

Thank you very much for your help 🙂 

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.