SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::SKWSClient Class Reference

The websocket connection to the Signal K server. More...

#include <sensesp/signalk/signalk_ws_client.h>

Inheritance diagram for sensesp::SKWSClient:
[legend]

Classes

struct  ReceivedUpdate
 A single received delta entry awaiting dispatch on the main task. More...
 

Public Member Functions

 SKWSClient (const String &config_path, std::shared_ptr< SKDeltaQueue > sk_delta_queue, const String &server_address, uint16_t server_port, bool use_mdns=true)
 
const String get_server_address () const
 
uint16_t get_server_port () const
 
virtual bool to_json (JsonObject &root) override final
 
virtual bool from_json (const JsonObject &config) override final
 
ValueProducer< int > & get_delta_tx_count_producer ()
 
ValueProducer< int > & get_delta_rx_count_producer ()
 Get the delta rx count producer object.
 
String get_connection_status ()
 Get a String representation of the current connection state.
 
void on_disconnected ()
 Called when the websocket connection is disconnected.
 
void on_error (int handshake_status)
 
void on_connected ()
 Called when the websocket connection is established.
 
void on_receive_delta (uint8_t *payload, size_t length)
 Called when the websocket receives a delta.
 
void on_receive_updates (JsonDocument &message)
 Called when a delta update is received.
 
void on_receive_put (JsonDocument &message)
 Called when a PUT event is received.
 
void connect ()
 
void loop ()
 
bool is_connected ()
 
void restart ()
 Drop the current connection (detached, non-blocking teardown) and let the reconnect path rebuild it.
 
bool is_connect_due () const
 
void send_delta ()
 
void sendTXT (String &payload)
 Send some processed data to the websocket.
 
bool is_ssl_enabled () const
 Check if SSL/TLS is enabled.
 
String get_auth_token () const
 Current Signal K access token, or an empty string if none.
 
void set_ssl_enabled (bool enabled)
 Enable or disable SSL/TLS manually.
 
bool is_send_meta_enabled () const
 Whether the WS subscribes with sendMeta=all.
 
void set_send_meta_enabled (bool enabled)
 
bool is_tofu_enabled () const
 Check if TOFU certificate verification is enabled.
 
void set_tofu_enabled (bool enabled)
 Enable or disable TOFU certificate verification.
 
bool has_tofu_anchor () const
 True if any trust anchor (pinned CA or leaf fingerprint) is stored.
 
bool has_tofu_ca () const
 True if a pinned CA certificate is stored (CA-anchor mode).
 
const String & get_tofu_ca () const
 
bool has_tofu_fingerprint () const
 True if a pinned leaf fingerprint is stored (leaf-fingerprint mode).
 
const String & get_tofu_fingerprint () const
 
const String & get_tofu_pin_cn () const
 Identity (CN) of whatever is pinned, and whether it is a CA.
 
bool is_tofu_pin_ca () const
 
const String & get_tofu_san () const
 TOFU'd leaf identity (normalized DNS SAN set) bound in CA-anchor mode. A reconnecting leaf must chain to the pinned CA AND present this same identity, so a different leaf from the same CA is rejected. Empty in leaf-fingerprint mode (the fingerprint already binds identity).
 
void reset_tofu ()
 Reset the stored trust anchor (CA or leaf fingerprint).
 
void stash_pending_ca (const String &ca_pem, const String &cn)
 Stash a candidate anchor seen during a handshake. Persisted only after the connection succeeds (commit_pending_tofu), so an unauthenticated MITM handshake cannot plant a trust anchor.
 
void stash_pending_leaf (const String &fingerprint, const String &cn)
 
void set_pending_san (const String &san)
 Record the leaf's identity (SAN set) for the pending CA anchor, captured at depth 0 and committed alongside the CA on success.
 
void clear_pending_tofu ()
 
bool has_pending_ca () const
 True if a candidate CA has already been stashed this handshake.
 
void commit_pending_tofu ()
 Persist a stashed anchor after a successful (authenticated) connection. Called from on_connected().
 
void flag_cert_error ()
 Flag a certificate rejection from the verify callback so the next disconnect surfaces as kSKWSCertificateError rather than a plain disconnect.
 
uint32_t client_generation () const
 Generation tag of the currently-valid client. The event handler compares the generation it was registered with against this to drop callbacks from a client that has been handed off for destruction.
 
