IoT Server Client
Connection, registration, custom objects and firmware state.
Data Structures
wb_iot_cert_config_t
X.509 certificates for the DTLS connection.
| Field | Type | Description |
|---|---|---|
ca_cert |
const uint8_t * |
CA certificate (DER) |
ca_cert_len |
size_t |
Length of ca_cert in bytes. |
client_cert |
const uint8_t * |
Client certificate (DER) |
client_cert_len |
size_t |
Length of client_cert in bytes. |
client_key |
const uint8_t * |
Client private key (DER) |
client_key_len |
size_t |
Length of client_key in bytes. |
wb_iot_device_info_t
Device information for the LwM2M Device Object (/3).
| Field | Type | Description |
|---|---|---|
device_type |
const char * |
Device type (e.g. “esp32”, “esp32s3”) |
firmware_version |
const char * |
Current firmware version. |
hardware_version |
const char * |
Hardware version (optional) |
manufacturer |
const char * |
Manufacturer (e.g. “WhirlingBits”) |
model_number |
const char * |
Model number. |
serial_number |
const char * |
Serial number (optional) |
wb_iot_nvs_config_t
Storage for the configuration transferred by provisioning (app, endpoint “wb-iot”).
wb_iot_server_config_t only holds pointers: this storage must live as long as the server handle (e.g. static).
| Field | Type | Description |
|---|---|---|
endpoint[64] |
char |
LwM2M endpoint name. |
host[128] |
char |
Server hostname or IP address. |
psk_identity[64] |
char |
PSK identity. |
psk_key[64] |
uint8_t |
PSK key (binary) |
psk_key_len |
size_t |
Length of psk_key in bytes. |
wb_iot_psk_config_t
PSK credentials for the DTLS connection.
| Field | Type | Description |
|---|---|---|
identity |
const char * |
PSK identity (usually the endpoint name) |
key |
const uint8_t * |
PSK key (binary, hex-decoded) |
key_len |
size_t |
Key length in bytes. |
wb_iot_server_config_t
Configuration of the connection to the WhirlingBits IoT Server.
| Field | Type | Description |
|---|---|---|
cert |
wb_iot_cert_config_t |
Certificates (only with WB_IOT_SEC_CERT) |
device_info |
wb_iot_device_info_t |
Contents of the Device Object (/3) |
endpoint_name |
const char * |
LwM2M endpoint name (unique per device) |
event_handler |
wb_iot_server_event_handler_t |
Event handler (optional) |
lifetime |
uint32_t |
Registration lifetime in seconds (0 = 300) |
ota |
wb_iot_ota_config_t |
OTA configuration. |
psk |
wb_iot_psk_config_t |
PSK credentials (only with WB_IOT_SEC_PSK) |
security |
wb_iot_security_mode_t |
Security mode. |
server_host |
const char * |
Hostname or IP address of the IoT Server. |
server_port |
uint16_t |
CoAP/CoAPS port (0 = 5683 or 5684 depending on security) |
user_ctx |
void * |
Passed through to the event handler. |
wb_iot_server_event_data_t
Event data passed to the event handler.
| Field | Type | Description |
|---|---|---|
data |
const void * |
Event-specific data (may be NULL) |
data_len |
size_t |
Length of data in bytes. |
type |
wb_iot_server_event_t |
Event type. |
Type Definitions
wb_iot_server_event_handler_t
typedef void(* wb_iot_server_event_handler_t) (wb_iot_server_event_data_t *event, void *user_ctx)
Application event handler callback.
wb_iot_server_handle_t
typedef struct wb_iot_server_ctx* wb_iot_server_handle_t
Handle of an IoT Server client, created by wb_iot_server_init().
Enumerations
wb_iot_security_mode_t
Security mode of the CoAP connection to the IoT Server.
| Enumerator | Value | Description |
|---|---|---|
WB_IOT_SEC_NONE |
Plain CoAP (port 5683, no DTLS) | |
WB_IOT_SEC_PSK |
DTLS with pre-shared key (port 5684) | |
WB_IOT_SEC_CERT |
DTLS with X.509 certificate (port 5684) |
wb_iot_server_event_t
Events delivered by the IoT Server client to the application callback.
| Enumerator | Value | Description |
|---|---|---|
WB_IOT_EVT_CONNECTED |
CoAP connection established. | |
WB_IOT_EVT_DISCONNECTED |
Connection lost. | |
WB_IOT_EVT_REGISTERED |
LwM2M registration with the IoT Server succeeded. | |
WB_IOT_EVT_REG_FAILED |
Registration failed. | |
WB_IOT_EVT_REG_UPDATED |
Registration update succeeded. | |
WB_IOT_EVT_OTA_PACKAGE_URI |
Server wrote the Package URI (/5/0/1); data is the URI. |
|
WB_IOT_EVT_OTA_EXECUTE |
Server triggered the update (/5/0/2) | |
WB_IOT_EVT_OTA_DOWNLOAD_START |
OTA download started. | |
WB_IOT_EVT_OTA_DOWNLOAD_DONE |
OTA download completed successfully. | |
WB_IOT_EVT_OTA_DOWNLOAD_FAILED |
OTA download failed. | |
WB_IOT_EVT_OTA_APPLYING |
OTA is being applied (reboot imminent) | |
WB_IOT_EVT_ERROR |
General error. |
Functions
wb_iot_server_add_object
Registers additional LwM2M objects.
esp_err_t wb_iot_server_add_object(wb_iot_server_handle_t handle, const wb_lwm2m_object_def_t *obj)
Parameters:
- handle (
wb_iot_server_handle_t): Handle fromwb_iot_server_init(). - obj (
const wb_lwm2m_object_def_t *): Object definition (referenced, not copied).
Returns:
ESP_OK on success.
Must be called BEFORE wb_iot_server_start(). The standard objects (Device, Firmware) are registered automatically.
wb_iot_server_config_load_nvs
Loads the configuration from the NVS namespace “wb_iot” (written by esp-idf-provisioning when the IoT Server app sets up the device).
esp_err_t wb_iot_server_config_load_nvs(wb_iot_nvs_config_t *store, wb_iot_server_config_t *config)
Parameters:
- store (
wb_iot_nvs_config_t *): Storage for strings and keys (must live as long as the handle). - config (
wb_iot_server_config_t *): Configuration to complete.
Returns:
ESP_OK, ESP_ERR_NOT_FOUND if the device has not been set up, otherwise an NVS error.
Sets server_host, server_port, endpoint_name, security, psk and lifetime in config; all other fields (device_info, ota, event_handler, …) remain unchanged.
wb_iot_server_destroy
Releases all resources.
esp_err_t wb_iot_server_destroy(wb_iot_server_handle_t handle)
Parameters:
- handle (
wb_iot_server_handle_t): Handle (invalid after the call).
Returns:
ESP_OK on success.
wb_iot_server_get_lwm2m_client
Returns the underlying wb-idf-lwm2m handle.
wb_lwm2m_client_handle_t wb_iot_server_get_lwm2m_client(wb_iot_server_handle_t handle)
Parameters:
- handle (
wb_iot_server_handle_t): Handle.
Returns:
wb_lwm2m_client_handle_t or NULL.
For advanced applications that need direct access to the LwM2M client.
wb_iot_server_get_ota
Returns the OTA handle.
wb_iot_ota_handle_t wb_iot_server_get_ota(wb_iot_server_handle_t handle)
Parameters:
- handle (
wb_iot_server_handle_t): Handle.
Returns:
wb_iot_ota_handle_t or NULL.
Gives direct access to the OTA module for progress queries or manual download/apply in MANUAL mode.
wb_iot_server_init
Initializes the IoT Server client.
wb_iot_server_handle_t wb_iot_server_init(const wb_iot_server_config_t *config)
Parameters:
- config (
const wb_iot_server_config_t *): Pointer to the configuration (copied).
Returns:
Handle, or NULL on error.
Internally creates a wb-idf-lwm2m client with the configured standard objects (Device /3, Firmware /5) and the IoT Server specific telemetry objects.
wb_iot_server_is_registered
Checks whether the client is registered with the IoT Server.
bool wb_iot_server_is_registered(wb_iot_server_handle_t handle)
Parameters:
- handle (
wb_iot_server_handle_t): Handle.
Returns:
true if registered.
wb_iot_server_notify
Sends a telemetry notification for a resource.
esp_err_t wb_iot_server_notify(wb_iot_server_handle_t handle, uint16_t obj_id, uint16_t inst_id, uint16_t res_id)
Parameters:
- handle (
wb_iot_server_handle_t): Handle. - obj_id (
uint16_t): Object ID. - inst_id (
uint16_t): Instance ID. - res_id (
uint16_t): Resource ID.
Returns:
ESP_OK on success.
Uses wb_lwm2m_notify() internally — the server reads the value via the registered read_cb.
wb_iot_server_ota_mark_valid
Confirms the running firmware after an OTA update.
esp_err_t wb_iot_server_ota_mark_valid(void)
Parameters:
- **** (
void)
Returns:
ESP_OK on success.
Wrapper around wb_iot_ota_mark_valid(). Call it at application start as soon as the new firmware is considered functional. Without this call the bootloader rolls back on the next start.
wb_iot_server_set_fw_result
Sets the OTA firmware update result (/5/0/5).
esp_err_t wb_iot_server_set_fw_result(wb_iot_server_handle_t handle, wb_lwm2m_fw_update_result_t result)
Parameters:
- handle (
wb_iot_server_handle_t): Handle. - result (
wb_lwm2m_fw_update_result_t): Update result (see wb_lwm2m_fw_update_result_t).
Returns:
ESP_OK on success.
wb_iot_server_set_fw_state
Sets the OTA firmware state (/5/0/3).
esp_err_t wb_iot_server_set_fw_state(wb_iot_server_handle_t handle, wb_lwm2m_fw_state_t state)
Parameters:
- handle (
wb_iot_server_handle_t): Handle. - state (
wb_lwm2m_fw_state_t): Firmware state (see wb_lwm2m_fw_state_t).
Returns:
ESP_OK on success.
Called by the application to report OTA progress.
wb_iot_server_start
Starts the connection to the IoT Server.
esp_err_t wb_iot_server_start(wb_iot_server_handle_t handle)
Parameters:
- handle (
wb_iot_server_handle_t): Handle.
Returns:
ESP_OK if the connection setup was started.
Establishes the CoAP connection and sends the LwM2M registration. Registration updates happen automatically.
wb_iot_server_stop
Stops the client (deregistration + disconnect).
esp_err_t wb_iot_server_stop(wb_iot_server_handle_t handle)
Parameters:
- handle (
wb_iot_server_handle_t): Handle.
Returns:
ESP_OK on success.
