SpaIot Library
|
Public Member Functions | |
SpaServer () | |
Default constructor. | |
bool | addClient (SpaClient &client) |
Add a client to the server. More... | |
int | clientCount () const |
Return the number of clients added to the server. | |
SpaClient * | client (const String &className) const |
Return the client with the specified className. More... | |
bool | removeClient (const String &className) |
Remove a client from the server. More... | |
bool | removeClient (const char *className) |
Remove a client from the server. More... | |
bool | removeClient (const SpaClient &client) |
Remove a client from the server. More... | |
bool | begin (const ServerSettings &settings, unsigned long waitingTimeMs=BeginWaitingTimeMs) |
Start the server. More... | |
void | end () |
Stop the server. More... | |
bool | handle () |
Process spa events and handle client requests. More... | |
const ServerSettings * | settings () const |
Returns the SpaServer Settings. More... | |
virtual void | begin (unsigned long waitingTimeMs=BeginWaitingTimeMs) |
Configures each of the buttons and initializes and connect with the spa. More... | |
virtual void | begin (const HardwareSettings &hwsettings, unsigned long waitingTimeMs=BeginWaitingTimeMs) |
Configures each of the buttons and initializes and connect with the spa. More... | |
virtual void | begin (const String &hwSettingsName, unsigned long waitingTimeMs=BeginWaitingTimeMs) |
Configures each of the buttons and initializes and connect with the spa. More... | |
virtual void | begin (const BusSettings &settings, const std::map< int, LedSettings > &leds, unsigned long waitingTimeMs=BeginWaitingTimeMs) |
virtual bool | isOpen () const |
Indicates whether the connection with the spa is established. More... | |
bool | hasButton (int key) const |
Check if the hardware configuration has the button. More... | |
Button & | button (int key) |
Button. More... | |
bool | pushButton (int key) |
Press and release a button. More... | |
uint8_t | setPower (bool v=true) |
Start or stop the spa. More... | |
uint8_t | setFilter (bool v=true) |
Start or stop the water filtration. More... | |
uint8_t | setHeater (bool v=true) |
Start or stop water heating. More... | |
uint8_t | setBubble (bool v=true) |
Start or stop the the bubble generator. More... | |
uint8_t | setJet (bool v=true) |
Start or stop the water jets. More... | |
bool | setDesiredTemp (uint16_t temp) |
Setting the desired water temperature. More... | |
bool | setSanitizerTime (uint16_t time) |
Set the water sanitation time. More... | |
uint16_t | waitForDesiredTemp (unsigned long MaxWaitingTimeMs=5000) |
Press the TempUp button to read the desired temperature. More... | |
const std::map< int, ButtonSettings > | buttonSettings () const |
Button settings provides. More... | |
virtual bool | isReady () const |
Check if communication with the spa is ready, that is to say if a frame has been received. | |
bool | hasLed (int key) const |
Check if the hardware configuration has the LED. More... | |
const BusSettings & | busSettings () const |
Bus settings provides at the instantiation. More... | |
const std::map< int, LedSettings > | ledSettings () const |
Leds settings provides at the instantiation. More... | |
uint16_t | rawStatus () const |
Last state of the LEDs received. More... | |
uint8_t | isLedOn (int key) const |
Last state received from an LED. More... | |
uint8_t | isPowerOn () const |
Last state of the Power LED. More... | |
uint8_t | isFilterOn () const |
Last state of the Filter LED. More... | |
uint8_t | isBubbleOn () const |
Last state of the Bubble LED. More... | |
uint8_t | isHeatReached () const |
Last state of the HeatReached LED. More... | |
uint8_t | isJetOn () const |
Last state of the Jet LED. More... | |
uint8_t | isSanitizerOn () const |
Last state of the Sanitizer LED. More... | |
uint8_t | isHeaterOn () const |
State of water heating. More... | |
uint16_t | waterTemp () const |
Water temperature in °C. More... | |
uint16_t | desiredTemp () const |
Water temperature desired in °C. More... | |
uint16_t | sanitizerTime () const |
Remaining sanitation time. More... | |
uint32_t | frameCounter () const |
Number of frames received from startup. More... | |
uint32_t | frameDropped () const |
Number of dropped frames. More... | |
uint16_t | error () const |
Error code displayed by the control panel. More... | |
bool | isSetupModeTriggered () const |
Reset request triggered. More... | |
uint8_t | isDisplayBlink () const |
Check if the display blink. More... | |
uint8_t | waitUntilDisplayBlink (unsigned long MaxWaitingTimeMs=5000) const |
Wait until the display blink. More... | |
uint16_t | waitForWaterTemp (unsigned long MaxWaitingTimeMs=25000) const |
Wait until the water temperature could be read. More... | |
void | clearTempUnitChangeCounter () |
Clear the setup mode trigger counter. More... | |
SpaServer class.
This class is used to send and receive events to/from, control and monitor the spa from the external world. The external world is represented by a client, which can be a web browser, a mobile app or a desktop application.
Here is a schematic representation of the communication between the spa and the clients:
+-----------+ FiFo +-----------+ | | write() --> OOOOOOOO --> pullFromSpa() | | | SpaServer | | Protected | <---> External world (MQTT, HTTP, Alexa, ...) | (SPA) | read() <-- OOOOOOOO <---- pushToSpa() | API | implements the protocol with an external library +-----------+ FiFo +-----------+ [ ---------------- SpaClient ---------------- ] [ --- External library (PubSubClient, SinricPro...) ---]
The communication between server and clients is asynchronous, clients can be connected or disconnected at any time. When the spa receives a command from a client, it executes it, then if the command has modified the state of the spa, it sends an event to all connected clients.
bool SpaIot::SpaServer::addClient | ( | SpaClient & | client | ) |
|
virtualinherited |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
settings | describes the bus pins settings |
leds | describes the leds settings |
|
virtualinherited |
Configures each of the buttons and initializes and connect with the spa.
isOpen()
lets you know if the connection has been successfully completed
hwsettings | Description of hardware settings |
bool SpaIot::SpaServer::begin | ( | const ServerSettings & | settings, |
unsigned long | waitingTimeMs = BeginWaitingTimeMs |
||
) |
Start the server.
Configures each of the buttons and initializes and connect with the spa. Must be called in the setup() function after addClient()
.
settings | SpaServer settings, contains the name of the spa hardware settings that must be stored in the registry beforehand. |
|
virtualinherited |
Configures each of the buttons and initializes and connect with the spa.
isOpen()
lets you know if the connection has been successfully completed
hwSettingsName | configuration name in the register of hardware settings |
|
virtualinherited |
Configures each of the buttons and initializes and connect with the spa.
isOpen()
lets you know if the connection has been successfully completed
Reimplemented from SpaIot::FrameDecoder.
|
inherited |
Bus settings provides at the instantiation.
|
inherited |
key | button identification key in the possible values of SpaIot::Key |
|
inherited |
Button settings provides.
|
inherited |
Clear the setup mode trigger counter.
The user can trigger a reset of settings by quickly changing SpaIot::SetupTrigUnitChangeMin times the temperature unit.
SpaClient* SpaIot::SpaServer::client | ( | const String & | className | ) | const |
Return the client with the specified className.
className | the name of the client class |
|
inherited |
Water temperature desired in °C.
The desired temperature can only be known if the user has made a setting. Indeed, this temperature is only displayed when the user presses the SpaIot::TempUp or SpaIot::TempDown buttons (blinking the display).
We can use ControlPanel::waitForDesiredTemp() to perform this operation and can read a correct value.
|
virtual |
Stop the server.
This method must be called in the main loop when the server is no longer needed. It closes the server and stops the server services and the client services with SpaClient::end().
Reimplemented from SpaIot::ControlPanel.
|
inherited |
Error code displayed by the control panel.
For example, the E90 value can be displayed to indicate a water circulation problem. The user manual must be consulted for the meaning of this code.
This value is reset when calling this function if no error code has been displayed for more than 4 seconds (SpaIot::ResetErrorTimeMs).
|
inherited |
Number of frames received from startup.
|
inherited |
Number of dropped frames.
If a new frame is received before decoding the previous frame is complete, this frame is lost. If the value of this counter increases rapidly is that the number of operations running under interruption by the CPU is important (the real time constraint is too high).
It is important to adjust the frequency of the CPU to its maximum value (160MHz for ESP8266).
bool SpaIot::SpaServer::handle | ( | ) |
Process spa events and handle client requests.
This method must be called periodically in the main loop.
|
inherited |
Check if the hardware configuration has the button.
key | button identification key in the possible values of SpaIot::Key |
|
inherited |
Check if the hardware configuration has the LED.
key | LED identification key in the possible values of SpaIot::Key |
|
inlineinherited |
Last state of the Bubble LED.
Lets you know if the bubble generator is started.
References SpaIot::Bubble, and SpaIot::FrameDecoder::isLedOn().
|
inherited |
Check if the display blink.
|
inlineinherited |
Last state of the Filter LED.
Lets you know if the water filtration pump is started.
References SpaIot::Filter, and SpaIot::FrameDecoder::isLedOn().
|
inherited |
State of water heating.
Indicates that the heating is started, that the temperature of the water is reached or not
|
inlineinherited |
Last state of the HeatReached LED.
Lets you know if the water temperature is greater than or equal to the desired temperature.
References SpaIot::HeatReached, and SpaIot::FrameDecoder::isLedOn().
|
inlineinherited |
Last state of the Jet LED.
Lets you know if the water jets are activated.
References SpaIot::FrameDecoder::isLedOn(), and SpaIot::Jet.
|
inherited |
Last state received from an LED.
key | LED identification key in the possible values of SpaIot::Key |
Referenced by SpaIot::FrameDecoder::isBubbleOn(), SpaIot::FrameDecoder::isFilterOn(), SpaIot::FrameDecoder::isHeatReached(), SpaIot::FrameDecoder::isJetOn(), SpaIot::FrameDecoder::isPowerOn(), and SpaIot::FrameDecoder::isSanitizerOn().
|
virtualinherited |
Indicates whether the connection with the spa is established.
begin()
succeeded and everything works returns true. Returns false if the connection to the spa is not established and no frame is received. Reimplemented from SpaIot::FrameDecoder.
|
inlineinherited |
Last state of the Power LED.
References SpaIot::FrameDecoder::isLedOn(), and SpaIot::Power.
|
inlineinherited |
Last state of the Sanitizer LED.
Lets you know if the sanitation of the water is in progress.
References SpaIot::FrameDecoder::isLedOn(), and SpaIot::Sanitizer.
|
inherited |
Reset request triggered.
The user can trigger a reset of settings by quickly changing SpaIot::SetupTrigUnitChangeMin times the temperature unit.
|
inherited |
Leds settings provides at the instantiation.
|
inherited |
Press and release a button.
key | button identification key in the possible values of SpaIot::Key |
|
inherited |
Last state of the LEDs received.
Pour la mise au point uniquement.
bool SpaIot::SpaServer::removeClient | ( | const char * | className | ) |
Remove a client from the server.
className | the name of the client class |
bool SpaIot::SpaServer::removeClient | ( | const SpaClient & | client | ) |
Remove a client from the server.
client | the client to remove |
bool SpaIot::SpaServer::removeClient | ( | const String & | className | ) |
Remove a client from the server.
className | the name of the client class |
|
inherited |
Remaining sanitation time.
|
inherited |
Start or stop the the bubble generator.
v | true for ON, false for OFF |
|
inherited |
Setting the desired water temperature.
temp | temperature in °C |
|
inherited |
Start or stop the water filtration.
v | true for ON, false for OFF |
|
inherited |
Start or stop water heating.
v | true for ON, false for OFF |
|
inherited |
Start or stop the water jets.
v | true for ON, false for OFF |
|
inherited |
Start or stop the spa.
v | true for ON, false for OFF |
|
inherited |
Set the water sanitation time.
time | Sanitation time in hours, the possible values are {0, 3, 5, 8}. 0 Disables sanitation. |
const ServerSettings* SpaIot::SpaServer::settings | ( | ) | const |
|
inherited |
Press the TempUp button to read the desired temperature.
MaxWaitingTimeMs | Maximum waiting time in milliseconds |
|
inherited |
Wait until the water temperature could be read.
Framedecoder must wait to be sure that the display does not blink and the value is stable before determining the temperature of the water.
It can take 20 seconds. waitForWaterTemp() can be used to wait for FrameDecoder to determine the temperature.
MaxWaitingTimeMs | Maximum waiting time in milliseconds |
|
inherited |
Wait until the display blink.
MaxWaitingTimeMs | Maximum waiting time in milliseconds |
|
inherited |
Water temperature in °C.
Framedecoder must wait to be sure that the display does not blink and the value is stable before determining the temperature of the water.
It can take 2 seconds. waitForWaterTemp() can be used to wait for FrameDecoder to determine the temperature. The frame decoder engine considers that the temperature is stable if the value not change during 2 seconds INIT_STABLE_WATER_COUNTER
, thus the value is only changed if it is stable for 2 seconds.