- Public Member Functions inherited from sensesp::FileSystemSaveable
 FileSystemSaveable (const String &config_path)
 
virtual bool load () override
 Load and populate the object from a persistent storage.
 
virtual bool save () override
 Save the object to a persistent storage.
 
virtual bool clear () override
 Delete the data from a persistent storage.
 
bool find_config_file (const String &config_path, String &filename)
 
- Public Member Functions inherited from sensesp::Saveable
 Saveable (const String &config_path)
 
virtual bool refresh ()
 Refresh the object. This may or may not access the persistent storage but is not expected to overwrite the object's state.
 
const String & get_config_path () const
 
- Public Member Functions inherited from sensesp::ValueProducer< SKWSConnectionState >
 ValueProducer ()
 
 ValueProducer (const SKWSConnectionState &initial_value)
 
virtual const SKWSConnectionStateget () const
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< SKWSConnectionState, typenameVConsumer::input_type >::value, std::shared_ptr< VConsumer > >::type connect_to (std::shared_ptr< VConsumer > consumer)
 Connect a producer to a transform with a different input type.
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< SKWSConnectionState, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to (VConsumer *consumer)
 
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< SKWSConnectionState, typenameVConsumer::input_type >::value, VConsumer * >::type connect_to (VConsumer &consumer)
 
void emit (const SKWSConnectionState &new_value)
 
- Public Member Functions inherited from sensesp::Observable
 Observable ()
 
 Observable (Observable &&other)
 Move constructor.
 
void notify ()
 
int attach (std::function< void()> observer)
 Attach an observer callback.
 
void detach (int id)
 Remove a previously attached observer by its ID.
 

Protected Member Functions

bool take_received_updates_semaphore (unsigned long int timeout_ms=0)
 
void release_received_updates_semaphore ()
 
void enqueue_received_update (ReceivedUpdate &&update)
 Push a received delta entry onto the queue, enforcing a per-kind budget so a metadata burst (one meta-delta per subscribed path at subscribe time when sendMeta=all is enabled) cannot evict pending value deltas, and vice versa. Caller must hold received_updates_semaphore_.
 
void process_received_updates ()
 Loop through the received updates and process them.
 
void test_token (const String host, const uint16_t port)
 
void send_access_request (const String host, const uint16_t port)
 
void poll_access_request (const String host, const uint16_t port, const String href)
 
void connect_ws (const String &host, const uint16_t port)
 
void detach_teardown ()
 Hand client_ to a detached one-shot task that stops+destroys it, so the blocking teardown never runs on the caller's context. Nulls client_ and bumps client_generation_ / sets teardown_in_progress_ immediately; no-op if client_ is null. If the reaper task can't be spawned (OOM), the handle is stashed in pending_teardown_ and the spawn is retried on the next event-loop tick – never reaped synchronously, which would block the loop.
 
void reap_async (esp_websocket_client_handle_t old)
 Spawn the detached reaper for old; on spawn failure (OOM) stash it in pending_teardown_ for a later retry instead of blocking the loop with a synchronous reap. No-op if old is null. Call on the event-loop context.
 
void run_connect_attempt ()
 The (blocking) connect attempt — mDNS resolve, SSL detect, and the access-request / poll / connect_ws leg. Run on a one-shot worker task so none of it blocks the SK/event-loop context. connect() is the dispatcher.
 
void subscribe_listeners ()
 Subscribes the SK delta paths to the websocket.
 
bool get_mdns_service (String &server_address, uint16_t &server_port)
 
bool detect_ssl ()
 
void set_connection_state (SKWSConnectionState state)
 
SKWSConnectionState get_connection_state ()
 
void schedule_reconnect ()
 
void reset_reconnect_interval ()
 

Static Protected Member Functions

static void teardown_task (void *arg)
 Body of the detached teardown task (stop+destroy+self-delete).
 
static void connect_worker (void *arg)
 

Protected Attributes

String server_address_ = ""
 
uint16_t server_port_ = 80
 
String conf_server_address_ = ""
 
uint16_t conf_server_port_ = 0
 
bool use_mdns_ = true
 
String client_id_ = ""
 
String polling_href_ = ""
 
String auth_token_ = NULL_AUTH_TOKEN
 
unsigned long next_attempt_ms_ = 0
 
unsigned long connect_interval_ms_ = 2000
 
bool ssl_enabled_ = false
 
bool tofu_enabled_ = true
 
bool send_meta_enabled_ = true
 
