Adapters
Connect the RainMaker SDK to your platform—React Native, web, Electron—by implementing small adapter interfaces for storage, BLE, notifications, and more.
What This Module Does?
Adapters bridge TypeScript SDK logic and platform-native capabilities (AsyncStorage, BLE modules, FCM, localStorage). The SDK stays platform-agnostic; your app supplies implementations at configure time.
Use adapters when you integrate @espressif/rainmaker-base-sdk on any platform that is not already wired for you (e.g. custom React Native, Vue, Angular, Electron).
Storage is always required. Other adapters depend on which features you enable — see table below.
Expected outcome: ESPRMBase.configure() receives working adapters and SDK features (provisioning, local control, push) function on your platform.
Configure Adapters as Needed
You only pass adapters for features your app uses.
| Adapter | Required? | Enables |
|---|---|---|
| Storage | Yes | Sessions, tokens, SDK cache |
| Provisioning | If onboarding devices | BLE/SoftAP provision flow |
| Local discovery | If local discovery | mDNS/Bonjour scan |
| Local control | If LAN control | Direct parameter updates on LAN |
| Notification | If push updates | Remote node update events |
| OAuth | If social login | Third-party auth code flow |
| App utility | Optional | BLE/location permission checks |
Common Workflows
Implement a Storage Adapter (web)
import type { ESPRMStorageAdapterInterface } from "@espressif/rainmaker-base-sdk";
class WebStorageAdapter implements ESPRMStorageAdapterInterface {
async setItem(name: string, value: string): Promise<void> {
localStorage.setItem(name, value);
}
async getItem(name: string): Promise<string | null> {
return localStorage.getItem(name);
}
async removeItem(name: string): Promise<void> {
localStorage.removeItem(name);
}
async clear(): Promise<void> {
localStorage.clear();
}
}
export default new WebStorageAdapter();
Implement Storage (React Native)
import AsyncStorage from "@react-native-async-storage/async-storage";
import type { ESPRMStorageAdapterInterface } from "@espressif/rainmaker-base-sdk";
const asyncStorageAdapter: ESPRMStorageAdapterInterface = {
setItem: (name, value) => AsyncStorage.setItem(name, value),
getItem: (name) => AsyncStorage.getItem(name),
removeItem: (name) => AsyncStorage.removeItem(name),
clear: () => AsyncStorage.clear(),
};
export default asyncStorageAdapter;
Register Adapters with the SDK
import { ESPRMBase } from "@espressif/rainmaker-base-sdk";
import storageAdapter from "./adapters/storage";
import provisionAdapter from "./adapters/provision";
ESPRMBase.configure({
baseUrl: "https://api.rainmaker.espressif.com",
version: "v1",
customStorageAdapter: storageAdapter,
provisionAdapter, // omit if not provisioning
});
See Getting Started for full configuration options.
Use the React Native Reference Implementation
Please see the complete implementations for adapters at esp-rainmaker-home/native-adaptors
Error Handling
Missing Storage Adapter
// Fails — storage is required
ESPRMBase.configure({ baseUrl: "https://api.rainmaker.espressif.com" });
// Correct
ESPRMBase.configure({
baseUrl: "https://api.rainmaker.espressif.com",
customStorageAdapter: storageAdapter,
});
Interface Mismatch
Implement every method defined by the interface as an async method returning a Promise. Declaring a class with implements ESPRMStorageAdapterInterface (or the corresponding interface for another adapter) lets TypeScript catch missing methods at compile time.
async setItem(name: string, value: string): Promise<void> {
try {
await AsyncStorage.setItem(name, value);
} catch (error) {
console.error("Storage setItem failed:", error);
throw error;
}
}
Advanced Concepts
Why Adapters Exist
React Native needs native modules for BLE; browsers use localStorage and limited Web Bluetooth; Electron may use the filesystem. Adapters let one SDK target all of them with the same TypeScript API.
Adapter Responsibilities (Summary)
| Adapter | Responsibility |
|---|---|
| Storage | setItem, getItem, removeItem, clear |
| Provisioning | Device search, connect, Wi-Fi scan, provision, disconnect |
| Local discovery | startDiscovery/stopDiscovery with mDNS params |
| Local control | LAN connect, sendData for local param paths |
| Notification | addNotificationListener for push payloads |
| OAuth | getCode from OAuth redirect URL |
| App utility | Permission checks before BLE/location features |
Best Practices
- Implement
implements Interfacefor compile-time safety - Throw or log errors inside adapters — do not swallow native failures
- Provide only adapters you need — smaller surface, easier testing
- Fork RN reference adapters instead of writing provisioning from scratch
- Test permission flows with
appUtilityAdapterbefore BLE onboarding UI

