Skip to main content

Getting Started

The CDF Store provides a centralized state management solution optimized for SDK. It handles caching, persistence, and real-time updates automatically. This section guides you through setting up and using the CDF Store in your project.

NPM Package: @espressif/rainmaker-base-cdf

To start using CDF, follow these steps:


Prerequisites

Before diving in, ensure you have the following:


Installation

Open your terminal or command prompt and navigate to your project directory.

Run the following command to install the @espressif/rainmaker-base-cdf package using npm:

npm install @espressif/rainmaker-base-cdf

This command will download and install the necessary CDF library into your project.


Importing the CDF Store

Once installed, you can import the CDF functionality into your TypeScript code using the following syntax:

import { CDF } from "@espressif/rainmaker-base-cdf";

This line imports the CDF class from the rainmaker-base-cdf library, providing access to the CDF Store functionalities.


Initializing the CDF Store

To create an instance of the CDF Store and connect it to your RainMaker backend, you'll need to initialize it using the CDF constructor. Here's a breakdown of the initialization process:

import { CDF } from "@espressif/rainmaker-base-cdf";

const initApp = async () => {
const sdkConfiguration: ESPRMBaseConfig = {
// Provide endpoint URL for your RainMaker deployment here.
baseUrl: "https://api.rainmaker.espressif.com",
version: "v1",
// Add other SDK configuration fields as needed
};

const cdfConfig: CDFconfig = {
autoSync: true
};

try {
const espCDF = await CDF(sdkConfiguration, cdfConfig);
// CDF Store is now initialized and ready to use
} catch (error) {
// Handle any error during CDF initialization.
console.error("CDF initialization failed:", error);
}
};

initApp();

SDK Configuration

The sdkConfiguration object uses the same configuration as the base SDK. For detailed information about all available SDK configuration fields, refer to the SDK Getting Started Guide.

Note: The SDK follows an adapter approach. For any of the provisioning, local discovery, local control, or notifications to work, they require communication with native code that can be provided through an adapter to the SDK. Learn more about SDK Adapters.

CDF Configuration

The cdfConfig object allows you to customize CDF-specific behavior:

FieldTypeDescription
autoSyncbooleanWhen set to true, allows for automatic retrieval of user data and initialization of stores. However, enabling auto-fetching may lead to delays in initializing the CDF if the user data is substantial, so it should be used with caution.

Next Steps

After setting up CDF, you can start using the stores:

  1. User Store - Learn about UserStore operations
  2. Node Store - Learn about NodeStore operations
  3. Group Store - Learn about GroupStore operations
  4. Automation Store - Learn about AutomationStore operations
  5. Scene Store - Learn about SceneStore operations
  6. Schedule Store - Learn about ScheduleStore operations
  7. Subscription Store - Learn about SubscriptionStore operations

For detailed information about each store and their capabilities, refer to the respective sections.

On this page