Skip to the content.

Cloud module

This module connects and manages communication with nRF Cloud over CoAP using nRF Cloud CoAP library in nRF Connect SDK. It controls the cloud connection, sends data to nRF Cloud, and processes incoming data such as device shadow document. The cloud module uses Zephyr’s state machine framework (SMF) and zbus for messaging with other modules.

The module’s responsibilities include:

nRF Cloud over CoAP utilizes DTLS connection ID which allows the device to quickly re-establish a secure connection with the cloud after a network disconnection without the need for a full DTLS handshake. The module uses the nRF Cloud CoAP library to handle the CoAP communication and DTLS connection management.

Below, the module’s main messages, configurations, and state machine are covered. Refer to the source files (cloud.c, cloud.h, and Kconfig.cloud) for implementation details.

Messages

The cloud module publishes and receives messages over the zbus channel CLOUD_CHAN. All module message types are defined in cloud.h and used within cloud.c.

Input Messages

Output Messages

The message structure used by the cloud module is defined in cloud.h:

struct cloud_msg {
	enum cloud_msg_type type;
	union  {
		struct cloud_payload payload;
		struct cloud_shadow_response response;
	};
};

Configurations

Several Kconfig options in Kconfig.cloud control this module’s behavior. Below are some notable ones:

For more details on these and other configurations, refer to Kconfig.cloud.

State diagram

Below is a simplified representation of the state machine implemented in cloud.c. The module starts in the STATE_RUNNING context, which immediately transitions to STATE_DISCONNECTED upon initialization. From there, network events and internal conditions drive state transitions.

stateDiagram-v2
    [*] --> STATE_RUNNING

    STATE_RUNNING --> STATE_DISCONNECTED: NETWORK_DISCONNECTED

    state STATE_RUNNING {
        [*] --> STATE_DISCONNECTED

        STATE_DISCONNECTED --> STATE_CONNECTING: NETWORK_CONNECTED

        STATE_CONNECTING --> STATE_CONNECTED: CLOUD_CONN_SUCCESS

        state STATE_CONNECTING {
            [*] --> STATE_CONNECTING_ATTEMPT

            STATE_CONNECTING_ATTEMPT --> STATE_CONNECTING_BACKOFF: CLOUD_CONN_FAILED
            STATE_CONNECTING_BACKOFF --> STATE_CONNECTING_ATTEMPT: CLOUD_BACKOFF_EXPIRED
        }

        state STATE_CONNECTED {
            [*] --> STATE_CONNECTED_READY_TO_SEND

            STATE_CONNECTED_READY_TO_SEND --> STATE_CONNECTED_PAUSED: NETWORK_DISCONNECTED
            STATE_CONNECTED_PAUSED --> STATE_CONNECTED_READY_TO_SEND: NETWORK_CONNECTED
        }
    }