LSH-Core
A robust C++ framework for Arduino-based home automation nodes
Loading...
Searching...
No Matches
EspCom Namespace Reference

Perform communication via Serial. More...

Functions

void init ()
 Init serial.
 
void sendJson (const JsonDocument &json)
 Sends a JsonDocument via Serial.
 
auto receiveAndDispatch () -> Deserializer::DispatchResult
 Reads from the communication serial port, processes complete messages, and dispatches commands.
 
auto canPing () -> bool
 Ping minimum interval check.
 
void updateLastSentTime ()
 Set last time payload has been sent to now.
 
auto isConnected () -> bool
 Checks if the ESP is considered connected.
 

Variables

uint32_t lastSentPayloadTime_ms = 0U
 Last time a payload has been sent.
 
uint32_t lastReceivedPayloadTime_ms = 0U
 Last time a valid payload has been received.
 
bool firstValidPayloadReceived = false
 True after the first valid payload has been received.
 
char inputBuffer [constants::espComConfigs::RAW_INPUT_BUFFER_SIZE]
 Raw buffer for incoming serial data.
 
size_t bytesRead = 0
 Number of bytes currently in the inputBuffer.
 

Detailed Description

Perform communication via Serial.

Function Documentation

◆ canPing()

auto EspCom::canPing ( ) -> bool

Ping minimum interval check.

Returns
true if the device can send ping.
false if the device can't send ping.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isConnected()

auto EspCom::isConnected ( ) -> bool

Checks if the ESP is considered connected.

The assumption is based on having received a valid payload (like a PING or any other command) within the defined CONNECTION_TIMEOUT_MS.

Returns
true if the ESP is connected.
false if the ESP is not connected (or timed out).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ receiveAndDispatch()

auto EspCom::receiveAndDispatch ( ) -> Deserializer::DispatchResult

Reads from the communication serial port, processes complete messages, and dispatches commands.

This function handles both MsgPack and JSON-newline protocols based on compilation flags. For JSON, it buffers incoming bytes until a newline is detected, then parses the message. For MsgPack, it attempts to deserialize directly from the stream. Upon receiving a valid message, it calls Deserializer::deserializeAndDispatch to execute the command.

Returns
Deserializer::DispatchResult A struct indicating if the command changed the device state.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendJson()

void EspCom::sendJson ( const JsonDocument &  json)

Sends a JsonDocument via Serial.

Parameters
jsonJsonDocument to be sent.
Here is the call graph for this function:
Here is the caller graph for this function: