• 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

4_4_Multiple_Web_Pages Start after power outage

Q&A Forum › Category: ESP32 › 4_4_Multiple_Web_Pages Start after power outage
0 Vote Up Vote Down
tthomas1232 asked 4 years ago

I recently set up my ESP32 with 4 relays using the instructions and code from the 4_4_Multiple_Web_Pages section of the book Build Web Servers ESP32. The instructions were great and my ESP32 and relays work as described. The only issue I have is when the ESP32 restarts after a power outage, the initial state of all the outputs is on. That could be a problem if equipment or lights start without my knowledge. Would you please suggest ways to adjust the code to put all the outputs to the off state upon startup of the ESP32. Thank you very much.

5 Answers
0 Vote Up Vote Down
Steve Mercer answered 4 years ago

In the setup section, after the pin mode statements, set all outputs to off. Sorry, I don’t have that particular book so I don’t have the code to look at.

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

Hi Thomas.

Alternatively, you may want to save the GPIOs state permanently whenever there is a change.

If you want to store small amounts of data, you can use the Preferences library.

We’ve just published a tutorial about that today: https://randomnerdtutorials.com/esp32-save-data-permanently-preferences/
In this tutorial, there’s a simple example showing how to “remember” the last GPIO state after a reset.

Alternatively, you can create a file in SPIFFS where you save a JSON variable with the GPIOs states whenever there’s a change. Then, you need to add some code at the beginning to read that file and set all GPIOs to their previous states.

I hope this helps.
Regards,
Sara

0 Vote Up Vote Down
tthomas1232 answered 4 years ago

Thank you very much.  Both suggestion were good.  I solved my own problem last night by adding code in the setup to to set the output pins to the proper state like that suggested by Steve.

0 Vote Up Vote Down
tthomas1232 answered 4 years ago

Thank you very much.  Both suggestion were good.  I solved my own problem last night by adding code in the setup to to set the output pins to the proper state like that suggested by Steve.

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

Hi.
That’s great!
I’ll close this question. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

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.