7static WebServer server(80);
35 Log.noticeln(
"Solenoid state changed to: %d", newState);
43 Log.noticeln(
"Received moisture reading: %.1f%%", moisture);
49 Log.noticeln(
"Timed operation completed, closing valve");
104 server.handleClient();
121 Log.noticeln(
"Opening valve");
124 server.send(200,
"text/plain",
"Opening valve");
128 Log.noticeln(
"Closing valve");
131 server.send(200,
"text/plain",
"Closing valve");
137 if (server.hasArg(
"time")) {
138 String time_str = server.arg(
"time");
139 time = time_str.toInt();
141 Log.errorln(
"Timed opening valve: no time specified");
142 server.send(400,
"text/plain",
"No time specified");
147 Log.errorln(
"Invalid time specified: %d", time);
148 server.send(400,
"text/plain",
"Invalid time specified");
152 Log.noticeln(
"Opening valve for %d seconds", time);
160 server.send(200,
"text/plain",
"Valve opened for set duration");
164 if (server.hasArg(
"min") && server.hasArg(
"max")) {
165 float min_thresh = server.arg(
"min").toFloat();
166 float max_thresh = server.arg(
"max").toFloat();
170 if (server.hasArg(
"interval")) {
175 "Auto irrigation configured: Min=%.1f%%, Max=%.1f%%, Interval=%lu min",
177 server.send(200,
"text/plain",
"Auto irrigation configured");
179 Log.errorln(
"Auto irrigation setup missing parameters");
180 server.send(400,
"text/plain",
"Missing min/max parameters");
185 if (server.hasArg(
"enable")) {
186 bool enable = server.arg(
"enable") ==
"true";
194 IrrigationCommand_State_CLOSE);
196 Log.noticeln(
"Auto irrigation %s", enable ?
"enabled" :
"disabled");
197 server.send(200,
"text/plain", enable ?
"Auto enabled" :
"Auto disabled");
199 server.send(400,
"text/plain",
"Missing enable parameter");
209 "\"solenoid_state\":\"" +
213 json +=
"\"auto_irrigation_enabled\":" +
219 json +=
"\"current_moisture\":" + String(current_moisture_value, 2);
222 server.send(200,
"application/json", json);
228 (currentState == IrrigationCommand_State_OPEN) ?
"open" :
"closed";
229 Log.noticeln(
"Current state: %s (%d)", stateStr.c_str(), currentState);
230 server.send(200,
"text/plain", stateStr);
234 if (server.hasArg(
"moisture")) {
235 float moisture = server.arg(
"moisture").toFloat();
241 "New moisture reading received, triggering irrigation check");
245 server.send(200,
"text/plain",
"Moisture received");
247 Log.errorln(
"Moisture endpoint missing parameter");
248 server.send(400,
"text/plain",
"Missing moisture parameter");
void HandleStatus()
Handles requests to /state.
IrrigationCommand_State GetSolenoidState()
Get the current solenoid state.
void SetupServer()
Setup endpoints for the webserver.
unsigned long check_interval
bool auto_irrigation_enabled
void HandleAutoToggle()
Handles auto irrigation toggle.
void HandleOpen()
Handles POST requests to /on.
void SetCurrentMoisture(float moisture)
float moisture_min_threshold
void HandleClose()
Handles POST requests to /off.
float GetCurrentMoisture()
float moisture_max_threshold
void HandleAutoIrrigationSetup()
Handles auto irrigation configuration.
void SetSolenoidState(IrrigationCommand_State newState)
Set the solenoid state.
void HandleState()
Handles requests to /state.
unsigned long timedDuration
const unsigned long MOISTURE_CHECK_INTERVAL
unsigned long last_moisture_check
void HandleClient()
Handle requests from the webserver.
IrrigationCommand_State currentSolenoidState
void HandleTimed()
Handles POST requests to /timed.
unsigned long timedStartTime
void UpdateTimedOperation()
void SetCheckInterval(unsigned long interval_ms)
void EnableAutoIrrigation(float min_thresh, float max_thresh)
bool IsAutoIrrigationEnabled()
float GetCurrentMoistureFromCache()
unsigned long GetCheckInterval()
void CheckIrrigationConditions()
void DisableAutoIrrigation()