String tofu_fingerprint_ = ""
 
String tofu_ca_pem_ = ""
 
String tofu_san_ = ""
 
String tofu_pin_cn_ = ""
 
bool tofu_pin_is_ca_ = false
 
String pending_ca_pem_ = ""
 
String pending_fingerprint_ = ""
 
String pending_cn_ = ""
 
String pending_san_ = ""
 
bool pending_is_ca_ = false
 
bool pending_valid_ = false
 
std::atomic< bool > cert_error_ {false}
 
TaskQueueProducer< SKWSConnectionStateconnection_state_
 
SKWSConnectionState task_connection_state_
 
std::atomic< esp_websocket_client_handle_t > client_ {nullptr}
 
std::atomic< uint32_t > client_generation_ {0}
 
std::atomic< bool > teardown_in_progress_ {false}
 
std::atomic< bool > auth_job_running_ {false}
 
std::atomic< esp_websocket_client_handle_t > pending_teardown_ {nullptr}
 
std::shared_ptr< SKDeltaQueuesk_delta_queue_
 
TaskQueueProducer< int > delta_tx_tick_producer_ {0, event_loop(), 990}
 Emits the number of deltas sent since last report.
 
Integrator< int, int > delta_tx_count_producer_ {1, 0, ""}
 
Integrator< int, int > delta_rx_count_producer_ {1, 0, ""}
 
uint32_t last_oversize_log_ms_ = 0
 millis() timestamp of the last oversize-delta-drop warning, used to rate-limit it when a device keeps producing a delta larger than the buffer. 0 = never logged, so the next drop logs immediately.
 
StaticSemaphore_t received_updates_semaphore_buffer_
 
SemaphoreHandle_t received_updates_semaphore_
 
std::list< ReceivedUpdatereceived_updates_ {}
 
- Protected Attributes inherited from sensesp::Saveable
const String config_path_
 
- Protected Attributes inherited from sensesp::ValueProducer< SKWSConnectionState >
SKWSConnectionState output_
 

Detailed Description

The websocket connection to the Signal K server.

See also
SensESPApp

Definition at line 80 of file signalk_ws_client.h.

Constructor & Destructor Documentation

◆ SKWSClient()

sensesp::SKWSClient::SKWSClient ( const String &  config_path,
std::shared_ptr< SKDeltaQueue sk_delta_queue,
const String &  server_address,
uint16_t  server_port,
bool  use_mdns = true 
)

Definition at line 363 of file signalk_ws_client.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ clear_pending_tofu()

void sensesp::SKWSClient::clear_pending_tofu ( )
inline

Definition at line 278 of file signalk_ws_client.h.

Here is the caller graph for this function:

◆ client_generation()

uint32_t sensesp::SKWSClient::client_generation ( ) const
inline

Generation tag of the currently-valid client. The event handler compares the generation it was registered with against this to drop callbacks from a client that has been handed off for destruction.

Definition at line 316 of file signalk_ws_client.h.

◆ commit_pending_tofu()

void sensesp::SKWSClient::commit_pending_tofu ( )
inline

Persist a stashed anchor after a successful (authenticated) connection. Called from on_connected().

Definition at line 290 of file signalk_ws_client.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect()

void sensesp::SKWSClient::connect ( )

Definition at line 889 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_worker()

void sensesp::SKWSClient::connect_worker ( void *  arg)
staticprotected

Definition at line 949 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_ws()

void sensesp::SKWSClient::connect_ws ( const String &  host,
const uint16_t  port 
)
protected

Definition at line 1378 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detach_teardown()

void sensesp::SKWSClient::detach_teardown ( )
protected

Hand client_ to a detached one-shot task that stops+destroys it, so the blocking teardown never runs on the caller's context. Nulls client_ and bumps client_generation_ / sets teardown_in_progress_ immediately; no-op if client_ is null. If the reaper task can't be spawned (OOM), the handle is stashed in pending_teardown_ and the spawn is retried on the next event-loop tick – never reaped synchronously, which would block the loop.

Definition at line 1501 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detect_ssl()

bool sensesp::SKWSClient::detect_ssl ( )
protected

Definition at line 844 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enqueue_received_update()

void sensesp::SKWSClient::enqueue_received_update ( ReceivedUpdate &&  update)
protected

