1.0.0 • Published 4 months ago

rn-nordic-mcu-fs-manager v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

React Native Nordic MCU File System Manager

React Native Nordic MCU File System Manager (currently supports download functionality only)

Table of Contents

Installation in managed Expo projects

For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release. If you follow the link and there is no documentation available then this library is not yet usable within managed projects it is likely to be included in an upcoming Expo SDK release.

Installation in bare React Native projects

For bare React Native projects, you must ensure that you have installed and configured the expo package before continuing.

Add the package to your npm dependencies

npm install rn-nordic-mcu-fs-manager

Configure for Android

No configuration needed.

Configure for iOS

Run npx pod-install after installing the npm package.

Usage

1. Import the Module

import RnNordicMcuFsManager from "rn-nordic-mcu-fs-manager";

2. Using the Module

Here's an example of how you can use the module in your application:

const App = () => {
  const fsManager = RnNordicMcuFsManager;

  const onDownloadProgressChanged = (progress: number) => {
    console.log("Progress: ", progress);
  };
  const onDownloadFailed = (error: string) => {
    console.log("Failed: ", error);
  };
  const onDownloadCanceled = () => {
    console.log("Canceled");
  };
  const onDownloadCompleted = (bytearray: number[]) => {
    fsManager.destroy();
    const result = String.fromCharCode(...bytearray);
    console.log("Completed", result);
  };

  return (
    <View>
      <Button
        title="Download File"
        onPress={async () => {
          try {
            fsManager.initialize(deviceId);
            fsManager.fileDownload(
              "/lfs1/Lorem_1000.txt",
              onDownloadProgressChanged,
              onDownloadFailed,
              onDownloadCanceled,
              onDownloadCompleted,
            );
          } catch (error) {
            console.error(error);
          }
        }}
      />
    </View>
  );
};

export default App;

Make sure to check the documentation for all available functions and their expected usage.


API Documentation

Methods

Initialize

initialize(bleId: string)

Description: Creates a connection with the bluetooth device and initializes a file system manager module.

Parameters:

  • bleId (string): For Android the device's mac address, for iOS the device's UUID

Destroy

destroy()

Description: Closes the connection with the bluetooth device and releases all the native modules.


File Download

fileDownload(filePath: string, onDownloadProgressChanged: function, onDownloadFailed: function, onDownloadCanceled: function, onDownloadCompleted: function)

Description:
Initiates a file download operation from the specified filePath. The method provides various callbacks to handle download progress, failure, cancellation, and completion.

Parameters:

  • filePath (string):
    The path to the file that you want to download (e.g., "/lfs1/Lorem_1000.txt").

  • onDownloadProgressChanged (function):
    A callback function that will be called with the current download progress (e.g., onDownloadProgressChanged(progress)), where progress is a number between 0 and 100.

  • onDownloadFailed (function):
    A callback function that will be called if the download fails. It receives an error message as a parameter (e.g., onDownloadFailed(error)).

  • onDownloadCanceled (function):
    A callback function that will be called if the download is canceled. It receives no parameters (e.g., onDownloadCanceled()).

  • onDownloadCompleted (function):
    A callback function that will be called when the download is completed successfully. It receives the downloaded byte array and must be converted to string (e.g., onDownloadCompleted(byteArray)).

Contributing

Contributions are very welcome! Please refer to guidelines described in the contributing guide.

Run the module locally

git clone git@github.com:coded-lines/rn-nordic-mcu-fs-manager.git && cd rn-nordic-mcu-fs-manager && npm install && cd example && npm install && cd ios && npx pod-install && cd .. && npx expo prebuild

Credits

This project is heavily inspired by and takes code from react-native-mcu-manager