The @espressif/rainmaker-base-sdk
package provides a foundational SDK to help mobile app developers quickly integrate with the ESP Rainmaker ecosystem. It enables seamless provisioning, control, and management of devices.
The @espressif/rainmaker-base-sdk
package is designed to accelerate app development by providing a unified API for interacting with the ESP Rainmaker platform. With support for different communication transports, developers can seamlessly integrate features such as provisioning, device control, and discovery into their apps.
The SDK provides:
Before installing the @espressif/rainmaker-base-sdk
package, ensure you meet the following prerequisites:
To install the latest version of the @espressif/rainmaker-base-sdk
package from the npm registry, you can use your preferred package manager:
npm install @espressif/rainmaker-base-sdk
yarn add @espressif/rainmaker-base-sdk
pnpm add @espressif/rainmaker-base-sdk
To build and install the package locally for development and testing:
Clone the repository
Check out the appropriate branch:
git checkout main
Ensure you are using Node.js v20.17.0 or higher. If you have nvm
installed, you can run:
nvm use
If you don’t have nvm
, please install Node.js v20.17.0 or a higher version manually.
Install the required dependencies using Yarn:
yarn install
Build the package:
yarn run build
Create a tarball for testing locally:
yarn pack
Add the tarball to your project:
yarn add <PATH_TO_PACK_TARBALL_FILE>
After installation, you can import and configure the SDK in your project as shown in the usage examples below.
Below is a step-by-step guide to logging in a user using the @espressif/rainmaker-base-sdk
SDK:
Import the SDK
Begin by importing the ESPRMBase
class from the @espressif/rainmaker-base-sdk
package.
import { ESPRMBase } from "@espressif/rainmaker-base-sdk";
Configure the SDK
Use the configure
method to initialize the SDK with the required base URL and API version.
ESPRMBase.configure({
baseUrl: "https://api.rainmaker.espressif.com",
version: "v1",
});
Get an Instance of the Authentication Module
Obtain an instance of the authentication module by calling getAuthInstance()
on the ESPRMBase
class.
const authInstance = ESPRMBase.getAuthInstance();
Attempt User Login
Call the login
method on the authentication instance, passing the username and password as arguments.
Handle the response or any potential errors using a try-catch block.
try {
const resp = await authInstance.login("<USERNAME>", "<PASSWORD>");
console.log(resp); // Log the response on successful login
} catch (error) {
console.log(error); // Handle and log any errors during login
}
Review the Login Response
The login
method returns a promise. On successful resolution, it provides the user's instance.
Ensure you properly log or handle the response in your application.
This project is licensed under the Apache 2.0 license - see the LICENSE file for details.