Skip to content

Commit 66e5cb8

Browse files
committed
first release
0 parents  commit 66e5cb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+5060
-0
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
24+
25+
# Android/IJ
26+
#
27+
.idea
28+
.gradle
29+
local.properties
30+
31+
# node.js
32+
#
33+
node_modules/
34+
npm-debug.log

README.adoc

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
2+
== Getting started
3+
=== Description
4+
5+
This is link:https://github.com/facebook/react-native[react-native] wrapper for link:https://github.com/EspressifApp[ESP8266 ESPTOUCH Smart config]
6+
7+
=== Featues
8+
* Support both IOS and Android
9+
* React Native Promise support
10+
* Fast way to do configure wifi network for IOT device
11+
12+
=== Mostly automatic install
13+
1. `npm install rnpm --global`
14+
2. `npm install react-native-smartconfig@latest --save`
15+
3. `rnpm link react-native-smartconfig`
16+
17+
=== Manual install
18+
==== iOS
19+
1. `npm install react-native-smartconfig@latest --save`
20+
2. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
21+
3. Go to `node_modules` ➜ `react-native-smartconfig` and add `RCTSmartconfig.xcodeproj`
22+
4. In XCode, in the project navigator, select your project. Add `libRCTSmartconfig.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
23+
5. Click `RCTSmartconfig.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). In the `Search Paths` section, look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../../react-native/React` - mark as `recursive`.
24+
5. Run your project (`Cmd+R`)
25+
26+
27+
==== Android
28+
29+
1. `npm install react-native-smartconfig@latest --save`
30+
2. Modify the ReactInstanceManager.builder() calls chain in `android/app/main/java/.../MainActivity.java` to include:
31+
32+
[source, javascript]
33+
----
34+
import com.tuanpm.RCTSmartconfig; // import
35+
36+
37+
.addPackage(new RCTSmartconfigPackage()) //for older version
38+
39+
new RCTSmartconfigPackage() // for newest version of react-native
40+
----
41+
42+
3. Append the following lines to `android/settings.gradle` before `include ':app'`:
43+
44+
[source, java]
45+
----
46+
include ':react-native-smartconfig'
47+
project(':react-native-smartconfig').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-smartconfig/android')
48+
----
49+
50+
4. Insert the following lines inside the dependencies block in `android/app/build.gradle`, don't missing `apply plugin:'java'` on top:
51+
52+
[source, java]
53+
----
54+
55+
compile project(':react-native-smartconfig')
56+
----
57+
58+
Notes:
59+
[source, java]
60+
----
61+
dependencies {
62+
compile project(':react-native-smartconfig')
63+
}
64+
----
65+
66+
[WARNING]
67+
But not like this
68+
[source, java]
69+
----
70+
buildscript {
71+
...
72+
dependencies {
73+
compile project(':react-native-smartconfig')
74+
}
75+
}
76+
----
77+
78+
== Usage
79+
80+
* Normal
81+
[source, javascript]
82+
----
83+
var Smartconfig = require('react-native').NativeModules.Smartconfig;
84+
Smartconfig.start({
85+
type: 'esptouch', //or airkiss, now doesn't not effect
86+
ssid: 'wifi-network-ssid',
87+
bssid: 'filter-device', //null if not need to filter
88+
password: 'wifi-password',
89+
timeout: 50000 //now doesn't not effect
90+
}).then(results) {
91+
//Array of device success do smartconfig
92+
console.log(results);
93+
/*[
94+
{
95+
'bssid': 'device-bssi1', //device bssid
96+
'ipv4': '192.168.1.11' //local ip address
97+
},
98+
{
99+
'bssid': 'device-bssi2', //device bssid
100+
'ipv4': '192.168.1.12' //local ip address
101+
},
102+
...
103+
]*/
104+
}.catch(error) {
105+
106+
};
107+
108+
Smartconfig.stop(); //interrupt task
109+
----
110+
111+
=== Todo
112+
113+
* [ ] Support automatic get current wifi network ssid
114+
* [ ] Set timeout effect
115+
* [ ] Support airkiss
116+
117+
=== LICENSE
118+
119+
```
120+
The MIT License (MIT)
121+
122+
Copyright (c) 2015 <TuanPM> https://twitter.com/tuanpmt
123+
124+
Permission is hereby granted, free of charge, to any person obtaining a copy
125+
of this software and associated documentation files (the "Software"), to deal
126+
in the Software without restriction, including without limitation the rights
127+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
128+
copies of the Software, and to permit persons to whom the Software is
129+
furnished to do so, subject to the following conditions:
130+
131+
The above copyright notice and this permission notice shall be included in all
132+
copies or substantial portions of the Software.
133+
134+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
135+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
136+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
137+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
138+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
139+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
140+
SOFTWARE.
141+
```

android/build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:1.2.3'
8+
}
9+
}
10+
11+
apply plugin: 'com.android.library'
12+
13+
android {
14+
compileSdkVersion 23
15+
buildToolsVersion "23.0.1"
16+
17+
defaultConfig {
18+
minSdkVersion 16
19+
targetSdkVersion 21
20+
versionCode 1
21+
versionName "1.0"
22+
}
23+
lintOptions {
24+
abortOnError false
25+
}
26+
}
27+
28+
repositories {
29+
mavenCentral()
30+
}
31+
32+
dependencies {
33+
compile "com.facebook.react:react-native:0.19.+"
34+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.espressif.iot.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+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.espressif.iot.esptouch;
2+
3+
import java.util.List;
4+
5+
import android.content.Context;
6+
7+
import com.espressif.iot.esptouch.task.EsptouchTaskParameter;
8+
import com.espressif.iot.esptouch.task.IEsptouchTaskParameter;
9+
import com.espressif.iot.esptouch.task.__EsptouchTask;
10+
11+
public class EsptouchTask implements IEsptouchTask {
12+
13+
public __EsptouchTask _mEsptouchTask;
14+
private IEsptouchTaskParameter _mParameter;
15+
16+
/**
17+
* Constructor of EsptouchTask
18+
*
19+
* @param apSsid
20+
* the Ap's ssid
21+
* @param apBssid
22+
* the Ap's bssid
23+
* @param apPassword
24+
* the Ap's password
25+
* @param isSsidHidden
26+
* whether the Ap's ssid is hidden
27+
* @param context
28+
* the Context of the Application
29+
*/
30+
public EsptouchTask(String apSsid, String apBssid, String apPassword,
31+
boolean isSsidHidden, Context context) {
32+
_mParameter = new EsptouchTaskParameter();
33+
_mEsptouchTask = new __EsptouchTask(apSsid, apBssid, apPassword,
34+
context, _mParameter, isSsidHidden);
35+
}
36+
37+
/**
38+
* Constructor of EsptouchTask
39+
*
40+
* @param apSsid
41+
* the Ap's ssid
42+
* @param apBssid
43+
* the Ap's bssid
44+
* @param apPassword
45+
* the Ap's password
46+
* @param isSsidHidden
47+
* whether the Ap's ssid is hidden
48+
* @param timeoutMillisecond
49+
* (it should be >= 15000+6000) millisecond of total timeout
50+
* @param context
51+
* the Context of the Application
52+
*/
53+
public EsptouchTask(String apSsid, String apBssid, String apPassword,
54+
boolean isSsidHidden, int timeoutMillisecond, Context context) {
55+
_mParameter = new EsptouchTaskParameter();
56+
_mParameter.setWaitUdpTotalMillisecond(timeoutMillisecond);
57+
_mEsptouchTask = new __EsptouchTask(apSsid, apBssid, apPassword,
58+
context, _mParameter, isSsidHidden);
59+
}
60+
61+
@Override
62+
public void interrupt() {
63+
_mEsptouchTask.interrupt();
64+
}
65+
66+
@Override
67+
public IEsptouchResult executeForResult() throws RuntimeException {
68+
return _mEsptouchTask.executeForResult();
69+
}
70+
71+
@Override
72+
public boolean isCancelled() {
73+
return _mEsptouchTask.isCancelled();
74+
}
75+
76+
@Override
77+
public List<IEsptouchResult> executeForResults(int expectTaskResultCount)
78+
throws RuntimeException {
79+
if (expectTaskResultCount <= 0) {
80+
expectTaskResultCount = Integer.MAX_VALUE;
81+
}
82+
return _mEsptouchTask.executeForResults(expectTaskResultCount);
83+
}
84+
85+
@Override
86+
public void setEsptouchListener(IEsptouchListener esptouchListener) {
87+
_mEsptouchTask.setEsptouchListener(esptouchListener);
88+
}
89+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.espressif.iot.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
9+
* the Esptouch result
10+
*/
11+
void onEsptouchResultAdded(IEsptouchResult result);
12+
}

0 commit comments

Comments
 (0)