ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
webserver.cpp File Reference
#include "webserver.hpp"
#include <Arduino.h>
#include <ArduinoLog.h>
#include <WebServer.h>

Go to the source code of this file.

Functions

IrrigationCommand_State GetSolenoidState ()
 Get the current solenoid state.
 
void SetSolenoidState (IrrigationCommand_State newState)
 Set the solenoid state.
 
float GetCurrentMoisture ()
 
void SetCurrentMoisture (float moisture)
 
void UpdateTimedOperation ()
 
void HandleOpen ()
 Handles POST requests to /on.
 
void HandleClose ()
 Handles POST requests to /off.
 
void HandleTimed ()
 Handles POST requests to /timed.
 
void HandleAutoIrrigationSetup ()
 Handles auto irrigation configuration.
 
void HandleAutoToggle ()
 Handles auto irrigation toggle.
 
void HandleStatus ()
 Handles requests to /state.
 
void HandleState ()
 Handles requests to /state.
 
void HandleMoisture ()
 
void HandleClient ()
 Handle requests from the webserver.
 
void SetupServer ()
 Setup endpoints for the webserver.
 

Variables

IrrigationCommand_State currentSolenoidState = IrrigationCommand_State_CLOSE
 
unsigned long timedStartTime = 0
 
unsigned long timedDuration = 0
 
bool timedOperation = false
 
float moisture_min_threshold
 
float moisture_max_threshold
 
unsigned long check_interval
 
float current_moisture = -1.0
 
bool auto_irrigation_enabled
 
unsigned long last_moisture_check = 0
 
const unsigned long MOISTURE_CHECK_INTERVAL = 300000
 

Function Documentation

◆ GetCurrentMoisture()

float GetCurrentMoisture ( )

Definition at line 39 of file webserver.cpp.

References GetCurrentMoistureFromCache().

Referenced by HandleStatus().

◆ GetSolenoidState()

IrrigationCommand_State GetSolenoidState ( )

Get the current solenoid state.

Definition at line 30 of file webserver.cpp.

References currentSolenoidState.

Referenced by CheckIrrigationConditions(), HandleState(), and HandleStatus().

◆ HandleAutoIrrigationSetup()

void HandleAutoIrrigationSetup ( )

Handles auto irrigation configuration.

Definition at line 163 of file webserver.cpp.

References EnableAutoIrrigation(), GetCheckInterval(), and SetCheckInterval().

Referenced by SetupServer().

◆ HandleAutoToggle()

void HandleAutoToggle ( )

Handles auto irrigation toggle.

Definition at line 184 of file webserver.cpp.

References DisableAutoIrrigation(), EnableAutoIrrigation(), GetMaxThreshold(), GetMinThreshold(), and SetSolenoidState().

Referenced by SetupServer().

◆ HandleClient()

void HandleClient ( )

Handle requests from the webserver.

Definition at line 103 of file webserver.cpp.

References UpdateTimedOperation().

Referenced by loop().

◆ HandleClose()

void HandleClose ( )

Handles POST requests to /off.

Forces the valve into the closd state.

Definition at line 127 of file webserver.cpp.

References SetSolenoidState(), and timedOperation.

Referenced by SetupServer().

◆ HandleMoisture()

void HandleMoisture ( )

Definition at line 233 of file webserver.cpp.

References CheckIrrigationConditions(), IsAutoIrrigationEnabled(), and SetCurrentMoisture().

Referenced by SetupServer().

◆ HandleOpen()

void HandleOpen ( )

Handles POST requests to /on.

Forces the valve into the open state.

Definition at line 120 of file webserver.cpp.

References SetSolenoidState(), and timedOperation.

Referenced by HandleTimed(), and SetupServer().

◆ HandleState()

void HandleState ( )

Handles requests to /state.

Gets the current state of the valve.

Definition at line 225 of file webserver.cpp.

References GetSolenoidState().

Referenced by SetupServer().

◆ HandleStatus()

void HandleStatus ( )

Handles requests to /state.

Gets the current status of the auto irrigation.

Definition at line 203 of file webserver.cpp.

References GetCheckInterval(), GetCurrentMoisture(), GetMaxThreshold(), GetMinThreshold(), GetSolenoidState(), and IsAutoIrrigationEnabled().

Referenced by SetupServer().

◆ HandleTimed()

void HandleTimed ( )

Handles POST requests to /timed.

Opens the valve for a specified time. If the valve is already open, it will closed afer the specified amount of time.

Definition at line 134 of file webserver.cpp.

References HandleOpen(), timedDuration, timedOperation, and timedStartTime.

Referenced by SetupServer().

◆ SetCurrentMoisture()

void SetCurrentMoisture ( float  moisture)

Definition at line 41 of file webserver.cpp.

References current_moisture.

Referenced by HandleMoisture().

◆ SetSolenoidState()

void SetSolenoidState ( IrrigationCommand_State  newState)

Set the solenoid state.

Definition at line 33 of file webserver.cpp.

References currentSolenoidState.

Referenced by CheckIrrigationConditions(), HandleAutoToggle(), HandleClose(), HandleOpen(), and UpdateTimedOperation().

◆ SetupServer()

void SetupServer ( )

Setup endpoints for the webserver.

Definition at line 108 of file webserver.cpp.

References HandleAutoIrrigationSetup(), HandleAutoToggle(), HandleClose(), HandleMoisture(), HandleOpen(), HandleState(), HandleStatus(), and HandleTimed().

Referenced by setup().

◆ UpdateTimedOperation()

void UpdateTimedOperation ( )

Definition at line 47 of file webserver.cpp.

References SetSolenoidState(), timedDuration, timedOperation, and timedStartTime.

Referenced by HandleClient().

Variable Documentation

◆ auto_irrigation_enabled

◆ check_interval

unsigned long check_interval
extern

◆ current_moisture

float current_moisture = -1.0

Definition at line 23 of file webserver.cpp.

Referenced by SetCurrentMoisture().

◆ currentSolenoidState

IrrigationCommand_State currentSolenoidState = IrrigationCommand_State_CLOSE

Definition at line 10 of file webserver.cpp.

Referenced by GetSolenoidState(), and SetSolenoidState().

◆ last_moisture_check

unsigned long last_moisture_check = 0

Definition at line 26 of file webserver.cpp.

◆ MOISTURE_CHECK_INTERVAL

const unsigned long MOISTURE_CHECK_INTERVAL = 300000

Definition at line 27 of file webserver.cpp.

◆ moisture_max_threshold

float moisture_max_threshold
extern

◆ moisture_min_threshold

float moisture_min_threshold
extern

◆ timedDuration

unsigned long timedDuration = 0

Definition at line 14 of file webserver.cpp.

Referenced by HandleTimed(), and UpdateTimedOperation().

◆ timedOperation

bool timedOperation = false

Definition at line 15 of file webserver.cpp.

Referenced by HandleClose(), HandleOpen(), HandleTimed(), and UpdateTimedOperation().

◆ timedStartTime

unsigned long timedStartTime = 0

Definition at line 13 of file webserver.cpp.

Referenced by HandleTimed(), and UpdateTimedOperation().