LSH-Core
A robust C++ framework for Arduino-based home automation nodes
Loading...
Searching...
No Matches
esp_com.hpp
Go to the documentation of this file.
1
21#ifndef LSHCORE_COMMUNICATION_ESP_COM_HPP
22#define LSHCORE_COMMUNICATION_ESP_COM_HPP
23
24#include <ArduinoJson.h>
25#include <stdint.h>
26
30
35namespace EspCom
36{
37 extern uint32_t lastSentPayloadTime_ms;
38 extern uint32_t lastReceivedPayloadTime_ms;
39 extern bool firstValidPayloadReceived;
40#ifndef CONFIG_MSG_PACK
42 extern size_t bytesRead;
43#endif
44
45 void init(); // Initialize serial
46 void sendJson(const JsonDocument &json); // Sends a json payload
47 auto receiveAndDispatch() -> Deserializer::DispatchResult; // Receives and processes a json payload.
48
49 // Utils
50 [[nodiscard]] auto canPing() -> bool; // Returns if the device can send ping or not
51 void updateLastSentTime(); // Set last time payload has been sent to now
52 [[nodiscard]] auto isConnected() -> bool; // Returns if esp is connected or not
53} // namespace EspCom
54
55#endif // LSHCORE_COMMUNICATION_ESP_COM_HPP
Defines build-time configurable parameters for serial communication.
Declares the function to deserialize and dispatch commands received from the ESP bridge.
Perform communication via Serial.
Definition esp_com.cpp:30
uint32_t lastReceivedPayloadTime_ms
Last time a valid payload has been received.
Definition esp_com.cpp:34
auto receiveAndDispatch() -> Deserializer::DispatchResult
Reads from the communication serial port, processes complete messages, and dispatches commands.
Definition esp_com.cpp:79
size_t bytesRead
Number of bytes currently in the inputBuffer.
Definition esp_com.cpp:38
uint32_t lastSentPayloadTime_ms
Last time a payload has been sent.
Definition esp_com.cpp:33
bool firstValidPayloadReceived
True after the first valid payload has been received.
Definition esp_com.cpp:35
auto canPing() -> bool
Ping minimum interval check.
Definition esp_com.cpp:159
void updateLastSentTime()
Set last time payload has been sent to now.
Definition esp_com.cpp:170
auto isConnected() -> bool
Checks if the ESP is considered connected.
Definition esp_com.cpp:185
void sendJson(const JsonDocument &json)
Sends a JsonDocument via Serial.
Definition esp_com.cpp:56
char inputBuffer[constants::espComConfigs::RAW_INPUT_BUFFER_SIZE]
Raw buffer for incoming serial data.
Definition esp_com.cpp:37
void init()
Init serial.
Definition esp_com.cpp:45
constexpr uint16_t RAW_INPUT_BUFFER_SIZE
Final allocated size for the raw serial input buffer.
Definition config.hpp:93
Represents the result of a dispatch operation.
Definition deserializer.hpp:36
Internal bridge that imports user-defined macros into the library's scope.