Skip to content

Component implementation for Bluetooth SIG Mesh SDK of Telink

License

Notifications You must be signed in to change notification settings

louisV7/react-native-btsig-telink

This branch is 157 commits behind flyskywhy/react-native-btsig-telink:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

469baed · Aug 26, 2022
Jul 5, 2022
Jul 4, 2022
Jul 5, 2022
Nov 29, 2019
Aug 14, 2020
Aug 14, 2020
Aug 26, 2022
Aug 19, 2020
Aug 26, 2022
Aug 26, 2022
Aug 26, 2022

Repository files navigation

React Native Bluetooth SIG Telink

npm version npm downloads npm licence Platform

Component implementation for Bluetooth SIG Mesh SDK of Telink.

Install

For RN >= 0.60 and Android SDK >= 29

npm i --save react-native-btsig-telink

For RN >= 0.60 and Android SDK < 29

npm i --save react-native-btsig-telink@1.2.x

For RN < 0.60

npm i --save react-native-btsig-telink@1.0.x

Android

For RN < 0.60, need files edited below:

In android/app/build.gradle

dependencies {
    implementation project(':react-native-btsig-telink')
}

In android/app/src/main/java/com/YourProject/MainApplication.java

import com.telink.sig.mesh.TelinkBtSigPackage;
...
    new TelinkBtSigPackage(),

In android/settings.gradle

include ':react-native-btsig-telink'
project(':react-native-btsig-telink').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-btsig-telink/android')

Sometimes will meet compile error java.io.FileNotFoundException: YOUR_PROJECT/node_modules/react-native-btsig-telink/android/.cxx/cmake/release/armeabi-v7a/android_gradle_build.json (The system cannot find the file specified) after upgrade this pacakge by npm install, can solve it by add --rerun-tasks to your gradlew command like

./android/gradlew assembleDebug --rerun-tasks -p ./android/

iOS

Open SigMeshOC/SigMeshOC.xcodeproj by Xcode, in 'Signing & Capabilities' of Target 的 'SigMeshOC', choose Team to your Apple ID, then close Xcode and:

cd node_modules/react-native-btsig-telink/SigMeshOC/
./Script.sh

results:

SigMeshOC/Build/Products/SigMeshOC/Release-iphoneos/SigMeshOC.framework/

For RN >= 0.60, in ios/Podfile

  pod 'SigMeshOC', :path => '../node_modules/react-native-btsig-telink/SigMeshOC'

For RN < 0.60, in ios/Podfile

  pod 'SigMeshOC', :path => '../node_modules/react-native-btsig-telink/SigMeshOC'
  pod 'RNBtSigTelink', :path => '../node_modules/react-native-btsig-telink'

For RN < 0.60 and RN >= 0.60

cd ios
pod install

fastBind

If you want fastBind, you need put the cpsData of your device into android/src/main/java/com/telink/sig/mesh/PrivateDevice.java and DeviceTypeModel in SigMeshOC/SigMeshOC/Model.m.

Usage

import React from 'react';
import { View } from 'react-native';
import meshModule from 'react-native-btsig-telink';

export default class MeshModuleExample extends React.Component {
    constructor(props) {
        super(props);
        meshModule.passthroughMode = {
            silan: [
                1,
                7,
            ],
            sllc: [
                30848,
            ],
        };
    }

    componentDidMount() {
        meshModule.addListener('leScan', this.onLeScan);
        meshModule.netKey = YOUR_16_BYTES_NETKEY;
        meshModule.appKey = YOUR_16_BYTES_APPKEY;

        // you can save data comes from (provision then bind function) meshModule.configNode()
        // Promise into devicesSavedInRedux after onLeScan() , then `meshModule.devices = devicesSavedInRedux`
        // here befor meshModule.doInit() so that can auto connect them after APP restart.
        // // devicesSavedInRedux = [{
        // //     meshAddress: 1,
        // //     macAddress: 'AB:CD:EF:GH:IJ:KL',
        // //     elementCnt: 2,
        // //     dhmKey: [12, 34, 56...],
        // //     nodeInfo: [12, 34, 56, ...]
        // // }];
        // meshModule.devices = devicesSavedInRedux;

        meshModule.doInit();
        meshModule.startScan({
            isSingleNode: false, // if true, will stop scan after found one device
            timeoutSeconds: 10,
        });
    }

    onLeScan = data => console.warn(data)

    render() {
        return (
            <View/>
        );
    }
}

Please discover more in index.native.js.

Donate

To support my work, please consider donate.

  • ETH: 0xd02fa2738dcbba988904b5a9ef123f7a957dbb3e

About

Component implementation for Bluetooth SIG Mesh SDK of Telink

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 76.3%
  • Java 10.8%
  • Objective-C 9.3%
  • HTML 1.5%
  • JavaScript 1.5%
  • Shell 0.2%
  • Other 0.4%