Push a received delta entry onto the queue, enforcing a per-kind budget so a metadata burst (one meta-delta per subscribed path at subscribe time when sendMeta=all is enabled) cannot evict pending value deltas, and vice versa. Caller must hold received_updates_semaphore_.

Push a received delta onto the queue with a per-kind budget.

Caller must hold received_updates_semaphore_. Meta and value entries are budgeted independently so a meta burst (~one entry per subscribed path at subscribe time) cannot evict pending value deltas, and vice versa.

Parameters
update

Definition at line 629 of file signalk_ws_client.cpp.

Here is the caller graph for this function:

◆ flag_cert_error()

void sensesp::SKWSClient::flag_cert_error ( )
inline

Flag a certificate rejection from the verify callback so the next disconnect surfaces as kSKWSCertificateError rather than a plain disconnect.

Definition at line 311 of file signalk_ws_client.h.

◆ from_json()

bool sensesp::SKWSClient::from_json ( const JsonObject &  root)
finaloverridevirtual

Deserializes the current object data from a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 1604 of file signalk_ws_client.cpp.

◆ get_auth_token()

String sensesp::SKWSClient::get_auth_token ( ) const
inline

Current Signal K access token, or an empty string if none.

Returned as a bare JWT without the "Bearer " prefix. Intended for subsystems that need to piggy-back on the same SK credentials as the main delta websocket — for example, a BLE gateway that also needs to authenticate against signalk-server's provider API but does not have its own access-request flow.

Returns "" when SKWSClient has not yet obtained a token (either because the server does not require auth, or because the access-request flow is still in progress). Callers that need auth must handle the empty-string case, typically by deferring their own connect attempts until the main SK websocket is connected (which is a precondition for a valid token anyway).

Definition at line 170 of file signalk_ws_client.h.

◆ get_connection_state()

SKWSConnectionState sensesp::SKWSClient::get_connection_state ( )
inlineprotected

Definition at line 517 of file signalk_ws_client.h.

Here is the caller graph for this function:

◆ get_connection_status()

String sensesp::SKWSClient::get_connection_status ( )

Get a String representation of the current connection state.

Returns
String

Definition at line 1662 of file signalk_ws_client.cpp.

Here is the call graph for this function:

◆ get_delta_rx_count_producer()

ValueProducer< int > & sensesp::SKWSClient::get_delta_rx_count_producer ( )
inline

Get the delta rx count producer object.

Returns
ValueProducer<int>&

Definition at line 110 of file signalk_ws_client.h.

◆ get_delta_tx_count_producer()

ValueProducer< int > & sensesp::SKWSClient::get_delta_tx_count_producer ( )
inline

Return a delta update ValueProducer that produces the number of sent deltas.

Definition at line 101 of file signalk_ws_client.h.

◆ get_mdns_service()

bool sensesp::SKWSClient::get_mdns_service ( String &  server_address,
uint16_t &  server_port 
)
protected

Definition at line 800 of file signalk_ws_client.cpp.

Here is the caller graph for this function:

◆ get_server_address()

const String sensesp::SKWSClient::get_server_address ( ) const
inline

Definition at line 91 of file signalk_ws_client.h.

◆ get_server_port()

uint16_t sensesp::SKWSClient::get_server_port ( ) const
inline

Definition at line 92 of file signalk_ws_client.h.

◆ get_tofu_ca()

const String & sensesp::SKWSClient::get_tofu_ca ( ) const
inline

Definition at line 226 of file signalk_ws_client.h.

◆ get_tofu_fingerprint()

const String & sensesp::SKWSClient::get_tofu_fingerprint ( ) const
inline

Definition at line 230 of file signalk_ws_client.h.

◆ get_tofu_pin_cn()

const String & sensesp::SKWSClient::get_tofu_pin_cn ( ) const
inline

Identity (CN) of whatever is pinned, and whether it is a CA.

Definition at line 233 of file signalk_ws_client.h.

◆ get_tofu_san()

const String & sensesp::SKWSClient::get_tofu_san ( ) const
inline

TOFU'd leaf identity (normalized DNS SAN set) bound in CA-anchor mode. A reconnecting leaf must chain to the pinned CA AND present this same identity, so a different leaf from the same CA is rejected. Empty in leaf-fingerprint mode (the fingerprint already binds identity).

Definition at line 240 of file signalk_ws_client.h.

◆ has_pending_ca()

bool sensesp::SKWSClient::has_pending_ca ( ) const
inline

