├── src ├── __tests__ │ └── index.test.tsx └── index.js ├── .gitattributes ├── babel.config.js ├── example ├── ios │ ├── File.swift │ ├── SmartconfigSwjavaExample │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── Info.plist │ │ ├── AppDelegate.m │ │ └── Base.lproj │ │ │ └── LaunchScreen.xib │ ├── SmartconfigSwjavaExample-Bridging-Header.h │ ├── SmartconfigSwjavaExample.xcworkspace │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── contents.xcworkspacedata │ ├── Podfile │ └── SmartconfigSwjavaExample.xcodeproj │ │ └── xcshareddata │ │ └── xcschemes │ │ └── SmartconfigSwjavaExample.xcscheme ├── android │ ├── .settings │ │ └── org.eclipse.buildship.core.prefs │ ├── app │ │ ├── debug.keystore │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── reactnativesmartconfigswjava │ │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ │ └── MainApplication.java │ │ │ │ └── AndroidManifest.xml │ │ │ └── debug │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── reactnativesmartconfigswjava │ │ │ │ └── ReactNativeFlipper.java │ │ └── proguard-rules.pro │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── .project │ ├── gradle.properties │ ├── build.gradle │ ├── gradlew.bat │ └── gradlew ├── app.json ├── index.js ├── babel.config.js ├── package.json ├── metro.config.js └── src │ └── App.js ├── android ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ ├── esptouch │ │ ├── IEsptouchListener.java │ │ ├── task │ │ │ ├── IEsptouchGenerator.java │ │ │ ├── ICodeData.java │ │ │ ├── __IEsptouchTask.java │ │ │ ├── IEsptouchTaskParameter.java │ │ │ └── EsptouchTaskParameter.java │ │ ├── protocol │ │ │ ├── TouchData.java │ │ │ ├── GuideCode.java │ │ │ ├── EsptouchGenerator.java │ │ │ ├── DataCode.java │ │ │ └── DatumCode.java │ │ ├── IEsptouchResult.java │ │ ├── EsptouchResult.java │ │ ├── util │ │ │ ├── CRC8.java │ │ │ ├── EspAES.java │ │ │ └── TouchNetUtil.java │ │ ├── IEsptouchTask.java │ │ ├── EsptouchTask.java │ │ └── udp │ │ │ ├── UDPSocketClient.java │ │ │ └── UDPSocketServer.java │ │ └── com │ │ └── reactnativesmartconfigswjava │ │ ├── SmartconfigSwjavaPackage.kt │ │ └── SmartconfigSwjavaModule.java ├── gradle.properties ├── .settings │ └── org.eclipse.buildship.core.prefs ├── .project ├── gradlew.bat ├── build.gradle └── gradlew ├── ios ├── SmartconfigSwjava-Bridging-Header.h ├── EspTouch │ ├── protocol │ │ ├── ESPGuideCode.h │ │ ├── ESPGuideCode.m │ │ ├── ESPDatumCode.h │ │ ├── ESPDataCode.h │ │ ├── ESPTouchGenerator.h │ │ ├── ESPDataCode.m │ │ ├── ESPTouchGenerator.m │ │ └── ESPDatumCode.m │ ├── ESPUtils │ │ ├── ESPAES.h │ │ ├── ESPTools.h │ │ ├── ESP_WifiUtil.h │ │ ├── ESPVersionMacro.h │ │ ├── ESP_CRC8.h │ │ ├── ESP_CRC8.m │ │ ├── ESP_NetUtil.h │ │ ├── ESPAES.m │ │ ├── ESP_ByteUtil.h │ │ ├── ESP_WifiUtil.m │ │ ├── ESP_ByteUtil.m │ │ ├── ESPTools.m │ │ └── ESP_NetUtil.m │ ├── ESPTouchDelegate.h │ ├── ESPTouchResult.h │ ├── udp │ │ ├── ESPUDPSocketServer.h │ │ └── ESPUDPSocketClient.h │ ├── task │ │ ├── ESPTouchResult.m │ │ └── ESPTouchTaskParameter.h │ └── ESPTouchTask.h ├── SmartconfigSwjava.m └── SmartconfigSwjava.swift ├── .editorconfig ├── react-native-smartconfig-quan.podspec ├── tsconfig.json ├── .gitignore ├── LICENSE ├── .circleci └── config.yml ├── README.md └── package.json /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // SmartconfigSwjavaExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /example/android/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | connection.project.dir= 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SmartconfigSwjavaExample", 3 | "displayName": "SmartconfigSwjava Example" 4 | } 5 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SmartconfigSwjava Example 3 | 4 | -------------------------------------------------------------------------------- /example/ios/SmartconfigSwjavaExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/ios/SmartconfigSwjavaExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | SmartconfigSwjava_kotlinVersion=1.3.50 2 | SmartconfigSwjava_compileSdkVersion=28 3 | SmartconfigSwjava_buildToolsVersion=28.0.3 4 | SmartconfigSwjava_targetSdkVersion=28 5 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ios/SmartconfigSwjava-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import "ESPTouchTask.h" 5 | #import "ESPTouchResult.h" 6 | #import "ESPTouchDelegate.h" 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nguyenvanquan7826/React-Native-Smart-Config-Quan/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /ios/EspTouch/protocol/ESPGuideCode.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPGuideCode.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/9/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPGuideCode : NSObject 12 | 13 | - (NSData *) getU16s; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/ios/SmartconfigSwjavaExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/SmartconfigSwjavaExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 4 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/IEsptouchListener.java: -------------------------------------------------------------------------------- 1 | package esptouch; 2 | 3 | public interface IEsptouchListener { 4 | /** 5 | * when new esptouch result is added, the listener will call 6 | * onEsptouchResultAdded callback 7 | * 8 | * @param result the Esptouch result 9 | */ 10 | void onEsptouchResultAdded(IEsptouchResult result); 11 | } 12 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'SmartconfigSwjavaExample' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | 5 | include ':reactnativesmartconfigswjava' 6 | project(':reactnativesmartconfigswjava').projectDir = new File(rootProject.projectDir, '../../android') 7 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | presets: ['module:metro-react-native-babel-preset'], 6 | plugins: [ 7 | [ 8 | 'module-resolver', 9 | { 10 | alias: { 11 | [pak.name]: path.join(__dirname, '..', pak.source), 12 | }, 13 | }, 14 | ], 15 | ], 16 | }; 17 | -------------------------------------------------------------------------------- /ios/SmartconfigSwjava.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "React/RCTViewManager.h" 3 | 4 | @interface RCT_EXTERN_MODULE(SmartconfigSwjava, NSObject) 5 | 6 | RCT_EXTERN_METHOD(stop) 7 | 8 | RCT_EXTERN_METHOD(start: (NSString *)ssid bssid:(NSString *)bssid password:(NSString *)password timeScan:(NSInteger)timeScan 9 | errorCallback:(RCTResponseSenderBlock *)errorCallback ) 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPUtils/ESPAES.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPAES.h 3 | // EspTouchDemo 4 | // 5 | // Created by AE on 2018/4/5. 6 | // 7 | 8 | #import 9 | 10 | @interface ESPAES : NSObject { 11 | @private NSString *key; 12 | } 13 | 14 | - (instancetype)initWithKey:(NSString *)secretKey; 15 | 16 | - (NSData *)AES128EncryptData:(NSData *)data; 17 | - (NSData *)AES128DecryptData:(NSData *)data; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0)) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/task/IEsptouchGenerator.java: -------------------------------------------------------------------------------- 1 | package esptouch.task; 2 | 3 | public interface IEsptouchGenerator { 4 | /** 5 | * Get guide code by the format of byte[][] 6 | * 7 | * @return guide code by the format of byte[][] 8 | */ 9 | byte[][] getGCBytes2(); 10 | 11 | /** 12 | * Get data code by the format of byte[][] 13 | * 14 | * @return data code by the format of byte[][] 15 | */ 16 | byte[][] getDCBytes2(); 17 | } 18 | -------------------------------------------------------------------------------- /example/ios/SmartconfigSwjavaExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (nonatomic, strong) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /example/ios/SmartconfigSwjavaExample/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | android_ 4 | Project android_ created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | android 4 | Project android created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPUtils/ESPTools.h: -------------------------------------------------------------------------------- 1 | // 2 | // EspNetUtils.h 3 | // Esp32Mesh 4 | // 5 | // Created by AE on 2018/4/19. 6 | // Copyright © 2018年 AE. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | @interface ESPTools : NSObject 13 | 14 | + (nullable NSString *)getCurrentWiFiSsid; 15 | + (nullable NSString *)getCurrentBSSID; 16 | 17 | + (NSString *)getIPAddress:(BOOL)preferIPv4; 18 | 19 | + (NSDictionary *)getIPAddresses; 20 | NS_ASSUME_NONNULL_END 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/reactnativesmartconfigswjava/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.reactnativesmartconfigswjava; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. This is used to schedule 9 | * rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "SmartconfigSwjavaExample"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/protocol/TouchData.java: -------------------------------------------------------------------------------- 1 | package esptouch.protocol; 2 | 3 | import esptouch.util.ByteUtil; 4 | 5 | public class TouchData { 6 | private final byte[] mData; 7 | 8 | public TouchData(String string) { 9 | mData = ByteUtil.getBytesByString(string); 10 | } 11 | 12 | public TouchData(byte[] data) { 13 | if (data == null) { 14 | throw new NullPointerException("data can't be null"); 15 | } 16 | mData = data; 17 | } 18 | 19 | public byte[] getData() { 20 | return mData; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPTouchDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchDelegate.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 8/14/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ESPTouchResult.h" 11 | 12 | 13 | @protocol ESPTouchDelegate 14 | 15 | /** 16 | * when new esptouch result is added, the listener will call 17 | * onEsptouchResultAdded callback 18 | * 19 | * @param result 20 | * the Esptouch result 21 | */ 22 | -(void) onEsptouchResultAddedWithResult: (ESPTouchResult *) result; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/task/ICodeData.java: -------------------------------------------------------------------------------- 1 | package esptouch.task; 2 | 3 | /** 4 | * the class used to represent some code to be transformed by UDP socket should implement the interface 5 | * 6 | * @author afunx 7 | */ 8 | public interface ICodeData { 9 | /** 10 | * Get the byte[] to be transformed. 11 | * 12 | * @return the byte[] to be transfromed 13 | */ 14 | byte[] getBytes(); 15 | 16 | /** 17 | * Get the char[](u8[]) to be transfromed. 18 | * 19 | * @return the char[](u8) to be transformed 20 | */ 21 | char[] getU8s(); 22 | } 23 | -------------------------------------------------------------------------------- /react-native-smartconfig-quan.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, "package.json"))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = "react-native-smartconfig-quan" 7 | s.version = package["version"] 8 | s.summary = package["description"] 9 | s.homepage = package["homepage"] 10 | s.license = package["license"] 11 | s.authors = package["author"] 12 | 13 | s.platforms = { :ios => "9.0" } 14 | s.source = { :git => "https://github.com/nguyenvanquan7826/React-Native-Smart-Config-Quan.git", :tag => "#{s.version}" } 15 | 16 | 17 | s.source_files = "ios/**/*.{h,m,mm,swift}" 18 | 19 | 20 | s.dependency "React" 21 | end 22 | -------------------------------------------------------------------------------- /ios/EspTouch/protocol/ESPGuideCode.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPGuideCode.m 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/9/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import "ESPGuideCode.h" 10 | #import "ESP_ByteUtil.h" 11 | 12 | #define GUIDE_CODE_LEN 4 13 | 14 | @implementation ESPGuideCode 15 | 16 | - (NSData *) getU16s 17 | { 18 | UInt16 guideU16s[GUIDE_CODE_LEN]; 19 | guideU16s[0] = 515; 20 | guideU16s[1] = 514; 21 | guideU16s[2] = 513; 22 | guideU16s[3] = 512; 23 | NSData* data = [[NSData alloc]initWithBytes:guideU16s length:GUIDE_CODE_LEN*2]; 24 | return data; 25 | } 26 | 27 | - (NSString *)description 28 | { 29 | NSData* data = [self getU16s]; 30 | return [ESP_ByteUtil getHexStringByData:data]; 31 | } 32 | 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-smartconfig-swjava-example", 3 | "description": "Example app for react-native-smartconfig-swjava", 4 | "version": "0.0.1", 5 | "private": true, 6 | "scripts": { 7 | "android": "react-native run-android", 8 | "ios": "react-native run-ios", 9 | "start": "react-native start" 10 | }, 11 | "dependencies": { 12 | "react": "16.11.0", 13 | "react-native": "0.62.2", 14 | "@react-native-community/geolocation": "^2.0.2", 15 | "@react-native-community/netinfo": "^5.9.6", 16 | "react-native-network-info": "^5.2.1" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "^7.9.6", 20 | "@babel/runtime": "^7.9.6", 21 | "babel-plugin-module-resolver": "^4.0.0", 22 | "metro-react-native-babel-preset": "^0.59.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /example/ios/SmartconfigSwjavaExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "react-native-smartconfig-swjava": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "importsNotUsedAsValues": "error", 11 | "forceConsistentCasingInFileNames": true, 12 | "jsx": "react", 13 | "lib": ["esnext"], 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitReturns": true, 18 | "noImplicitUseStrict": false, 19 | "noStrictGenericChecks": false, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "resolveJsonModule": true, 23 | "skipLibCheck": true, 24 | "strict": true, 25 | "target": "esnext" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .idea 35 | .gradle 36 | local.properties 37 | android.iml 38 | 39 | # Cocoapods 40 | # 41 | example/ios/Pods 42 | 43 | # node.js 44 | # 45 | node_modules/ 46 | npm-debug.log 47 | yarn-debug.log 48 | yarn-error.log 49 | 50 | # BUCK 51 | buck-out/ 52 | \.buckd/ 53 | android/app/libs 54 | android/keystores/debug.keystore 55 | 56 | # Expo 57 | .expo/* 58 | 59 | # generated by bob 60 | lib/ 61 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/IEsptouchResult.java: -------------------------------------------------------------------------------- 1 | package esptouch; 2 | 3 | import java.net.InetAddress; 4 | 5 | public interface IEsptouchResult { 6 | 7 | /** 8 | * check whether the esptouch task is executed suc 9 | * 10 | * @return whether the esptouch task is executed suc 11 | */ 12 | boolean isSuc(); 13 | 14 | /** 15 | * get the device's bssid 16 | * 17 | * @return the device's bssid 18 | */ 19 | String getBssid(); 20 | 21 | /** 22 | * check whether the esptouch task is cancelled by user 23 | * 24 | * @return whether the esptouch task is cancelled by user 25 | */ 26 | boolean isCancelled(); 27 | 28 | /** 29 | * get the ip address of the device 30 | * 31 | * @return the ip device of the device 32 | */ 33 | InetAddress getInetAddress(); 34 | } 35 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativesmartconfigswjava/SmartconfigSwjavaPackage.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativesmartconfigswjava 2 | 3 | import java.util.Arrays 4 | import java.util.Collections 5 | 6 | import com.facebook.react.ReactPackage 7 | import com.facebook.react.bridge.NativeModule 8 | import com.facebook.react.bridge.ReactApplicationContext 9 | import com.facebook.react.uimanager.ViewManager 10 | import com.facebook.react.bridge.JavaScriptModule 11 | 12 | class SmartconfigSwjavaPackage : ReactPackage { 13 | override fun createNativeModules(reactContext: ReactApplicationContext): List { 14 | return Arrays.asList(SmartconfigSwjavaModule(reactContext)) 15 | } 16 | 17 | override fun createViewManagers(reactContext: ReactApplicationContext): List> { 18 | return emptyList>() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPUtils/ESP_WifiUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESP_WifiUtil.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 6/15/16. 6 | // Copyright © 2016 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESP_WifiUtil : NSObject 12 | 13 | // refer to http://stackoverflow.com/questions/7072989/iphone-ipad-osx-how-to-get-my-ip-address-programmatically 14 | + (NSString *)getIPAddress:(BOOL)preferIPv4; 15 | 16 | // refer to http://stackoverflow.com/questions/7072989/iphone-ipad-osx-how-to-get-my-ip-address-programmatically 17 | + (NSDictionary *)getIPAddresses; 18 | 19 | /** 20 | * get local ip address by IPv4 21 | * 22 | * @return local ip address by IPv4(or nil when en0/ipv4 unaccessible) 23 | */ 24 | + (NSString *)getIPAddress4; 25 | 26 | /** 27 | * get local ip address by IPv6 28 | * 29 | * @return local ip address by IPv6(or nil when en0/ipv6 unaccessible) 30 | */ 31 | + (NSString *)getIpAddress6; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /ios/EspTouch/protocol/ESPDatumCode.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPDatumCode.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/9/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPDatumCode : NSObject 12 | { 13 | @private 14 | NSMutableArray *_dataCodes; 15 | } 16 | 17 | /** 18 | * Constructor of DatumCode 19 | * 20 | * @param apSsid 21 | * the Ap's ssid 22 | * @param apBssid 23 | * the Ap's bssid 24 | * @param apPwd 25 | * the Ap's password ssid 26 | * @param ipAddrData 27 | * the ip address of the phone or pad 28 | * @param isSsidHidden 29 | * whether the Ap's ssid is hidden 30 | * 31 | */ 32 | - (id) initWithSsid: (NSData *) apSsid andApBssid: (NSData *) apBssid andApPwd: (NSData*) apPwd andInetAddrData: (NSData *) ipAddrData andIsSsidHidden: (BOOL) isSsidHidden; 33 | 34 | - (NSData *) getBytes; 35 | 36 | - (NSData *) getU16s; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useAndroidX=true 21 | android.enableJetifier=true 22 | FLIPPER_VERSION=0.33.1 23 | -------------------------------------------------------------------------------- /ios/EspTouch/protocol/ESPDataCode.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPDataCode.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/9/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define DATA_CODE_LEN 6 12 | 13 | /** 14 | * one data format:(data code should have 2 to 65 data) 15 | * 16 | * control byte high 4 bits low 4 bits 17 | * 1st 9bits: 0x0 crc(high) data(high) 18 | * 2nd 9bits: 0x1 sequence header 19 | * 3rd 9bits: 0x0 crc(low) data(low) 20 | * 21 | * sequence header: 0,1,2,... 22 | * 23 | * @author afunx 24 | * 25 | */ 26 | @interface ESPDataCode : NSObject 27 | { 28 | @private 29 | Byte _seqHeader; 30 | @private 31 | Byte _dataHigh; 32 | @private 33 | Byte _dataLow; 34 | @private 35 | Byte _crcHigh; 36 | @private 37 | Byte _crcLow; 38 | } 39 | 40 | - (NSData*) getBytes; 41 | 42 | - (id) initWithU8: (UInt8) u8 andIndex: (int) index; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPUtils/ESPVersionMacro.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPVersionMacro.h 3 | // suite 4 | // 5 | // Created by fby on 5/16/16. 6 | // Copyright © 2016 fby. All rights reserved. 7 | // 8 | 9 | #ifndef ESPVersionMacro_h 10 | #define ESPVersionMacro_h 11 | #import 12 | 13 | #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) 14 | #define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) 15 | #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 16 | #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) 17 | #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) 18 | 19 | 20 | #endif /* ESPVersionMacro_h */ 21 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPTouchResult.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchResult.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/14/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPTouchResult : NSObject 12 | 13 | // it is used to check whether the esptouch task is executed suc 14 | @property (nonatomic,assign) BOOL isSuc; 15 | 16 | // it is used to store the device's bssid 17 | @property (nonatomic,strong) NSString * bssid; 18 | 19 | // it is used to check whether the esptouch task is cancelled by user 20 | @property (atomic,assign) BOOL isCancelled; 21 | 22 | // it is used to store the device's ip address 23 | @property (atomic) NSData * ipAddrData; 24 | 25 | /** 26 | * Constructor of EsptouchResult 27 | * 28 | * @param isSuc whether the esptouch task is executed suc 29 | * @param bssid the device's bssid 30 | * @param ipAddrData the device's ip address 31 | */ 32 | - (id) initWithIsSuc: (BOOL) isSuc andBssid: (NSString *) bssid andInetAddrData: (NSData *) ipAddrData; 33 | 34 | - (NSString *) getAddressString; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 hieptran 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ios/EspTouch/udp/ESPUDPSocketServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPUDPSocketServer.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/13/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define BUFFER_SIZE 64 12 | 13 | @interface ESPUDPSocketServer : NSObject 14 | { 15 | @private 16 | Byte _buffer[BUFFER_SIZE]; 17 | } 18 | 19 | @property (nonatomic, assign) int port; 20 | 21 | - (void) close; 22 | 23 | - (void) interrupt; 24 | 25 | /** 26 | * Set the socket timeout in milliseconds 27 | * 28 | * @param timeout 29 | * the timeout in milliseconds or 0 for no timeout. 30 | */ 31 | - (void) setSocketTimeout: (int) timeout; 32 | 33 | /** 34 | * Receive one byte from the port 35 | * 36 | * @return one byte receive from the port or UINT8_MAX(it impossible receive it from the socket) 37 | */ 38 | - (Byte) receiveOneByte4; 39 | 40 | - (NSData *) receiveSpecLenBytes4: (int)len; 41 | 42 | - (Byte) receiveOneByte6; 43 | 44 | - (NSData *) receiveSpecLenBytes6:(int)len; 45 | 46 | - (id) initWithPort: (int) port AndSocketTimeout: (int) socketTimeout; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "28.0.3" 6 | minSdkVersion = 16 7 | compileSdkVersion = 28 8 | targetSdkVersion = 28 9 | } 10 | repositories { 11 | google() 12 | jcenter() 13 | } 14 | dependencies { 15 | classpath("com.android.tools.build:gradle:3.5.2") 16 | 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | mavenLocal() 25 | maven { 26 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 27 | url("$rootDir/../node_modules/react-native/android") 28 | } 29 | maven { 30 | // Android JSC is installed from npm 31 | url("$rootDir/../node_modules/jsc-android/dist") 32 | } 33 | 34 | google() 35 | jcenter() 36 | maven { url 'https://www.jitpack.io' } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const blacklist = require('metro-config/src/defaults/blacklist'); 3 | const escape = require('escape-string-regexp'); 4 | const pak = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | const modules = Object.keys({ 9 | ...pak.peerDependencies, 10 | }); 11 | 12 | module.exports = { 13 | projectRoot: __dirname, 14 | watchFolders: [root], 15 | 16 | // We need to make sure that only one version is loaded for peerDependencies 17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules 18 | resolver: { 19 | blacklistRE: blacklist( 20 | modules.map( 21 | (m) => 22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 23 | ) 24 | ), 25 | 26 | extraNodeModules: modules.reduce((acc, name) => { 27 | acc[name] = path.join(__dirname, 'node_modules', name); 28 | return acc; 29 | }, {}), 30 | }, 31 | 32 | transformer: { 33 | getTransformOptions: async () => ({ 34 | transform: { 35 | experimentalImportSupport: false, 36 | inlineRequires: true, 37 | }, 38 | }), 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/protocol/GuideCode.java: -------------------------------------------------------------------------------- 1 | package esptouch.protocol; 2 | 3 | import esptouch.task.ICodeData; 4 | import esptouch.util.ByteUtil; 5 | 6 | public class GuideCode implements ICodeData { 7 | 8 | public static final int GUIDE_CODE_LEN = 4; 9 | 10 | @Override 11 | public byte[] getBytes() { 12 | throw new RuntimeException("DataCode don't support getBytes()"); 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | StringBuilder sb = new StringBuilder(); 18 | char[] dataU8s = getU8s(); 19 | for (int i = 0; i < GUIDE_CODE_LEN; i++) { 20 | String hexString = ByteUtil.convertU8ToHexString(dataU8s[i]); 21 | sb.append("0x"); 22 | if (hexString.length() == 1) { 23 | sb.append("0"); 24 | } 25 | sb.append(hexString).append(" "); 26 | } 27 | return sb.toString(); 28 | } 29 | 30 | @Override 31 | public char[] getU8s() { 32 | char[] guidesU8s = new char[GUIDE_CODE_LEN]; 33 | guidesU8s[0] = 515; 34 | guidesU8s[1] = 514; 35 | guidesU8s[2] = 513; 36 | guidesU8s[3] = 512; 37 | return guidesU8s; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ios/EspTouch/task/ESPTouchResult.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchResult.m 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/14/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import "ESPTouchResult.h" 10 | #import "ESP_NetUtil.h" 11 | 12 | @implementation ESPTouchResult 13 | 14 | - (id) initWithIsSuc: (BOOL) isSuc andBssid: (NSString *) bssid andInetAddrData: (NSData *) ipAddrData 15 | { 16 | self = [super init]; 17 | if (self) 18 | { 19 | self.isSuc = isSuc; 20 | self.bssid = bssid; 21 | self.isCancelled = NO; 22 | self.ipAddrData = ipAddrData; 23 | } 24 | return self; 25 | } 26 | 27 | - (NSString *)getAddressString { 28 | NSString *ipAddrDataStr = [ESP_NetUtil descriptionInetAddr4ByData:self.ipAddrData]; 29 | if (ipAddrDataStr==nil) { 30 | ipAddrDataStr = [ESP_NetUtil descriptionInetAddr6ByData:self.ipAddrData]; 31 | } 32 | return ipAddrDataStr; 33 | } 34 | 35 | - (NSString *)description 36 | { 37 | NSString *ipAddrDataStr = [self getAddressString]; 38 | return [[NSString alloc]initWithFormat:@"[isSuc: %@,isCancelled: %@,bssid: %@,inetAddress: %@]",self.isSuc? @"YES":@"NO", 39 | self.isCancelled? @"YES":@"NO" 40 | ,self.bssid 41 | ,ipAddrDataStr]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /ios/EspTouch/protocol/ESPTouchGenerator.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchGenerator.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/9/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPTouchGenerator : NSObject 12 | { 13 | @private 14 | NSMutableArray *_gcBytes2; 15 | @private 16 | NSMutableArray *_dcBytes2; 17 | } 18 | /** 19 | * Constructor of EsptouchGenerator, it will cost some time(maybe a bit much) 20 | * 21 | * @param apSsid 22 | * the Ap's ssid 23 | * @param apBssid 24 | * the Ap's bssid 25 | * @param apPwd 26 | * the Ap's password 27 | * @param ipAddrData 28 | * the ip address of the phone or pad 29 | * @param isSsidHidden 30 | * whether the Ap's ssid is hidden 31 | */ 32 | - (id) initWithSsid: (NSData *)apSsid andApBssid: (NSData *)apBssid andApPassword: (NSData *)apPwd andInetAddrData: (NSData *)ipAddrData andIsSsidHidden: (BOOL)isSsidHidden; 33 | 34 | /** 35 | * Get guide code by the format of byte[][] 36 | * @return guide code by the format of byte[][] 37 | */ 38 | - (NSArray *) getGCBytes2; 39 | 40 | /** 41 | * Get data code by the format of byte[][] 42 | * @return data code by the format of byte[][] 43 | */ 44 | - (NSArray *) getDCBytes2; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/EsptouchResult.java: -------------------------------------------------------------------------------- 1 | package esptouch; 2 | 3 | import java.net.InetAddress; 4 | import java.util.concurrent.atomic.AtomicBoolean; 5 | 6 | public class EsptouchResult implements IEsptouchResult { 7 | 8 | private final boolean mIsSuc; 9 | private final String mBssid; 10 | private final InetAddress mInetAddress; 11 | private AtomicBoolean mIsCancelled; 12 | 13 | /** 14 | * Constructor of EsptouchResult 15 | * 16 | * @param isSuc whether the esptouch task is executed suc 17 | * @param bssid the device's bssid 18 | * @param inetAddress the device's ip address 19 | */ 20 | public EsptouchResult(boolean isSuc, String bssid, InetAddress inetAddress) { 21 | this.mIsSuc = isSuc; 22 | this.mBssid = bssid; 23 | this.mInetAddress = inetAddress; 24 | this.mIsCancelled = new AtomicBoolean(false); 25 | } 26 | 27 | @Override 28 | public boolean isSuc() { 29 | return this.mIsSuc; 30 | } 31 | 32 | @Override 33 | public String getBssid() { 34 | return this.mBssid; 35 | } 36 | 37 | @Override 38 | public boolean isCancelled() { 39 | return mIsCancelled.get(); 40 | } 41 | 42 | public void setIsCancelled(boolean isCancelled) { 43 | this.mIsCancelled.set(isCancelled); 44 | } 45 | 46 | @Override 47 | public InetAddress getInetAddress() { 48 | return this.mInetAddress; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /ios/EspTouch/udp/ESPUDPSocketClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPUDPSocketClient.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/13/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPUDPSocketClient : NSObject 12 | 13 | - (void) close; 14 | 15 | - (void) interrupt; 16 | 17 | /** 18 | * send the data by UDP 19 | * 20 | * @param bytesArray2 21 | * the array of datas to be sent 22 | * @param targetHostName 23 | * the host name of target, e.g. 192.168.1.101 24 | * @param port 25 | * the port of target 26 | * @param interval 27 | * the milliseconds to between each UDP sent 28 | */ 29 | - (void) sendDataWithBytesArray2: (NSArray *) bytesArray2 ToTargetHostName: (NSString *)targetHostName WithPort: (int) port 30 | andInterval: (long) interval; 31 | 32 | /** 33 | * send the data by UDP 34 | * 35 | * @param bytesArray2 36 | * the data to be sent 37 | * @param offset 38 | * the offset which data to be sent 39 | * @param count 40 | * the count of the data 41 | * @param targetHostName 42 | * the host name of target, e.g. 192.168.1.101 43 | * @param port 44 | * the port of target 45 | * @param interval 46 | * the milliseconds to between each UDP sent 47 | */ 48 | - (void) sendDataWithBytesArray2: (NSArray *) bytesArray2 Offset: (NSUInteger) offset Count: (NSUInteger) count ToTargetHostName: (NSString *)targetHostName WithPort: (int) port 49 | andInterval: (long) interval; 50 | @end 51 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { DeviceEventEmitter, NativeEventEmitter, NativeModules, Platform } from 'react-native'; 2 | 3 | let { SmartconfigSwjava } = NativeModules; 4 | 5 | const eventEmitter = new NativeEventEmitter(SmartconfigSwjava); 6 | var subscription; 7 | 8 | const startSmartConfig = (ssid, bssid, password, timeScan, callback) => { 9 | let eventNameToListener = 'SmartConfig'; 10 | 11 | if (Platform.OS == 'ios') { 12 | console.log('start ios config'); 13 | 14 | if (typeof subscription !== 'undefined' && subscription) { 15 | subscription.remove(); 16 | } 17 | 18 | subscription = eventEmitter.addListener(eventNameToListener, callback); 19 | SmartconfigSwjava.start(ssid, bssid, password, timeScan, callback); 20 | 21 | } else { 22 | console.log('start android config'); 23 | 24 | let taskCount = 1; // only find 1 device 25 | if (typeof subscription !== 'undefined' && subscription) { 26 | console.log('remove listener'); 27 | subscription.remove(); 28 | } 29 | subscription = DeviceEventEmitter.addListener(eventNameToListener, callback); 30 | SmartconfigSwjava.start(ssid, bssid, password, timeScan, taskCount); 31 | } 32 | }; 33 | 34 | const stopSmartConfig = () => { 35 | console.log('Stop smart config'); 36 | SmartconfigSwjava.stop(); 37 | }; 38 | 39 | 40 | class SmartConfig { 41 | static start(ssid, bssid, password, timeScan, callback) { 42 | startSmartConfig(ssid, bssid, password, timeScan, callback); 43 | } 44 | 45 | static stop() { 46 | stopSmartConfig(); 47 | } 48 | } 49 | 50 | export default SmartConfig; 51 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPUtils/ESP_CRC8.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESP_CRC8.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 3/23/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define CRC_POLYNOM 0x8c 12 | 13 | #define CRC_INITIAL 0x00 14 | 15 | // the interface is copied from the interface Checksum from Java 16 | @interface ESP_CRC8 : NSObject 17 | 18 | /** 19 | * Returns the current calculated checksum value. 20 | * 21 | * @return the checksum. 22 | */ 23 | - (long)getValue; 24 | 25 | /** 26 | * Resets the checksum value applied before beginning calculations on a new 27 | * stream of data. 28 | */ 29 | - (void)reset; 30 | 31 | /** 32 | * Updates the checksum with the given bytes. 33 | * 34 | * @param buf 35 | * the byte array from which to read the bytes. 36 | * @param off 37 | * the initial position in {@code buf} to read the bytes from. 38 | * @param nbytes 39 | * the number of bytes to read from {@code buf}. 40 | */ 41 | - (void)updateWithBuf:(Byte[])buf Off:(int)off Nbytes:(int)nbytes; 42 | 43 | /** 44 | * Updates the checksum with the given bytes. 45 | * 46 | * @param buf 47 | * the byte array from which to read the bytes. 48 | * @param nbytes 49 | * the number of bytes to read from {@code buf}. 50 | */ 51 | - (void)updateWithBuf:(Byte [])buf Nbytes:(int)nbytes; 52 | 53 | /** 54 | * Updates the checksum value with the given byte. 55 | * 56 | * @param value 57 | * the byte to update the checksum with. 58 | */ 59 | - (void)updateWithValue:(int)value; 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /ios/EspTouch/protocol/ESPDataCode.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPDataCode.m 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 4/9/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import "ESPDataCode.h" 10 | #import "ESP_ByteUtil.h" 11 | #import "ESP_CRC8.h" 12 | 13 | #define INDEX_MAX 127 14 | 15 | @implementation ESPDataCode 16 | 17 | - (id) initWithU8: (UInt8) u8 andIndex: (int) index 18 | { 19 | if (index > INDEX_MAX) 20 | { 21 | perror("index > INDEX_MAX"); 22 | } 23 | self = [super init]; 24 | if (self) 25 | { 26 | NSData* u8Data = [ESP_ByteUtil splitUint8To2Bytes:u8]; 27 | [u8Data getBytes:&_dataHigh range:NSMakeRange(0, 1)]; 28 | [u8Data getBytes:&_dataLow range:NSMakeRange(1, 1)]; 29 | ESP_CRC8 *crc = [[ESP_CRC8 alloc]init]; 30 | [crc updateWithValue:u8]; 31 | [crc updateWithValue:index]; 32 | NSData* crcData = [ESP_ByteUtil splitUint8To2Bytes:[crc getValue]]; 33 | [crcData getBytes:&_crcHigh range:NSMakeRange(0, 1)]; 34 | [crcData getBytes:&_crcLow range:NSMakeRange(1, 1)]; 35 | _seqHeader = index; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSData *) getBytes 41 | { 42 | Byte bytes[DATA_CODE_LEN]; 43 | bytes[0] = 0x00; 44 | bytes[1] = [ESP_ByteUtil combine2bytesToOneWithHigh:_crcHigh andLow:_dataHigh]; 45 | bytes[2] = 0x01; 46 | bytes[3] = _seqHeader; 47 | bytes[4] = 0x00; 48 | bytes[5] = [ESP_ByteUtil combine2bytesToOneWithHigh:_crcLow andLow:_dataLow]; 49 | NSData* data = [[NSData alloc]initWithBytes:bytes length:DATA_CODE_LEN]; 50 | return data; 51 | } 52 | 53 | - (NSString *)description 54 | { 55 | NSData* data = [self getBytes]; 56 | return [ESP_ByteUtil getHexStringByData:data]; 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPUtils/ESP_CRC8.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESP_CRC8.m 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 3/23/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import "ESP_CRC8.h" 10 | 11 | @implementation ESP_CRC8 12 | 13 | static ushort crcTable[256]; 14 | 15 | NSNumber *_init; 16 | NSNumber *_value; 17 | 18 | +(void) initialize 19 | { 20 | for (ushort dividend=0; dividend < 256; dividend++) 21 | { 22 | ushort remainder = dividend; 23 | for (ushort bit = 0; bit < 8; ++bit) 24 | { 25 | if ((remainder & 0x01) != 0) 26 | { 27 | remainder = (remainder >> 1) ^ CRC_POLYNOM; 28 | } 29 | else 30 | { 31 | remainder >>= 1; 32 | } 33 | crcTable[dividend] = (ushort) remainder; 34 | } 35 | } 36 | } 37 | 38 | -(id) init 39 | { 40 | if(self = [super init]) 41 | { 42 | _init = [[NSNumber alloc]initWithInt:CRC_INITIAL]; 43 | _value = [[NSNumber alloc] initWithInt:CRC_INITIAL]; 44 | } 45 | return self; 46 | } 47 | 48 | - (long)getValue 49 | { 50 | return [_value unsignedShortValue] & 0xff; 51 | } 52 | 53 | - (void)reset 54 | { 55 | _value = _init; 56 | } 57 | 58 | - (void)updateWithBuf:(Byte[])buf Off:(int)off Nbytes:(int)nbytes 59 | { 60 | for (int i = 0; i < nbytes; i++) 61 | { 62 | int data = buf[off + i] ^ _value.intValue; 63 | int value = crcTable[data & 0xff] ^ (_value.intValue << 8); 64 | _value = [NSNumber numberWithInt:value]; 65 | } 66 | } 67 | 68 | - (void)updateWithBuf:(Byte [])buf Nbytes:(int)nbytes 69 | { 70 | [self updateWithBuf:buf Off:0 Nbytes:nbytes]; 71 | } 72 | 73 | 74 | - (void)updateWithValue:(int)value 75 | { 76 | Byte b[1] = { (Byte)value }; 77 | [self updateWithBuf:b Nbytes:1]; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/protocol/EsptouchGenerator.java: -------------------------------------------------------------------------------- 1 | package esptouch.protocol; 2 | 3 | import java.net.InetAddress; 4 | 5 | import esptouch.task.IEsptouchGenerator; 6 | import esptouch.util.ByteUtil; 7 | 8 | public class EsptouchGenerator implements IEsptouchGenerator { 9 | 10 | private final byte[][] mGcBytes2; 11 | private final byte[][] mDcBytes2; 12 | 13 | /** 14 | * Constructor of EsptouchGenerator, it will cost some timeText(maybe a bit 15 | * much) 16 | * 17 | * @param apSsid the Ap's ssid 18 | * @param apBssid the Ap's bssid 19 | * @param apPassword the Ap's password 20 | * @param inetAddress the phone's or pad's local ip address allocated by Ap 21 | * @param isSsidHiden whether the Ap's ssid is hidden 22 | */ 23 | public EsptouchGenerator(byte[] apSsid, byte[] apBssid, byte[] apPassword, 24 | InetAddress inetAddress, boolean isSsidHiden) { 25 | // generate guide code 26 | GuideCode gc = new GuideCode(); 27 | char[] gcU81 = gc.getU8s(); 28 | mGcBytes2 = new byte[gcU81.length][]; 29 | 30 | for (int i = 0; i < mGcBytes2.length; i++) { 31 | mGcBytes2[i] = ByteUtil.genSpecBytes(gcU81[i]); 32 | } 33 | 34 | // generate data code 35 | DatumCode dc = new DatumCode(apSsid, apBssid, apPassword, inetAddress, 36 | isSsidHiden); 37 | char[] dcU81 = dc.getU8s(); 38 | mDcBytes2 = new byte[dcU81.length][]; 39 | 40 | for (int i = 0; i < mDcBytes2.length; i++) { 41 | mDcBytes2[i] = ByteUtil.genSpecBytes(dcU81[i]); 42 | } 43 | } 44 | 45 | @Override 46 | public byte[][] getGCBytes2() { 47 | return mGcBytes2; 48 | } 49 | 50 | @Override 51 | public byte[][] getDCBytes2() { 52 | return mDcBytes2; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /example/ios/SmartconfigSwjavaExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | SmartconfigSwjava Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | NSAllowsArbitraryLoads 30 | 31 | NSExceptionDomains 32 | 33 | localhost 34 | 35 | NSExceptionAllowsInsecureHTTPLoads 36 | 37 | 38 | 39 | 40 | NSLocationWhenInUseUsageDescription 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UIViewControllerBasedStatusBarAppearance 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/util/CRC8.java: -------------------------------------------------------------------------------- 1 | package esptouch.util; 2 | 3 | import java.util.zip.Checksum; 4 | 5 | public class CRC8 implements Checksum { 6 | 7 | private static final short[] crcTable = new short[256]; 8 | private static final short CRC_POLYNOM = 0x8c; 9 | private static final short CRC_INITIAL = 0x00; 10 | 11 | static { 12 | for (int dividend = 0; dividend < 256; dividend++) { 13 | int remainder = dividend;// << 8; 14 | for (int bit = 0; bit < 8; ++bit) 15 | if ((remainder & 0x01) != 0) 16 | remainder = (remainder >>> 1) ^ CRC_POLYNOM; 17 | else 18 | remainder >>>= 1; 19 | crcTable[dividend] = (short) remainder; 20 | } 21 | } 22 | 23 | private final short init; 24 | private short value; 25 | 26 | public CRC8() { 27 | this.value = this.init = CRC_INITIAL; 28 | } 29 | 30 | @Override 31 | public void update(byte[] buffer, int offset, int len) { 32 | for (int i = 0; i < len; i++) { 33 | int data = buffer[offset + i] ^ value; 34 | value = (short) (crcTable[data & 0xff] ^ (value << 8)); 35 | } 36 | } 37 | 38 | /** 39 | * Updates the current checksum with the specified array of bytes. 40 | * Equivalent to calling update(buffer, 0, buffer.length). 41 | * 42 | * @param buffer the byte array to update the checksum with 43 | */ 44 | public void update(byte[] buffer) { 45 | update(buffer, 0, buffer.length); 46 | } 47 | 48 | @Override 49 | public void update(int b) { 50 | update(new byte[]{(byte) b}, 0, 1); 51 | } 52 | 53 | @Override 54 | public long getValue() { 55 | return value & 0xff; 56 | } 57 | 58 | @Override 59 | public void reset() { 60 | value = init; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /android/src/main/java/esptouch/task/__IEsptouchTask.java: -------------------------------------------------------------------------------- 1 | package esptouch.task; 2 | 3 | import java.util.List; 4 | 5 | import esptouch.IEsptouchListener; 6 | import esptouch.IEsptouchResult; 7 | 8 | /** 9 | * IEsptouchTask defined the task of esptouch should offer. INTERVAL here means 10 | * the milliseconds of interval of the step. REPEAT here means the repeat times 11 | * of the step. 12 | * 13 | * @author afunx 14 | */ 15 | public interface __IEsptouchTask { 16 | 17 | /** 18 | * Turn on or off the log. 19 | */ 20 | static final boolean DEBUG = true; 21 | 22 | /** 23 | * set the esptouch listener, when one device is connected to the Ap, it will be called back 24 | * 25 | * @param esptouchListener when one device is connected to the Ap, it will be called back 26 | */ 27 | void setEsptouchListener(IEsptouchListener esptouchListener); 28 | 29 | /** 30 | * Interrupt the Esptouch Task when User tap back or close the Application. 31 | */ 32 | void interrupt(); 33 | 34 | /** 35 | * Note: !!!Don't call the task at UI Main Thread or RuntimeException will 36 | * be thrown Execute the Esptouch Task and return the result 37 | * 38 | * @return the IEsptouchResult 39 | * @throws RuntimeException 40 | */ 41 | IEsptouchResult executeForResult() throws RuntimeException; 42 | 43 | /** 44 | * Note: !!!Don't call the task at UI Main Thread or RuntimeException will 45 | * be thrown Execute the Esptouch Task and return the result 46 | * 47 | * @param expectTaskResultCount the expect result count(if expectTaskResultCount <= 0, 48 | * expectTaskResultCount = Integer.MAX_VALUE) 49 | * @return the list of IEsptouchResult 50 | * @throws RuntimeException 51 | */ 52 | List executeForResults(int expectTaskResultCount) throws RuntimeException; 53 | 54 | boolean isCancelled(); 55 | } 56 | -------------------------------------------------------------------------------- /ios/EspTouch/ESPUtils/ESP_NetUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPNetUtil.h 3 | // EspTouchDemo 4 | // 5 | // Created by fby on 5/15/15. 6 | // Copyright (c) 2015 fby. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESP_NetUtil : NSObject 12 | 13 | /** 14 | * get local ip v4 or nil 15 | * 16 | * @return local ip v4 or nil 17 | */ 18 | + (NSString *) getLocalIPv4; 19 | 20 | /** 21 | * get local ip v6 or nil 22 | * 23 | * @return local ip v6 or nil 24 | */ 25 | + (NSString *) getLocalIPv6; 26 | 27 | /** 28 | * whether the ipAddr is v4 29 | * 30 | * @return whether the ipAddr is v4 31 | */ 32 | + (BOOL) isIPv4Addr:(NSString *)ipAddr; 33 | 34 | /** 35 | * whether the ipAddr v4 is private 36 | * 37 | * @return whether the ipAddr v4 is private 38 | */ 39 | + (BOOL) isIPv4PrivateAddr:(NSString *)ipAddr; 40 | 41 | /** 42 | * get the local ip address by local inetAddress ip4 43 | * 44 | * @param localInetAddr4 local inetAddress ip4 45 | */ 46 | + (NSData *) getLocalInetAddress4ByAddr:(NSString *) localInetAddr4; 47 | 48 | /** 49 | * get the invented local ip address by local port 50 | * 51 | */ 52 | + (NSData *) getLocalInetAddress6ByPort:(int) localPort; 53 | 54 | /** 55 | * parse InetAddress 56 | */ 57 | + (NSData *) parseInetAddrByData: (NSData *) inetAddrData andOffset: (int) offset andCount: (int) count; 58 | 59 | /** 60 | * descrpion inetAddrData for print pretty IPv4 61 | */ 62 | + (NSString *) descriptionInetAddr4ByData: (NSData *) inetAddrData; 63 | 64 | /** 65 | * descrpion inetAddrData for print pretty IPv6 66 | */ 67 | + (NSString *) descriptionInetAddr6ByData: (NSData *) inetAddrData; 68 | 69 | /** 70 | * parse bssid 71 | * 72 | * @param bssid the bssid 73 | * @return byte converted from bssid 74 | */ 75 | + (NSData *) parseBssid2bytes: (NSString *) bssid; 76 | 77 | /** 78 | * send a dummy GET to "https://8.8.8.8" just to get Network Permission after ios10.0(including) 79 | */ 80 | + (void) tryOpenNetworkPermission; 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /example/src/App.js: -------------------------------------------------------------------------------- 1 | import SmartConfig from 'react-native-smartconfig-quan'; 2 | import { Button, Text, View } from 'react-native'; 3 | import React, { useState } from 'react'; 4 | 5 | export default function App() { 6 | 7 | const [log, setLog] = useState('log here'); 8 | let foundDevice = false; 9 | 10 | const wifiName = 'Viettel'; 11 | const wifiPass = '0965677826'; 12 | // you can random bssid of wifi, but it need correct format 13 | const wifiBssid = '8a:29:9c:69:af:9b'; 14 | 15 | // timeout not work with android, on android default is 45s 16 | const TIME_OUT_SMART_CONFIG = 30 * 1000; // 30s 17 | 18 | function config() { 19 | setLog('configuring...'); 20 | foundDevice = false; 21 | 22 | SmartConfig.start(wifiName, wifiBssid, wifiPass, TIME_OUT_SMART_CONFIG, (event) => { 23 | console.log(event); 24 | let { eventName, data } = event; 25 | if (eventName === 'onFoundDevice') { 26 | foundDevice = true; 27 | data = JSON.parse(data); 28 | 29 | // data in event is ip of ESP 30 | setLog('Found device\nip: ' + data.ip + '\nbssid: ' + data.bssid); 31 | } else { 32 | if (!foundDevice) { 33 | setLog('Not found'); 34 | } 35 | } 36 | }); 37 | } 38 | 39 | function stopConfig() { 40 | SmartConfig.stop(); 41 | setLog('Stopped config'); 42 | } 43 | 44 | return ( 45 | 46 | {log} 47 | 48 | 49 |