The Helium React Native SDK is a collection of modules that can be used by a React Native application to interact with Hotspots and the Helium Blockchain. It has first class support for Typescript.
For usage, refer to the Helium Maker Starter App which utilizes this SDK to build out the base features needed to add Hotspots to the Helium Blockchain.
Along with this you may find the following Helium documentation useful:
yarn add @helium/react-native-sdk
# or
npm install @helium/react-native-sdk
Please browse the documentation for more information.
You can import the different modules such as Account, Location, HotspotBleManager, heliumHttpClient, and AddGateway to get started.
import { Account, Location, AddGateway } from '@helium/react-native-sdk';
// example usage of Account.createKeypair
const { keypairRaw, address, mnemonic } = await Account.createKeypair();
There is an example app included with this SDK. It's intended for reference only and currently does not build on the Apple M1 processor. A practical use of this SDK can be seen here Helium Maker Starter App
Use the HotspotBleManager to interact with a Hotspot via bluetooth.
import { HotspotBleProvider, useHotspotBle } from '@helium/react-native-sdk';
// some examples of the functions you may want to use
const { startScan, stopScan, connect, scannedDevices } = useHotspotBle();
In order to get started with the HotspotBleManager you must first wrap your root app component in a HotspotBleProvider.
For example:
import React from 'react';
import { HotspotBleProvider } from '@helium/react-native-sdk';
const App = () => (
<HotspotBleProvider>
<YourRootAppComponent />
</HotspotBleProvider>
);
You are now ready to use the HotspotBleManager throughout your application.
You can use the HotspotBleManager to {@link startScan}, {@link stopScan}, and read information from {@link scannedDevices}. Check out the Device docs for more info on scanned devices.
For a full working example see the example app.
import React, { useEffect } from 'react';
import { useHotspotBle } from '@helium/react-native-sdk';
const { startScan, stopScan, scannedDevices } = useHotspotBle();
useEffect(() => {
// you would probably want to call this on a button click, we scan right away
startScan((error) => {
if (error) {
console.error(error);
}
});
}, []);
useEffect(() => {
// you would probably want to call this on a button click, but we stop after 10 seconds
setTimeout(stopScan, 10000);
}, []);
const ScanComponent = () => <Text>{scannedDevices[0]?.localName}</Text>;
After scanning, you can connect to {@link scannedDevices} by calling connect.
import { useHotspotBle } from '@helium/react-native-sdk';
const { connect, scannedDevices } = useHotspotBle();
connect(scannedDevices[0]);
Once connect has been called you can use the other HotspotBleManager to interact with a connected Device. For example, you may want to call {@link getDiagnosticInfo} to read the hotspot's diagnostic information or {@link readWifiNetworks} to display available wifi networks the hotspot can see and then {@link setWifi} to set a network.
Visit the example app for full examples of Wifi Setup, WifiSettings, or Diagnostics.
See the contributing guide to learn how to contribute to the repository and the development workflow.
Generated using TypeDoc