True if a candidate CA has already been stashed this handshake.

Definition at line 287 of file signalk_ws_client.h.

◆ has_tofu_anchor()

bool sensesp::SKWSClient::has_tofu_anchor ( ) const
inline

True if any trust anchor (pinned CA or leaf fingerprint) is stored.

Definition at line 220 of file signalk_ws_client.h.

◆ has_tofu_ca()

bool sensesp::SKWSClient::has_tofu_ca ( ) const
inline

True if a pinned CA certificate is stored (CA-anchor mode).

Definition at line 225 of file signalk_ws_client.h.

◆ has_tofu_fingerprint()

bool sensesp::SKWSClient::has_tofu_fingerprint ( ) const
inline

True if a pinned leaf fingerprint is stored (leaf-fingerprint mode).

Definition at line 229 of file signalk_ws_client.h.

◆ is_connect_due()

bool sensesp::SKWSClient::is_connect_due ( ) const
inline

Definition at line 139 of file signalk_ws_client.h.

Here is the caller graph for this function:

◆ is_connected()

bool sensesp::SKWSClient::is_connected ( )

Definition at line 1457 of file signalk_ws_client.cpp.

Here is the call graph for this function:

◆ is_send_meta_enabled()

bool sensesp::SKWSClient::is_send_meta_enabled ( ) const
inline

Whether the WS subscribes with sendMeta=all.

When true, the signalk-server pushes metadata deltas (units, zones, displayName, displayUnits, etc.) over the same WebSocket connection as value deltas, so consumers don't have to make separate REST /meta requests per path.

Defaults to true. When enabled, meta-deltas can be consumed via SKMetadataListener. Disable only if you have a constrained client that doesn't want meta-deltas at all (they are otherwise ignored by SKValueListener since meta updates carry no values array).

Definition at line 196 of file signalk_ws_client.h.

◆ is_ssl_enabled()

bool sensesp::SKWSClient::is_ssl_enabled ( ) const
inline

Check if SSL/TLS is enabled.

Definition at line 152 of file signalk_ws_client.h.

◆ is_tofu_enabled()

bool sensesp::SKWSClient::is_tofu_enabled ( ) const
inline

Check if TOFU certificate verification is enabled.

Definition at line 205 of file signalk_ws_client.h.

◆ is_tofu_pin_ca()

bool sensesp::SKWSClient::is_tofu_pin_ca ( ) const
inline

Definition at line 234 of file signalk_ws_client.h.

◆ loop()

void sensesp::SKWSClient::loop ( )

Definition at line 1024 of file signalk_ws_client.cpp.

◆ on_connected()

void sensesp::SKWSClient::on_connected ( )

Called when the websocket connection is established.

Called in the websocket task context.

Definition at line 452 of file signalk_ws_client.cpp.

Here is the call graph for this function:

◆ on_disconnected()

void sensesp::SKWSClient::on_disconnected ( )

Called when the websocket connection is disconnected.

This method is called in the websocket task context.

Definition at line 414 of file signalk_ws_client.cpp.

Here is the call graph for this function:

◆ on_error()

void sensesp::SKWSClient::on_error ( int  handshake_status)

Definition at line 428 of file signalk_ws_client.cpp.

Here is the call graph for this function:

◆ on_receive_delta()

void sensesp::SKWSClient::on_receive_delta ( uint8_t *  payload,
size_t  length 
)

Called when the websocket receives a delta.

Called in the websocket task context.

Parameters
payload

Definition at line 520 of file signalk_ws_client.cpp.

Here is the call graph for this function:

◆ on_receive_put()

void sensesp::SKWSClient::on_receive_put ( JsonDocument &  message)

Called when a PUT event is received.

Called in the websocket task context.

Parameters
message

Definition at line 730 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_receive_updates()

void sensesp::SKWSClient::on_receive_updates ( JsonDocument &  message)

Called when a delta update is received.

Called in the websocket task context.

Parameters
message

Definition at line 565 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ poll_access_request()

void sensesp::SKWSClient::poll_access_request ( const String  host,
const uint16_t  port,
const String  href 
)
protected

Definition at line 1248 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_received_updates()

void sensesp::SKWSClient::process_received_updates ( )
protected

Loop through the received updates and process them.

This method is called in the main task context.

Definition at line 667 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reap_async()

void sensesp::SKWSClient::reap_async ( esp_websocket_client_handle_t  old)
protected

