SpaIot Library
SpaIot::SpaServer

SpaServer class. More...

Inheritance diagram for SpaIot::SpaServer:

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.
 
SpaClientclient (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 ServerSettingssettings () 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...
 
Buttonbutton (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, ButtonSettingsbuttonSettings () 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 BusSettingsbusSettings () const
 Bus settings provides at the instantiation. More...
 
const std::map< int, LedSettingsledSettings () 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...
 

Detailed Description

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.

Warning
Thus a client must not block its process to wait for an event from the spa or the system will be blocked.

Member Function Documentation

◆ addClient()

bool SpaIot::SpaServer::addClient ( SpaClient client)

Add a client to the server.

Must be called in the setup() function before begin().

Parameters
clientSpaClient to add
Returns
true if the client is added successfully, false otherwise

◆ begin() [1/5]

virtual void SpaIot::FrameDecoder::begin ( const BusSettings settings,
const std::map< int, LedSettings > &  leds,
unsigned long  waitingTimeMs = BeginWaitingTimeMs 
)
virtualinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
settingsdescribes the bus pins settings
ledsdescribes the leds settings

◆ begin() [2/5]

virtual void SpaIot::ControlPanel::begin ( const HardwareSettings hwsettings,
unsigned long  waitingTimeMs = BeginWaitingTimeMs 
)
virtualinherited

Configures each of the buttons and initializes and connect with the spa.

isOpen() lets you know if the connection has been successfully completed

Parameters
hwsettingsDescription of hardware settings

◆ begin() [3/5]

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().

Warning
All clients must be added and its begin() method must be called before calling this method.
Parameters
settingsSpaServer settings, contains the name of the spa hardware settings that must be stored in the registry beforehand.
Returns
true if the server is started successfully, false otherwise

◆ begin() [4/5]

virtual void SpaIot::ControlPanel::begin ( const String &  hwSettingsName,
unsigned long  waitingTimeMs = BeginWaitingTimeMs 
)
virtualinherited

Configures each of the buttons and initializes and connect with the spa.

isOpen() lets you know if the connection has been successfully completed

Parameters
hwSettingsNameconfiguration name in the register of hardware settings

◆ begin() [5/5]

virtual void SpaIot::ControlPanel::begin ( unsigned long  waitingTimeMs = BeginWaitingTimeMs)
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.

◆ busSettings()

const BusSettings& SpaIot::FrameDecoder::busSettings ( ) const
inherited

Bus settings provides at the instantiation.

Returns
constant reference on settings

◆ button()

Button& SpaIot::ControlPanel::button ( int  key)
inherited

Button.

Parameters
keybutton identification key in the possible values of SpaIot::Key
Returns
refernce on the button

◆ buttonSettings()

const std::map<int, ButtonSettings> SpaIot::ControlPanel::buttonSettings ( ) const
inherited

Button settings provides.

Returns
Constant reference on the std::map containing the button settings. The different key values are defined by SpaIot::Key

◆ clearTempUnitChangeCounter()

void SpaIot::FrameDecoder::clearTempUnitChangeCounter ( )
inherited

Clear the setup mode trigger counter.

The user can trigger a reset of settings by quickly changing SpaIot::SetupTrigUnitChangeMin times the temperature unit.

See also
SpaIot::SetupTrigUnitChangeMin This function can be used to clear the counter if the user wants to ignore the trigger.

◆ client()

SpaClient* SpaIot::SpaServer::client ( const String &  className) const

Return the client with the specified className.

Parameters
classNamethe name of the client class
Returns
the client with the specified className, or nullptr if not found

◆ desiredTemp()

uint16_t SpaIot::FrameDecoder::desiredTemp ( ) const
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.

Returns
Water temperature desired in °C, UnsetValue16 if it has not been determined yet.

◆ end()

void SpaIot::SpaServer::end ( )
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.

◆ error()

uint16_t SpaIot::FrameDecoder::error ( ) const
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).

Returns
The error code, 0 in normal situation

◆ frameCounter()

uint32_t SpaIot::FrameDecoder::frameCounter ( ) const
inherited

Number of frames received from startup.

Returns
Number of frames received including the frames dropped

◆ frameDropped()

uint32_t SpaIot::FrameDecoder::frameDropped ( ) const
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).

Returns
Number of frames dropped

◆ handle()

bool SpaIot::SpaServer::handle ( )

Process spa events and handle client requests.

This method must be called periodically in the main loop.

Returns
true if an event has been processed, false otherwise

◆ hasButton()

bool SpaIot::ControlPanel::hasButton ( int  key) const
inherited

Check if the hardware configuration has the button.

