Smart farming · The backyard farm AI runs series · Part 2
The backyard farm AI runs, part 2: an ESP32 dropping off Wi-Fi every hour, cause and fix traced with real data
A farm ESP32 dropped off Wi-Fi 23–55 times a day on average (reason 2, ZTE router). Testable causes ruled out with evidence; the drops stopped by themselves and the cause is not yet proven. Step-by-step method, charts and FAQ.
Published · Last updated
The AI we train at home learns only from the farm's own data. If the data has gaps, the model sees only part of the picture and learns the wrong thing without anyone noticing. This part does not yet measure how much a model would learn wrong; it is about how we found the gap: the farm board dropped off Wi-Fi 45 times in 47 hours, 2.6 hours missing in all, or 5.6% of the time.
It is also a record of concluding wrongly twice. First, the channel hypothesis was wrong. Second, the evidence I used to point at the router compared the wrong device. Both were caught by measuring and by a reader checking the article. The cause is therefore still unknown, and on the evening of 19 November the drops stopped by themselves with no fix applied. So this article sets out what has been ruled out, what remains, and the fixes ready for whatever further measurement shows.
In short
- Problem: the farm's ESP32 board dropped off Wi-Fi 23 times a day on average (16–18 Nov) and 55 a day after the channel was fixed (18–19 Nov), 3–6 minutes each time, stopping the mister mid-pulse in the hottest hours.
- Found: the router settings were not the cause, the board did not restart and the router never went down. The signal at the board was weak (−70 to −80 dBm), but weakness alone does not explain it: drops got more frequent while the signal improved. Fixing the channel did not help.
- Outcome: from the evening of 19 November drops fell to one a day (the router restarting itself at 04:44) for 9 days running, with the signal at −66 to −68 dBm and nothing changed. The cause is not proven. Suspects are interference or something that changed then, such as water or moisture between the box and the router.
- Fixed: firmware that lets the mister finish its pulse when Wi-Fi drops (10 days, 19–28 Nov, 902 pulses, none cut short), and the edge computer watching for drops every 5 seconds.
- Recommended lasting fix: a stronger signal at the board, such as an external antenna, an access point near the box, or a cable.
We first saw it on the afternoon of 18 November 2026, when the farm app showed "safety stop" twice, at 12:06 and 14:01. The mister stopped mid-pulse in the hottest part of the day. I suspected an overheated control box. The board's log pointed to the network instead.
The system
An ESP32 board in a box beside the plot reads the sensors and drives the pump and mister relays. It sends data over the house's 2.4 GHz Wi-Fi to two places: the edge computer at home (the main controller, which keeps the data, trains the AI and gives the commands) and a cloud server (the backup). Both paths share one Wi-Fi link, so when Wi-Fi drops, both go at once. The board's firmware has had Wi-Fi power saving (modem sleep) switched off from the start.
This drawing sums up the whole story on one page. The weak point is the Wi-Fi hop between the board and the router; fixes ① to ③ are in use, and ④ is the recommended lasting fix.
The board carries a safety rule I set on 14 November: if Wi-Fi is lost, or no controller is connected at all, every relay switches off at once. A pump left running with nobody watching can overflow a tank or run dry and fail.
Tzounis et al. (2017), reviewing IoT in agriculture, list unreliable wireless connectivity among its main challenges. A small farm on home Wi-Fi feels this sharply: a home router is tuned for phones and TVs, not for a device at the far end of the garden.
Method
- Before the fix: 16 Nov 2026 22:00 to 18 Nov 2026 21:08, 47 hours.
- After the fix: 18 Nov 2026 21:45 to 19 Nov 2026 19:36, 21.8 hours (the firmware-install restart at 22:03 excluded), shorter than the 24 hours this article itself recommends.
- One drop: from the server logging the board offline to logging it online again.
- From the board: signal strength (RSSI), the last disconnect reason, a drop count since power-on, and uptime.
- Comparison devices: from 04:27 on 19 Nov the edge computer pinged the board, a CCTV camera and the router every 5 seconds. At first it identified devices by IP, which went wrong (see the section on my mistake below). From 20:03 on 19 Nov it identifies them by MAC address. The edge computer itself is on 5 GHz Wi-Fi, not a LAN cable.
Findings before the fix
- 45 drops, 66 minutes apart (median; shortest 10, longest 89), each lasting 206 seconds (median), 9,464 seconds in total.
- By day (06:00–18:00) 1.0 drops an hour, by night 0.9: about the same, so in this period box heat was not a factor.
- The board did not restart. It reported 122,393 seconds (34 hours) of uptime and normal free memory.
- The disconnect reason was reason 2; the board reported a signal of −77 and −80 dBm in this period (two readings).
- The cloud and the edge lost the board at the same moments, for example 12:06, 13:04 and 14:01 on the 18th.
- A firmware update over Wi-Fi (a 1.2 MB file) failed once with an incomplete download.
The "safety stop" showed up only around noon because that is when misting is most frequent. On 18 November the system ran 99 pulses between 08:00 and 14:00, so a drop usually landed on a running pulse.
First hypothesis: the Auto channel
In the IEEE 802.11 standard, reason code 2 means "previous authentication no longer valid". At first I read it as the router dropping the board, but Espressif, the maker of the ESP32 (2026), documents that the board reports this code in two cases: when it receives the code from the router, and when its own authentication timer runs out. So the code alone cannot say which side ended the link.
On signal strength, Zhao and Govindan (2003) measured low-power wireless sensor radios (not Wi-Fi) and found a "transitional region" between good reception and none, where delivery swings widely and unpredictably. I use this only as an analogy: the dBm ranges of the two radios differ, and Wi-Fi at −80 dBm still connects at a low rate. The point taken is that a device with little signal margin is the first to drop and the slowest to rejoin when something in the network changes.
The house router, an NT-supplied ZTE, had its 2.4 GHz channel set to Auto. Such a router scans for a quieter channel and moves there from time to time. The survey by Chieochan et al. (2010) and the work of Akl and Arepally (2007) describe how dynamic channel assignment improves a network as a whole, but every move forces each device to find the router and authenticate again. So my hypothesis was that the channel moves caused the drops.
The test: a fixed channel
At 21:45 on 18 November I set the 2.4 GHz band to channel 6 · 20 MHz bandwidth · 802.11b/g/n mode. Channel 6 is one of the three that do not overlap (1, 6, 11). The network name and password were left alone. One lesson on the way: the first change, at 21:08, quietly switched the bandwidth to Auto, so I had to set 20 MHz explicitly.
At the same time I wrote firmware 1.7.7, which lets a mister running a timed pulse (5 minutes at most) finish the pulse and switch itself off, while the water pump still stops at once. It was installed over Wi-Fi at 22:03 on 18 November 2026, after two failed attempts (the first download was incomplete; the second collided with the router restarting its radio after Apply).
The split follows the risk. A pump left on can flood a tank. A timed mist pulse is counted down by the board itself and is certain to end within 5 minutes, command or no command. The server tells the board which relay is the mister. The board keeps that flag in RAM only, so after a restart, until the config arrives, every relay falls back to the instant stop.
Results after the fix: the hypothesis was wrong
- The board still dropped 50 times in 21.8 hours, or 55 a day, more than before (23 a day). Drops came 24 minutes apart (median) and lasted 326 seconds (median): 19.9% of the time offline.
- By day 2.8 drops an hour, by night 1.6, unlike before, when day and night were about equal. Box heat, or anything that happens only by day, such as the mister pump running or busier neighbouring Wi-Fi, has to be reconsidered.
- The signal in this period was better than before the fix, −70 to −77 dBm (16 readings, average −73), yet drops became more frequent. So a weak signal alone cannot explain the drops.
- Throughout the board's drops the edge computer could still ping the router over 5 GHz, except at 04:44. The router itself did not go down, and the 5 GHz band did not drop with the board.
- At 04:44 the whole router vanished from the network for 80 seconds, matching the short drop at 04:44 seen every day. It is probably a scheduled restart set by the provider; I have not yet checked the settings.
- The router's DHCP lease is 24 hours, so IP renewal is not the cause of the cyclic drops.
What the evidence supports is only this: the channel moves were not the main cause, since with a fixed channel the drops continued and became more frequent, and the router itself stayed up. Whether the cause is the whole home 2.4 GHz band or the weak-signal board side cannot yet be told apart.
Layer two did well on its first day, but the count is incomplete. On 19 November there were 93 mist pulses and not one was cut short by a Wi-Fi drop, against 2 the day before. That number does not tell the whole story. Between 08:00 and 17:00 that day the board was offline 26.8% of the time. Most misting rules decide from the readings the board sends, so almost no new pulse started while it was offline (the forecast rule sent one command that never reached the board), and the pulses that should have run but did not are not counted. That was also the first day of pacing mist water over the whole day, which cuts pulses on purpose. It is one day of data; it needs at least a week.
The risk of letting a pulse run unsupervised: at worst the mister runs a full 5 minutes after Wi-Fi drops, using under 0.4 litres (at the measured flow of about 0.075 L/min). The water leaves as mist over the plot, so nothing can overflow. The board counts the time itself without the network, and its own maximum on-time is a second cap. If the mist tank is empty, the mister pump may run dry for up to 5 minutes per pulse. The main water pump, which could flood a tank, still stops at once.
My own mistake: the camera evidence does not hold
The 19 November version of this article said "the CCTV camera dropped with the board 37 times out of 37" and used it as the main evidence that the router was the cause. That evidence is wrong.
The edge computer pinged the camera at 192.168.1.5, the camera's address on the 18th. But when the router restarted its radio after the settings change, the board was given 192.168.1.5 and the camera moved to 192.168.1.9. From the moment the edge computer started pinging, what it logged as "camera" was the board itself, so the comparison was the board against itself, which matches every time. The "board" at 192.168.1.2 was another device, which explains why the board seemed not to answer ping.
I found this because a reader checking the article asked why the board would not answer ping yet still sent data. Checking the IP-to-MAC table showed the addresses had swapped. From 20:03 on 19 Nov the edge computer identifies devices by MAC address, which does not change with the IP, but by then the frequent drops had stopped, so there is still no valid camera comparison from a period of frequent drops. The earlier data is kept separately and labelled as mis-identified.
Latest results: the drops stopped by themselves
- From about 19:30 on 19 Nov to 28 Nov (9 days) the server saw the board drop once a day, at 04:44 every day for about a minute, when the router restarted itself.
- During the day on 20 Nov there were no drops at all, although the air reached 40.5 °C and the mister ran 117 pulses.
- Nobody changed the router settings, the firmware or where anything sits (confirmed again on 28 Nov). The only event was refilling the mist tank at 20:01, after the drops had already stopped.
- Signal strength: before the fix −77 and −80 dBm · after fixing the channel −70 to −77 dBm (average −73) · quiet stretch from 20 Nov −66 to −68 dBm (4 readings taken from the system), about 5–10 dB stronger than while dropping.
- Air humidity at the plot: daily averages of 71–80% from 16 to 19 Nov and 59–67% from 20 Nov, falling with the quiet stretch; but at 19:30 on the 19th, when the drops stopped, humidity was rising (65% → 76%), so no conclusion can be drawn from it yet.
- The camera (now identified by MAC address) dropped only from 04:44 to 04:47, together with the router.
- The edge computer's pings to the board went unanswered for short spells, 18 minutes in all, but the server never saw the board drop, so a lost ping is not the same as dropping off Wi-Fi.
The daily chart counts calendar days (13 to 48 drops), unlike the averages of 23 and 55 a day above, which follow the test periods. The blue points are the day's average signal where readings exist. Drops rose while the signal improved on 18–19 Nov, then fell to one a day once the signal rose a step further. The two may simply coincide, or share a cause.
The cause: what has been ruled out, and what remains
| Suspect | Evidence | Result |
|---|---|---|
| Hot control box | 40.5 °C on 20 Nov, no drops by day | not enough to cause drops alone (tested once the signal was good); not ruled out as a factor together with a weak signal |
| Mister pump causing a power dip or noise | 117 pulses on 20 Nov, no drops | not enough to cause drops alone (tested once the signal was good); not ruled out as a factor together with a weak signal |
| Auto channel | still dropping, more often, on a fixed channel | ruled out |
| DHCP lease | set to 24 hours | ruled out |
| Board restarting or code hanging | continuous uptime | ruled out |
| Wi-Fi power saving | off in the firmware from the start | ruled out |
| Router going down | answered ping over 5 GHz throughout, except its 04:44 restart | ruled out |
| Intermittent 2.4 GHz interference from outside, such as neighbours' Wi-Fi or other wireless devices | the drops started and stopped by themselves with no change on our side | still possible, no direct evidence |
| A board signal so weak it has no margin | −70 to −80 dBm while dropping, and a firmware download once came in incomplete; yet drops grew while the signal improved | likely a contributing factor, cannot explain it alone |
| Water or moisture between the box and the router (mist, wet leaves, damp inside the box), which absorbs 2.4 GHz | humidity averaged lower in the quiet stretch, but was rising when the drops stopped | still possible, needs more measurement |
What the evidence supports: the actual cause is not yet proven. The data do not support a weak signal as the sole cause, since after the channel change the signal was better than before yet drops were more frequent, so something else likely grew stronger then, such as interference on the 2.4 GHz band or water and moisture in the signal's path. That the drops stopped as the signal rose may be coincidence, or a shared cause changing both. The next step that would separate them is recording signal strength every 10 minutes, alongside humidity and misting.
The fix: what is in use, and what is ready
In use
- Firmware 1.7.7 lets the mister finish its pulse when Wi-Fi drops. Over 10 days (19–28 Nov) the mister ran 902 pulses and none was cut short.
- The edge computer keeps watch, pinging the board, the camera and the router every 5 seconds, identifying them by MAC address and summarising every hour. If the drops return, we will have a valid comparison with the camera straight away.
- Channel 6 · 20 MHz stays. It did not reduce the drops, but it keeps one variable fixed while measuring continues.
Ready if the drops return (chosen by the camera comparison)
- Camera drops with the board: the router or the whole home band is the problem. Install a farm-only outdoor access point on a channel away from the router's.
- Only the board drops: the problem is on the board's side. Strengthen its signal with an external antenna, move the box or the router closer, or put an access point near the box, or stop depending on Wi-Fi with a cable.
Either way, the most lasting fix is likely giving the board a stronger signal margin, because even if the interference is found, a weak-signal board will still drop easily when the next source of interference appears.
Finding the cause, step by step
An order that works for any IoT device that drops out now and then: start at the device, widen to the network, and change one thing at a time.
- Does the device restart? Check its uptime. Frequent resets point to power or code. No resets point to the network.
- Read the reason code, together with the chip maker's documentation. Some codes, such as reason 2 on the ESP32, can come from either the router or the device.
- Do other devices drop too? Have a computer in the house ping a second Wi-Fi device at the same time, identifying devices by MAC address, not IP, since an IP can change on every reconnect. If both drop together, the router or interference is the problem; also ping the router from a computer on a LAN cable, and if the router still answers, the router is up and the problem narrows to the radio. If only one drops, look at that device or its signal.
- Change one setting, and measure before and after over equal periods, at least 24 hours each, better 48. Compare with the same set of numbers (drops per hour, split by day and night, and share of time offline).
- Fix what you found. If it is the router, give key devices their own access point; if it is the device side, strengthen the signal or use a cable.
Next steps
- Let the edge computer keep watching without changing anything; if the drops return, a valid camera comparison will be there straight away. Since 21:27 on 28 November 2026 the system records the signal strength every time the board reports (about once a minute), with an hourly average and minimum, so if the drops return, signal can be compared with humidity and misting hour by hour.
- Read the router's log around the drops (logging is now on), and check whether a restart is scheduled at 04:44.
- Count the mist pulses that should have run but did not because the board was offline.
- Then choose a fix, such as a farm-only outdoor access point or a better antenna for the board, one change at a time, 48 hours per period.
Each result will be added to this article and logged in the revision history.
Limits
- One board, one router, one house: a case study, not a controlled experiment.
- The after period is 21.8 hours, shorter than the 47-hour before period, and on a different day; conditions such as neighbours' Wi-Fi may differ.
- The test changed three settings at once (channel, bandwidth and mode) and the firmware in the same period, so I cannot say what had which effect. Firmware 1.7.7 changes only how relays behave on a drop, not the Wi-Fi code, but it is still a confounder.
- The edge computer is on 5 GHz Wi-Fi, not a LAN cable, so reaching the router from it shows the router and the 5 GHz band were up, but says nothing about 2.4 GHz.
- The valid camera comparison started after the drops had stopped, so there is no valid comparison yet from a period when the board dropped often.
- The drops have been gone for 9 days but may return if the interference does, and the board logged only a few signal readings early on.
- I have not yet read the router's internal log.
If your farm devices drop out now and then
- Follow the five steps above, and in step 3 identify devices by MAC address from the start.
- Make the signal at the device stronger. Move the router, add an extender or a separate access point, or use a cable, and compare signal strength before and after.
- Match the safety rule to each device's risk. Anything that causes damage when left on must stop at once. Anything the board knows will end by itself shortly may finish.
- Count the gaps in your data before training any AI. Know what share is missing and when. Gaps that recur by day can teach a model the wrong story about the hottest part of the day. Count what did not happen because data was missing, not only what did.
- Let your hypothesis be wrong, do not conclude beyond the evidence, and have someone else read it. Both mistakes in this article were caught because the data was measured and someone asked the right question.
Frequently asked questions
Why does an ESP32 drop off Wi-Fi in cycles, every hour or more often?
On this farm it is not proven. The board did not restart, the router did not go down, and the router settings were not the cause. The signal at the board was weak (−70 to −80 dBm), but drops got more frequent while it improved, so interference or another factor likely played a part, such as water or moisture between the device and the router. The drops stopped as the signal rose to −66 to −68 dBm, which may be coincidence. If you see this, compare with another device and record signal strength from the start.
Does reason 2 (AUTH_EXPIRE) on an ESP32 mean the router kicked the device off?
Not necessarily. Espressif's documentation says the ESP32 reports reason 2 both when it receives that code from the router and when its own authentication timer runs out, so other evidence is needed.
Does setting a fixed Wi-Fi channel help?
Not on this farm. With channel 6 at 20 MHz the drops rose from 23 to 55 a day. A fixed channel is still useful while measuring, because it removes one variable that changes by itself.
How do I tell whether the router or the device is the problem?
Have a computer in the house ping the problem device and another Wi-Fi device every few seconds, identifying them by MAC address rather than IP, since IPs can change. If both drop together, the router or interference across the house is the problem. If only one drops, look at that device or its signal.
How do I keep pumps and misters safe when Wi-Fi drops?
Let the board decide safety itself instead of waiting for the network. On this farm the water pump stops at once when contact is lost, while a mister running a timed pulse of 5 minutes or less finishes it and switches off, since it cannot overflow anything.
References
Zhao, J., & Govindan, R. (2003). Understanding packet delivery performance in dense wireless sensor networks. Proceedings of the 1st International Conference on Embedded Networked Sensor Systems (SenSys '03), 1–13. https://doi.org/10.1145/958491.958493
Akl, R., & Arepally, A. (2007). Dynamic channel assignment in IEEE 802.11 networks. 2007 IEEE International Conference on Portable Information Devices, 1–5. https://doi.org/10.1109/PORTABLE.2007.63
Chieochan, S., Hossain, E., & Diamond, J. (2010). Channel assignment schemes for infrastructure-based 802.11 WLANs: A survey. IEEE Communications Surveys & Tutorials, 12(1), 124–136. https://doi.org/10.1109/SURV.2010.020110.00047
Tzounis, A., Katsoulas, N., Bartzanas, T., & Kittas, C. (2017). Internet of Things in agriculture, recent advances and future challenges. Biosystems Engineering, 164, 31–48. https://doi.org/10.1016/j.biosystemseng.2017.09.007
Espressif Systems. (2026). Wi-Fi driver: Station scenarios and Wi-Fi reason codes. ESP-IDF Programming Guide (v6.1.1). Retrieved November 19, 2026, from https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/wifi-driver/station-scenarios.html
IEEE. (2021). IEEE Standard for Information Technology, Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications (IEEE Std 802.11-2020). https://doi.org/10.1109/IEEESTD.2021.9363693
Drop times, signal strength, mist pulses, mist commands, the firmware update and the edge computer's ping log come from the Baan Rak Phak farm system log, 16–28 November 2026, including air humidity at the plot, measured and analysed by Pisarn Boonnuk. All drawings are redrawn from that data.
Revision history
- : The system started recording signal-strength history at 21:27 on 28 Nov (added to next steps)
- : Revised after a third review: the signal was better after the channel change yet drops were more frequent, so a weak signal is no longer called the main cause (description, summary, FAQ) · heat and pump now "not enough to cause drops alone" · Zhao and Govindan used as an analogy · humidity data and the water suspect added · one set of signal figures per period · 10 days, 902 pulses · data through 28 Nov · overlapping drawing fixed and printing uses the light theme
- : Added a drawing of the data path ESP32 → router → edge and VPS, marking the weak point and where each fix sits
- : Updated stale text: the 48-hour measuring step (done) and the state of the camera comparison
- : Added an opening summary, 9 days of results (one drop a day, signal 8–10 dB stronger with nothing changed), a daily chart of drops and signal strength, and an FAQ · title and description now carry search terms (ESP32, reason 2)
- : Added latest results: drops stopped by themselves from ~19:30 on 19 Nov (one drop in 23 h) · table of causes ruled out with evidence, and remaining suspects · fixes in use and ready, chosen by the camera comparison · comparison drawing now shows three periods
- : Major correction: withdrew "camera dropped with the board 37/37" because IPs had swapped and the edge compared the board with itself · conclusion changed to cause unknown · day/night rates for both periods · router still answered ping over 5 GHz · pulses never started while offline (26.8% of 08–17) and water pacing began the same day · edge now identifies devices by MAC
- : Revised after review: title matches the content · reason 2 on the ESP32 can come from either side (Espressif docs) · conclusion softened to "points to the router" until its log is read · risk analysis of the 5-minute pulse added · firmware named as a confounder · unsourced −70 dBm threshold removed · cover drawing no longer claims burnt leaves, which were not measured
- : Added 21.8 h of results after the fix: the Auto-channel hypothesis was wrong, the camera dropped with the board every time, the cause is the router radio · added a step-by-step diagnosis section, a before/after drawing, and corrected the cover drawing
- : Firmware 1.7.7 installed on the board at 22:03 (previously described as being installed)