Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanpmt committed Feb 1, 2016
0 parents commit 66e5cb8
Show file tree
Hide file tree
Showing 51 changed files with 5,060 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IJ
#
.idea
.gradle
local.properties

# node.js
#
node_modules/
npm-debug.log
141 changes: 141 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@

== Getting started
=== Description

This is link:https://github.com/facebook/react-native[react-native] wrapper for link:https://github.com/EspressifApp[ESP8266 ESPTOUCH Smart config]

=== Featues
* Support both IOS and Android
* React Native Promise support
* Fast way to do configure wifi network for IOT device

=== Mostly automatic install
1. `npm install rnpm --global`
2. `npm install react-native-smartconfig@latest --save`
3. `rnpm link react-native-smartconfig`

=== Manual install
==== iOS
1. `npm install react-native-smartconfig@latest --save`
2. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
3. Go to `node_modules` ➜ `react-native-smartconfig` and add `RCTSmartconfig.xcodeproj`
4. In XCode, in the project navigator, select your project. Add `libRCTSmartconfig.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
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`.
5. Run your project (`Cmd+R`)


==== Android

1. `npm install react-native-smartconfig@latest --save`
2. Modify the ReactInstanceManager.builder() calls chain in `android/app/main/java/.../MainActivity.java` to include:

[source, javascript]
----
import com.tuanpm.RCTSmartconfig; // import
.addPackage(new RCTSmartconfigPackage()) //for older version
new RCTSmartconfigPackage() // for newest version of react-native
----

3. Append the following lines to `android/settings.gradle` before `include ':app'`:

[source, java]
----
include ':react-native-smartconfig'
project(':react-native-smartconfig').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-smartconfig/android')
----

4. Insert the following lines inside the dependencies block in `android/app/build.gradle`, don't missing `apply plugin:'java'` on top:

[source, java]
----
compile project(':react-native-smartconfig')
----

Notes:
[source, java]
----
dependencies {
compile project(':react-native-smartconfig')
}
----

[WARNING]
But not like this
[source, java]
----
buildscript {
...
dependencies {
compile project(':react-native-smartconfig')
}
}
----

== Usage

* Normal
[source, javascript]
----
var Smartconfig = require('react-native').NativeModules.Smartconfig;
Smartconfig.start({
type: 'esptouch', //or airkiss, now doesn't not effect
ssid: 'wifi-network-ssid',
bssid: 'filter-device', //null if not need to filter
password: 'wifi-password',
timeout: 50000 //now doesn't not effect
}).then(results) {
//Array of device success do smartconfig
console.log(results);
/*[
{
'bssid': 'device-bssi1', //device bssid
'ipv4': '192.168.1.11' //local ip address
},
{
'bssid': 'device-bssi2', //device bssid
'ipv4': '192.168.1.12' //local ip address
},
...
]*/
}.catch(error) {
};
Smartconfig.stop(); //interrupt task
----

=== Todo

* [ ] Support automatic get current wifi network ssid
* [ ] Set timeout effect
* [ ] Support airkiss

=== LICENSE

```
The MIT License (MIT)

Copyright (c) 2015 <TuanPM> https://twitter.com/tuanpmt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
34 changes: 34 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}

repositories {
mavenCentral()
}

dependencies {
compile "com.facebook.react:react-native:0.19.+"
}
51 changes: 51 additions & 0 deletions android/espressif/iot/esptouch/EsptouchResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.espressif.iot.esptouch;

import java.net.InetAddress;
import java.util.concurrent.atomic.AtomicBoolean;

public class EsptouchResult implements IEsptouchResult {

private final boolean mIsSuc;
private final String mBssid;
private final InetAddress mInetAddress;
private AtomicBoolean mIsCancelled;

/**
* Constructor of EsptouchResult
*
* @param isSuc whether the esptouch task is executed suc
* @param bssid the device's bssid
* @param inetAddress the device's ip address
*/
public EsptouchResult(boolean isSuc, String bssid,InetAddress inetAddress) {
this.mIsSuc = isSuc;
this.mBssid = bssid;
this.mInetAddress = inetAddress;
this.mIsCancelled = new AtomicBoolean(false);
}

@Override
public boolean isSuc() {
return this.mIsSuc;
}

@Override
public String getBssid() {
return this.mBssid;
}

@Override
public boolean isCancelled() {
return mIsCancelled.get();
}

public void setIsCancelled(boolean isCancelled){
this.mIsCancelled.set(isCancelled);
}

@Override
public InetAddress getInetAddress() {
return this.mInetAddress;
}

}
89 changes: 89 additions & 0 deletions android/espressif/iot/esptouch/EsptouchTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.espressif.iot.esptouch;

import java.util.List;

import android.content.Context;

import com.espressif.iot.esptouch.task.EsptouchTaskParameter;
import com.espressif.iot.esptouch.task.IEsptouchTaskParameter;
import com.espressif.iot.esptouch.task.__EsptouchTask;

public class EsptouchTask implements IEsptouchTask {

public __EsptouchTask _mEsptouchTask;
private IEsptouchTaskParameter _mParameter;

/**
* Constructor of EsptouchTask
*
* @param apSsid
* the Ap's ssid
* @param apBssid
* the Ap's bssid
* @param apPassword
* the Ap's password
* @param isSsidHidden
* whether the Ap's ssid is hidden
* @param context
* the Context of the Application
*/
public EsptouchTask(String apSsid, String apBssid, String apPassword,
boolean isSsidHidden, Context context) {
_mParameter = new EsptouchTaskParameter();
_mEsptouchTask = new __EsptouchTask(apSsid, apBssid, apPassword,
context, _mParameter, isSsidHidden);
}

/**
* Constructor of EsptouchTask
*
* @param apSsid
* the Ap's ssid
* @param apBssid
* the Ap's bssid
* @param apPassword
* the Ap's password
* @param isSsidHidden
* whether the Ap's ssid is hidden
* @param timeoutMillisecond
* (it should be >= 15000+6000) millisecond of total timeout
* @param context
* the Context of the Application
*/
public EsptouchTask(String apSsid, String apBssid, String apPassword,
boolean isSsidHidden, int timeoutMillisecond, Context context) {
_mParameter = new EsptouchTaskParameter();
_mParameter.setWaitUdpTotalMillisecond(timeoutMillisecond);
_mEsptouchTask = new __EsptouchTask(apSsid, apBssid, apPassword,
context, _mParameter, isSsidHidden);
}

@Override
public void interrupt() {
_mEsptouchTask.interrupt();
}

@Override
public IEsptouchResult executeForResult() throws RuntimeException {
return _mEsptouchTask.executeForResult();
}

@Override
public boolean isCancelled() {
return _mEsptouchTask.isCancelled();
}

@Override
public List<IEsptouchResult> executeForResults(int expectTaskResultCount)
throws RuntimeException {
if (expectTaskResultCount <= 0) {
expectTaskResultCount = Integer.MAX_VALUE;
}
return _mEsptouchTask.executeForResults(expectTaskResultCount);
}

@Override
public void setEsptouchListener(IEsptouchListener esptouchListener) {
_mEsptouchTask.setEsptouchListener(esptouchListener);
}
}
12 changes: 12 additions & 0 deletions android/espressif/iot/esptouch/IEsptouchListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.espressif.iot.esptouch;

public interface IEsptouchListener {
/**
* when new esptouch result is added, the listener will call
* onEsptouchResultAdded callback
*
* @param result
* the Esptouch result
*/
void onEsptouchResultAdded(IEsptouchResult result);
}
Loading

0 comments on commit 66e5cb8

Please sign in to comment.