npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-xbee-ble

v0.1.3

Published

This package wraps xbee-android

Downloads

5

Readme

react-native-xbee-ble

This package wraps xbee-android. Currently, only android is supported because xbee does not have Objective-C or Swift implementation. Support for IOS could be done but needs to be implemented base on e.g. react-native-ble-manager and SRP authentication and packets encryption needs to be done.

Package can send user data relay frame and also receive. There is also possibility to send file over BLE using URL -> it creates stream of user data relay to SERIAL interface which can be use for save later by MCU.

Installation

npm install react-native-xbee-ble

Android

  • Add sources for xbee libraries
android/build.gradle
//..
allprojects {
    repositories {
    //..
      maven {
        url 'http://ftp1.digi.com/support/m-repo/'
    }
    //..
  }
}
  • there might be error also with minSdk 19 needed so also update value in android/build.gradle.
  • there might be error with android:allowBackup="false" change it to true

Usage

Permission for android to cover all library functionality

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Before everything start ble manager. Typically, use it in useEffect

import XbeeBleManager from 'react-native-xbee-ble';

useEffect(async () => {
  //...
  await XbeeBleManager.start();
  //...
},[]);

Start scan

const startScan = () => {
  XbeeBleManager.scan()
    .then(() => console.log('Scan started'))
    .catch((err) => console.log(err));
};

// Stop scan
const stopScan = () => {
  XbeeBleManager.stopScan()
    .then(() => console.log('Scan stopped'))
    .catch((err) => console.log(err));
};

Event handler emitter

This needs to be used to get possibility to set event handlers

const XbeeBleManagerModule = NativeModules.XbeeBle;
const xbeeBleManagerEmitter = new NativeEventEmitter(XbeeBleManagerModule);

Handle devices discovers

// in use effect used for start manager add
useEffect(async () => {
  //...
  xbeeBleManagerEmitter.addListener(
    'BleManagerDiscoverPeripheral',
    handleDiscoverPeripheral
  );
  //...
  return () => {
    //...
    xbeeBleManagerEmitter.removeListener(
      'BleManagerDiscoverPeripheral',
      handleDiscoverPeripheral
    );
    //...
  };
}, []);

const handleDiscoverPeripheral = (peripheral: Peripheral) => {
  if (!peripheral.name) {
    peripheral.name = 'NO NAME';
  }
  // Xbee device has by default name Xbee. There is a filter by name, remove it if neccessary
  if (!peripherals.has(peripheral.id) && peripheral.name.includes('XBee')) {
    // Do something else with peripherals typically set list state
  }
};

Connect/Disconnect

const connect = (item: Peripheral) => () => {
    if (!item.connected) {
      // Stop scan before connect
      XbeeBleManager.stopScan().then(() =>
        XbeeBleManager.connectToDevice(item.id, '1234') // 1234 is password set by XCTU in BLE setting
          .then(() => {
            // use this to speed up communication or delete if speed is not neccesarry
            // with this setting it is able to write about 7,2 kB/s without about 2 kB/s
            XbeeBleManager.requestConnectionPriority(
              item.id,
              ConnectionPriority.high,
            );
            item.connected = true;
            // set list state value
          })
          .catch((e) => console.log(e))
      );
    } else {
      XbeeBleManager.disconnectFromDevice(item.id).then(() => {
        item.connected = false;
        // set list state value
      });
    }
  };

Send user data relay

// item is Peripheral, could be also id directly
XbeeBleManager.sendUserDataRelay(
  item.id,
  UserDataRelayInterface.serial, // use UserDataRelayInterface.ble for echo
  [...Buffer.from('HELLO', 'utf-8')]
)

Receive user data relay

When xbee received user data

// in use effect used for start manager add
useEffect(async () => {
  //...
  xbeeBleManagerEmitter.addListener(
    'XbeeReceivedUserDataRelay',
    handleDataReceived
  );
  //...
  return () => {
    //...
    xbeeBleManagerEmitter.removeListener(
      'XbeeReceivedUserDataRelay',
      handleDataReceived
    );
    //...
  };
}, []);

//...
const handleDataReceived = (data: UserDataRelayData) => {
  console.log(data);
};
//...

Send file using BLE

Use post images to upload some image and later used as url for this function. After image is uploaded use direct link. This function is good when you use BLE to transfer some files to MCU using UART.

// item is Peripheral, could be also id directly
XbeeBleManager.sendFile({
  address: item.id,
  url: 'https://i.postimg.cc/7ZtsYgFT/Screenshot-from-2021-12-21-15-45-06.png'
})
  .then(() => console.log('file sent'))
  .catch((err) => console.log(err))

Handle file transfer progress

// in use effect used for start manager add
useEffect(async () => {
  //...
  xbeeBleManagerEmitter.addListener(
    'XbeeFileSendProgress',
    handleFileProgress
  );
  //...
  return () => {
    //...
    xbeeBleManagerEmitter.removeListener(
      'XbeeFileSendProgress',
      handleFileProgress
    );
    //...
  };
}, []);

const handleFileProgress = (progress: FileProgress) => {
  console.log(progress);
};

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT