Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By wesli
#88576 I'm using a Wemos D1 mini to control 3 relays using a browser. I started first with NodeMcu and Lua script. The web UI has 2 pages. One to control the relays and one config page, where I can setup the Wemos to work as client (STA) or access point (AP), IP address, basic authentication etc. On the config page I put a reboot button, which reboots the Wemos. With NodeMcu the Wemos D1 reboots and preserves the output state of the 3 GPIO's. Meaning if a relay was on it stays on after the restart.
Some weeks ago I switched to Arduino (using PlatformIO). I programmed a sketch with same functionality as the Lua program. The only difference is that when I reboot the Wemos the relays are switched off (if they where on) during the reboot.
Does somebody knows how NodeMcu achieve it to preserve the GPIO output state with Lua (node.rstart())? And is it possible to do the same with Arduino?
User avatar
By Mr.Gil
#88728 The outputs of the Arduino are set high with a weak pull up, that is part of the initial code before control is passed to your code. This is well documented in the Arduino literature. Save the state of the outputs in EEPROM when they change. AS close as possible at the beginning of your setup define the output pins and set the mode as output. Next read the EEPROM and set the port pins appropriately. That works for me. There is a very short glitch (code dependent) on the outputs when resetting with this method, however is typically to short for the relay outputs to activate.
User avatar
By StanJ
#88899 NodeMCU uses a different SDK, which is where the problem lies. Arduino uses 2.2.1, and NodeMCU uses one of the 3.x.x versions. All of the reset/boot processing is handled by the (closed-source) SDK. Sounds like espressif fixed that wart in the 3.x versions.

Not all pins are reset during external or Deep Sleep reset, but most are. I saw a couple of them hold their state through a Deep Sleep reset. Sorry, I don't recall which ones at the moment.
User avatar
By schufti
#88903 picking up Mr.Gils idea of early rebuilding i/o states: there are weakly defined void functions preinit(void) and user_init(void) (see core_esp8266_main.cpp) that may be best fit for this purpose. If it is only about sw restart, it may be sufficient to use RTC mem for handing over states, maybe much faster by using port registers directly.