Spawn the detached reaper for old; on spawn failure (OOM) stash it in pending_teardown_ for a later retry instead of blocking the loop with a synchronous reap. No-op if old is null. Call on the event-loop context.

Definition at line 1480 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ release_received_updates_semaphore()

void sensesp::SKWSClient::release_received_updates_semaphore ( )
inlineprotected

Definition at line 450 of file signalk_ws_client.h.

Here is the caller graph for this function:

◆ reset_reconnect_interval()

void sensesp::SKWSClient::reset_reconnect_interval ( )
inlineprotected

Definition at line 526 of file signalk_ws_client.h.

Here is the caller graph for this function:

◆ reset_tofu()

void sensesp::SKWSClient::reset_tofu ( )
inline

Reset the stored trust anchor (CA or leaf fingerprint).

Call this when the server's CA has changed legitimately so the device re-captures it on the next connection. Re-capture is trust-on-first-use; trigger it on a trusted network.

Definition at line 249 of file signalk_ws_client.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restart()

void sensesp::SKWSClient::restart ( )

Drop the current connection (detached, non-blocking teardown) and let the reconnect path rebuild it.

Warning
Must run on the event-loop (SK connection) context only. It does not check auth_job_running_, so calling it concurrently with a running connect worker could interleave its client_.exchange(nullptr) with the worker's client_.store(h) and orphan a live client (leak + dropped events). Has no callers today. See #1033.

Definition at line 1515 of file signalk_ws_client.cpp.

Here is the call graph for this function:

◆ run_connect_attempt()

void sensesp::SKWSClient::run_connect_attempt ( )
protected

The (blocking) connect attempt — mDNS resolve, SSL detect, and the access-request / poll / connect_ws leg. Run on a one-shot worker task so none of it blocks the SK/event-loop context. connect() is the dispatcher.

Definition at line 956 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_reconnect()

void sensesp::SKWSClient::schedule_reconnect ( )
inlineprotected

Definition at line 519 of file signalk_ws_client.h.

Here is the caller graph for this function:

◆ send_access_request()

void sensesp::SKWSClient::send_access_request ( const String  host,
const uint16_t  port 
)
protected

Definition at line 1115 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_delta()

void sensesp::SKWSClient::send_delta ( )

Definition at line 1522 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendTXT()

void sensesp::SKWSClient::sendTXT ( String &  payload)

Send some processed data to the websocket.

Sends the specified payload to the server over the websocket this client is connected to. If no connection currently exist, the call is safely ignored.

Called in the websocket task context.

Parameters
payload

Definition at line 790 of file signalk_ws_client.cpp.

Here is the call graph for this function:

◆ set_connection_state()

void sensesp::SKWSClient::set_connection_state ( SKWSConnectionState  state)
inlineprotected

Definition at line 501 of file signalk_ws_client.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_pending_san()

void sensesp::SKWSClient::set_pending_san ( const String &  san)
inline

Record the leaf's identity (SAN set) for the pending CA anchor, captured at depth 0 and committed alongside the CA on success.

Definition at line 277 of file signalk_ws_client.h.

◆ set_send_meta_enabled()

void sensesp::SKWSClient::set_send_meta_enabled ( bool  enabled)
inline

Definition at line 197 of file signalk_ws_client.h.

Here is the call graph for this function:

◆ set_ssl_enabled()

void sensesp::SKWSClient::set_ssl_enabled ( bool  enabled)
inline

Enable or disable SSL/TLS manually.

Note: SSL is normally auto-detected. Use this only if you need to override the auto-detection behavior.

Definition at line 178 of file signalk_ws_client.h.

Here is the call graph for this function:

◆ set_tofu_enabled()

void sensesp::SKWSClient::set_tofu_enabled ( bool  enabled)
inline

Enable or disable TOFU certificate verification.

When enabled, the issuing CA (or, for servers that present no CA, the leaf certificate) is captured on first connection and verified on subsequent connections.

Definition at line 214 of file signalk_ws_client.h.

Here is the call graph for this function:

◆ stash_pending_ca()

void sensesp::SKWSClient::stash_pending_ca ( const String &  ca_pem,
const String &  cn 
)
inline

Stash a candidate anchor seen during a handshake. Persisted only after the connection succeeds (commit_pending_tofu), so an unauthenticated MITM handshake cannot plant a trust anchor.

Definition at line 261 of file signalk_ws_client.h.