Parameters
keybutton identification key in the possible values of SpaIot::Key
Returns
true if the button exists, false otherwise

◆ hasLed()

bool SpaIot::FrameDecoder::hasLed ( int  key) const
inherited

Check if the hardware configuration has the LED.

Parameters
keyLED identification key in the possible values of SpaIot::Key
Returns
true if the LED exists

◆ isBubbleOn()

uint8_t SpaIot::FrameDecoder::isBubbleOn ( ) const
inlineinherited

Last state of the Bubble LED.

Lets you know if the bubble generator is started.

Returns
true if the LED is lit, false if it is off, UnsetValue8 if this LED does not exist or if no frame has been received.

References SpaIot::Bubble, and SpaIot::FrameDecoder::isLedOn().

◆ isDisplayBlink()

uint8_t SpaIot::FrameDecoder::isDisplayBlink ( ) const
inherited

Check if the display blink.

Returns
true if blinking, false if not, UnsetValue8 if no frame has been received.

◆ isFilterOn()

uint8_t SpaIot::FrameDecoder::isFilterOn ( ) const
inlineinherited

Last state of the Filter LED.

Lets you know if the water filtration pump is started.

Returns
true if the LED is lit, false if it is off, UnsetValue8 if this LED does not exist or if no frame has been received.

References SpaIot::Filter, and SpaIot::FrameDecoder::isLedOn().

◆ isHeaterOn()

uint8_t SpaIot::FrameDecoder::isHeaterOn ( ) const
inherited

State of water heating.

Indicates that the heating is started, that the temperature of the water is reached or not

Returns
true if the heater is started, false if it is off, UnsetValue8 if no frame has been received.

◆ isHeatReached()

uint8_t SpaIot::FrameDecoder::isHeatReached ( ) const
inlineinherited

Last state of the HeatReached LED.

Lets you know if the water temperature is greater than or equal to the desired temperature.

Returns
true if the LED is lit, false if it is off, UnsetValue8 if this LED does not exist or if no frame has been received.

References SpaIot::HeatReached, and SpaIot::FrameDecoder::isLedOn().

◆ isJetOn()

uint8_t SpaIot::FrameDecoder::isJetOn ( ) const
inlineinherited

Last state of the Jet LED.

Lets you know if the water jets are activated.

Returns
true if the LED is lit, false if it is off, UnsetValue8 if this LED does not exist or if no frame has been received.

References SpaIot::FrameDecoder::isLedOn(), and SpaIot::Jet.

◆ isLedOn()

uint8_t SpaIot::FrameDecoder::isLedOn ( int  key) const
inherited

Last state received from an LED.

Parameters
keyLED identification key in the possible values of SpaIot::Key
Returns
true if the LED is lit, false if it is off, UnsetValue8 if this LED does not exist or if no frame has been received.

Referenced by SpaIot::FrameDecoder::isBubbleOn(), SpaIot::FrameDecoder::isFilterOn(), SpaIot::FrameDecoder::isHeatReached(), SpaIot::FrameDecoder::isJetOn(), SpaIot::FrameDecoder::isPowerOn(), and SpaIot::FrameDecoder::isSanitizerOn().

◆ isOpen()

virtual bool SpaIot::ControlPanel::isOpen ( ) const
virtualinherited

Indicates whether the connection with the spa is established.

Returns
If 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.

◆ isPowerOn()

uint8_t SpaIot::FrameDecoder::isPowerOn ( ) const
inlineinherited

Last state of the Power LED.

Returns
true if the LED is lit, false if it is off, UnsetValue8 if this LED does not exist or if no frame has been received.

References SpaIot::FrameDecoder::isLedOn(), and SpaIot::Power.

◆ isSanitizerOn()

uint8_t SpaIot::FrameDecoder::isSanitizerOn ( ) const
inlineinherited

Last state of the Sanitizer LED.

Lets you know if the sanitation of the water is in progress.

Returns
true if the LED is lit, false if it is off, UnsetValue8 if this LED does not exist or if no frame has been received.

References SpaIot::FrameDecoder::isLedOn(), and SpaIot::Sanitizer.

◆ isSetupModeTriggered()

bool SpaIot::FrameDecoder::isSetupModeTriggered ( ) const
inherited

Reset request triggered.

The user can trigger a reset of settings by quickly changing SpaIot::SetupTrigUnitChangeMin times the temperature unit.

See also
SpaIot::SetupTrigUnitChangeMin
SpaIot::SetupTrigUnitChangeStepMaxMs
Returns
true if triggered

◆ ledSettings()

const std::map<int, LedSettings> SpaIot::FrameDecoder::ledSettings ( ) const
inherited

Leds settings provides at the instantiation.

Returns
Constant reference on the std::map containing the LED settings. The different key values are defined by SpaIot::Key

◆ pushButton()

bool SpaIot::ControlPanel::pushButton ( int  key)
inherited

Press and release a button.

Parameters
keybutton identification key in the possible values of SpaIot::Key
Returns
true if the button exists, false otherwise

◆ rawStatus()

uint16_t SpaIot::FrameDecoder::rawStatus ( ) const
inherited

Last state of the LEDs received.

Pour la mise au point uniquement.

Returns
The value corresponding to the last control frame of the LEDs, the value is the binary complement of the frame signal. UnsetValue16 is returned if no frame has been received.

◆ removeClient() [1/3]

bool SpaIot::SpaServer::removeClient ( const char *  className)

Remove a client from the server.

Parameters
classNamethe name of the client class

◆ removeClient() [2/3]

bool SpaIot::SpaServer::removeClient ( const SpaClient client)

Remove a client from the server.

Parameters
clientthe client to remove

◆ removeClient() [3/3]

bool SpaIot::SpaServer::removeClient ( const String &  className)

Remove a client from the server.

Parameters
classNamethe name of the client class

◆ sanitizerTime()

uint16_t SpaIot::FrameDecoder::sanitizerTime ( ) const
inherited

Remaining sanitation time.

Returns
Remaining sanitation time in hours, UnsetValue16 if it has not been determined yet.

◆ setBubble()

uint8_t SpaIot::ControlPanel::setBubble ( bool  v = true)
inherited

Start or stop the the bubble generator.

Parameters
vtrue for ON, false for OFF
Returns
the state returned by isBubbleOn()

◆ setDesiredTemp()

bool SpaIot::ControlPanel::setDesiredTemp ( uint16_t  temp)
inherited

Setting the desired water temperature.

Parameters
temptemperature in °C
Returns

◆ setFilter()

uint8_t SpaIot::ControlPanel::setFilter ( bool  v = true)
inherited

Start or stop the water filtration.

Parameters
vtrue for ON, false for OFF
Returns
the state returned by isFilterOn()

◆ setHeater()

uint8_t SpaIot::ControlPanel::setHeater ( bool  v = true)
inherited

Start or stop water heating.

Parameters
vtrue for ON, false for OFF
Returns
the state returned by isHeaterOn()

◆ setJet()

uint8_t SpaIot::ControlPanel::setJet ( bool  v = true)
inherited

Start or stop the water jets.

Parameters
vtrue for ON, false for OFF
Returns
the state returned by isJetOn()

◆ setPower()

uint8_t SpaIot::ControlPanel::setPower ( bool  v = true)
inherited

Start or stop the spa.

Parameters
vtrue for ON, false for OFF
Returns
the state returned by isPowerOn()

◆ setSanitizerTime()

bool SpaIot::ControlPanel::setSanitizerTime ( uint16_t  time)
inherited

Set the water sanitation time.

Parameters
timeSanitation time in hours, the possible values are {0, 3, 5, 8}. 0 Disables sanitation.
Returns
true if the setting has been made, false if the requested value is invalid.

◆ settings()

const ServerSettings* SpaIot::SpaServer::settings ( ) const

Returns the SpaServer Settings.

Returns
the SpaServer Settings, or nullptr if not set

◆ waitForDesiredTemp()

uint16_t SpaIot::ControlPanel::waitForDesiredTemp ( unsigned long  MaxWaitingTimeMs = 5000)
inherited

Press the TempUp button to read the desired temperature.

Parameters
MaxWaitingTimeMsMaximum waiting time in milliseconds
Returns
Water temperature desired in °C, UnsetValue16 if it has not been determined yet.

◆ waitForWaterTemp()

uint16_t SpaIot::FrameDecoder::waitForWaterTemp ( unsigned long  MaxWaitingTimeMs = 25000) const
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.

Parameters
MaxWaitingTimeMsMaximum waiting time in milliseconds
Returns
Water temperature in °C, UnsetValue16 if it has not been determined yet.

◆ waitUntilDisplayBlink()

uint8_t SpaIot::FrameDecoder::waitUntilDisplayBlink ( unsigned long  MaxWaitingTimeMs = 5000) const
inherited

Wait until the display blink.

Parameters
MaxWaitingTimeMsMaximum waiting time in milliseconds
Returns
true if blinking, false if not, UnsetValue8 if no frame has been received.

◆ waterTemp()

uint16_t SpaIot::FrameDecoder::waterTemp ( ) const
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.

Returns
Water temperature in °C, UnsetValue16 if it has not been determined yet.