Hello everyone. First, I am an extremely novice coder, so I'll apologize in advance for the inevitably messy and disorganized nature of my code, and possible omissions of important information to diagnose the issue. Tried including everything I could think of.
I learned to code (as much as I know, anyway) solely to build a controller for my indoor garden with the intent of maintaining ideal VPD (basically, controlling temperature and humidity in relation to each other). The desired conditions vary between day and night, so the NodeMCU controller must connect to WiFi in order to check the time. The problem is, about a day and a half after I start running the code, it will experience some sort of error and stop working. This doesn't always happen, but it happens a lot of the time, and occasionally will happen in less than ~36 hours.
For whatever reason, when it errs, it runs only the swamp cooler and nothing else (probably something electrical which I don't understand, since I have the swamp cooler on the RX pin). Because the room is so humid and relatively hot, I haven't been comfortable leaving my computer in there the whole time with Serial Monitor on waiting for it to crash (plus I use my computer daily). When I attempt to check the board in Serial Monitor after it has erred, it has no output.
However, there is one other circumstance where it also runs only the swamp cooler and nothing else: when I restart the NodeMCU, and it is attempting to connect to WiFi and check the time. Before this, it only says "WiFi Disconnected..." repeatedly in the serial monitor.
My theory is: the NodeMCU fails to connect to WiFi during a scheduled two-hour restart (which I ironically included to circumvent possible memory-related freezes which could come with just running the code indefinitely). This leaves it looping the "WiFi Disconnected..." menu until its memory fills up and it freezes. I'll take this opportunity to stress my novice experience level, so I might not exactly be qualified to diagnose the problem. Because there's no specific error code, and such a specific issue, it's hard for me to look into on my own.
In short: trying to create a controller which will switch on/off 5 different relays and connect itself to WiFi. For some reason, possibly related to WiFi and possibly not, after roughly a day and a half to two days, it freezes up and has no output on the Serial Monitor.
Any insight? Code attached. I also tried including a check which would tell me if the WiFi is disconnected and shut the NodeMCU off if it's been disconnected while running for more than 15 minutes, but this portion
- Doesn't really work - it seems to constantly say it's disconnected from WiFi, even though it must connect to get past the initial time-check.
- Wouldn't work to reset it anyway, if the issue is the NodeMCU filling up with the "WiFi Disconnected..." message from void.setup