◆ stash_pending_leaf()

void sensesp::SKWSClient::stash_pending_leaf ( const String &  fingerprint,
const String &  cn 
)
inline

Definition at line 268 of file signalk_ws_client.h.

◆ subscribe_listeners()

void sensesp::SKWSClient::subscribe_listeners ( )
protected

Subscribes the SK delta paths to the websocket.

Called in the websocket task context.

Definition at line 470 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ take_received_updates_semaphore()

bool sensesp::SKWSClient::take_received_updates_semaphore ( unsigned long int  timeout_ms = 0)
inlineprotected

Definition at line 441 of file signalk_ws_client.h.

Here is the caller graph for this function:

◆ teardown_task()

void sensesp::SKWSClient::teardown_task ( void *  arg)
staticprotected

Body of the detached teardown task (stop+destroy+self-delete).

Definition at line 1468 of file signalk_ws_client.cpp.

Here is the caller graph for this function:

◆ test_token()

void sensesp::SKWSClient::test_token ( const String  host,
const uint16_t  port 
)
protected

Definition at line 1029 of file signalk_ws_client.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_json()

bool sensesp::SKWSClient::to_json ( JsonObject &  root)
finaloverridevirtual

Serializes the current object data into a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 1582 of file signalk_ws_client.cpp.

Member Data Documentation

◆ auth_job_running_

std::atomic<bool> sensesp::SKWSClient::auth_job_running_ {false}
protected

Definition at line 405 of file signalk_ws_client.h.

◆ auth_token_

String sensesp::SKWSClient::auth_token_ = NULL_AUTH_TOKEN
protected

Definition at line 329 of file signalk_ws_client.h.

◆ cert_error_

std::atomic<bool> sensesp::SKWSClient::cert_error_ {false}
protected

Definition at line 373 of file signalk_ws_client.h.

◆ client_

std::atomic<esp_websocket_client_handle_t> sensesp::SKWSClient::client_ {nullptr}
protected

Definition at line 393 of file signalk_ws_client.h.

◆ client_generation_

std::atomic<uint32_t> sensesp::SKWSClient::client_generation_ {0}
protected

Definition at line 398 of file signalk_ws_client.h.

◆ client_id_

String sensesp::SKWSClient::client_id_ = ""
protected

Definition at line 327 of file signalk_ws_client.h.

◆ conf_server_address_

String sensesp::SKWSClient::conf_server_address_ = ""
protected

Definition at line 323 of file signalk_ws_client.h.

◆ conf_server_port_

uint16_t sensesp::SKWSClient::conf_server_port_ = 0
protected

Definition at line 324 of file signalk_ws_client.h.

◆ connect_interval_ms_

unsigned long sensesp::SKWSClient::connect_interval_ms_ = 2000
protected

Definition at line 332 of file signalk_ws_client.h.

◆ connection_state_

TaskQueueProducer<SKWSConnectionState> sensesp::SKWSClient::connection_state_
protected
Initial value:
{
std::shared_ptr< reactesp::EventLoop > event_loop()
Definition sensesp.cpp:9

Definition at line 375 of file signalk_ws_client.h.

◆ delta_rx_count_producer_

Integrator<int, int> sensesp::SKWSClient::delta_rx_count_producer_ {1, 0, ""}
protected

Definition at line 415 of file signalk_ws_client.h.

◆ delta_tx_count_producer_

Integrator<int, int> sensesp::SKWSClient::delta_tx_count_producer_ {1, 0, ""}
protected

Definition at line 414 of file signalk_ws_client.h.

◆ delta_tx_tick_producer_

TaskQueueProducer<int> sensesp::SKWSClient::delta_tx_tick_producer_ {0, event_loop(), 990}
protected

Emits the number of deltas sent since last report.

Definition at line 413 of file signalk_ws_client.h.

◆ last_oversize_log_ms_

uint32_t sensesp::SKWSClient::last_oversize_log_ms_ = 0
protected

millis() timestamp of the last oversize-delta-drop warning, used to rate-limit it when a device keeps producing a delta larger than the buffer. 0 = never logged, so the next drop logs immediately.

Definition at line 420 of file signalk_ws_client.h.

◆ next_attempt_ms_

unsigned long sensesp::SKWSClient::next_attempt_ms_ = 0
protected

Definition at line 331 of file signalk_ws_client.h.

◆ pending_ca_pem_

String sensesp::SKWSClient::pending_ca_pem_ = ""
protected

Definition at line 363 of file signalk_ws_client.h.

◆ pending_cn_

String sensesp::SKWSClient::pending_cn_ = ""
protected

Definition at line 365 of file signalk_ws_client.h.

◆ pending_fingerprint_

String sensesp::SKWSClient::pending_fingerprint_ = ""
protected

Definition at line 364 of file signalk_ws_client.h.

◆ pending_is_ca_

bool sensesp::SKWSClient::pending_is_ca_ = false
protected

Definition at line 367 of file signalk_ws_client.h.

◆ pending_san_

String sensesp::SKWSClient::pending_san_ = ""
protected

Definition at line 366 of file signalk_ws_client.h.

◆ pending_teardown_

std::atomic<esp_websocket_client_handle_t> sensesp::SKWSClient::pending_teardown_ {nullptr}
protected

Definition at line 410 of file signalk_ws_client.h.

◆ pending_valid_

bool sensesp::SKWSClient::pending_valid_ = false
protected

Definition at line 368 of file signalk_ws_client.h.

◆ polling_href_

String sensesp::SKWSClient::polling_href_ = ""
protected

Definition at line 328 of file signalk_ws_client.h.

◆ received_updates_

std::list<ReceivedUpdate> sensesp::SKWSClient::received_updates_ {}
protected

Definition at line 436 of file signalk_ws_client.h.

◆ received_updates_semaphore_

SemaphoreHandle_t sensesp::SKWSClient::received_updates_semaphore_
protected
Initial value:
=
xSemaphoreCreateRecursiveMutexStatic(&received_updates_semaphore_buffer_)
StaticSemaphore_t received_updates_semaphore_buffer_

Definition at line 434 of file signalk_ws_client.h.

◆ received_updates_semaphore_buffer_

StaticSemaphore_t sensesp::SKWSClient::received_updates_semaphore_buffer_
protected

Definition at line 433 of file signalk_ws_client.h.

◆ send_meta_enabled_

bool sensesp::SKWSClient::send_meta_enabled_ = true
protected

Definition at line 340 of file signalk_ws_client.h.

◆ server_address_

String sensesp::SKWSClient::server_address_ = ""
protected

Definition at line 320 of file signalk_ws_client.h.

◆ server_port_

uint16_t sensesp::SKWSClient::server_port_ = 80
protected

Definition at line 321 of file signalk_ws_client.h.

◆ sk_delta_queue_

std::shared_ptr<SKDeltaQueue> sensesp::SKWSClient::sk_delta_queue_
protected

Definition at line 411 of file signalk_ws_client.h.

◆ ssl_enabled_

bool sensesp::SKWSClient::ssl_enabled_ = false
protected

Definition at line 335 of file signalk_ws_client.h.

◆ task_connection_state_

SKWSConnectionState sensesp::SKWSClient::task_connection_state_
protected
Initial value:

task_connection_state is used to track the internal task state which might be out of sync with the published connection state.

Definition at line 380 of file signalk_ws_client.h.

◆ teardown_in_progress_

std::atomic<bool> sensesp::SKWSClient::teardown_in_progress_ {false}
protected

Definition at line 401 of file signalk_ws_client.h.

◆ tofu_ca_pem_

String sensesp::SKWSClient::tofu_ca_pem_ = ""
protected

Definition at line 347 of file signalk_ws_client.h.

◆ tofu_enabled_

bool sensesp::SKWSClient::tofu_enabled_ = true
protected

Definition at line 336 of file signalk_ws_client.h.

◆ tofu_fingerprint_

String sensesp::SKWSClient::tofu_fingerprint_ = ""
protected

Definition at line 346 of file signalk_ws_client.h.

◆ tofu_pin_cn_

String sensesp::SKWSClient::tofu_pin_cn_ = ""
protected

Definition at line 357 of file signalk_ws_client.h.

◆ tofu_pin_is_ca_

bool sensesp::SKWSClient::tofu_pin_is_ca_ = false
protected

Definition at line 358 of file signalk_ws_client.h.

◆ tofu_san_

String sensesp::SKWSClient::tofu_san_ = ""
protected

Definition at line 353 of file signalk_ws_client.h.

◆ use_mdns_

bool sensesp::SKWSClient::use_mdns_ = true
protected

Definition at line 325 of file signalk_ws_client.h.


The documentation for this class was generated from the following files: