Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Description

[react-native](https://github.com/facebook/react-native) module for [ESP8266 ESPTOUCH Smart config](https://github.com/EspressifApp)
[react-native](https://github.com/facebook/react-native) module for [ESP8266 ESPTOUCH Smart config v0.3.7.1](https://github.com/EspressifApp)

## Featues
* Support both IOS and Android
Expand Down Expand Up @@ -75,7 +75,7 @@ Smartconfig.start({
ssid: 'wifi-network-ssid',
bssid: 'filter-device', //"" if not need to filter (don't use null)
password: 'wifi-password',
timeout: 50000 //now doesn't not effect
timeout: 50000
}).then(function(results){
//Array of device success do smartconfig
console.log(results);
Expand All @@ -100,7 +100,6 @@ Smartconfig.stop(); //interrupt task
## Todo

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

## LICENSE
Expand Down
Empty file modified android/build.gradle
100644 → 100755
Empty file.
Empty file modified android/src/main/AndroidManifest.xml
100644 → 100755
Empty file.
84 changes: 42 additions & 42 deletions android/src/main/java/com/espressif/iot/esptouch/EsptouchResult.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,47 @@

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;
}
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;
}

}
167 changes: 95 additions & 72 deletions android/src/main/java/com/espressif/iot/esptouch/EsptouchTask.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,89 +1,112 @@
package com.espressif.iot.esptouch;

import java.util.List;

import android.content.Context;
import android.text.TextUtils;

import com.espressif.iot.esptouch.protocol.TouchData;
import com.espressif.iot.esptouch.task.EsptouchTaskParameter;
import com.espressif.iot.esptouch.task.IEsptouchTaskParameter;
import com.espressif.iot.esptouch.task.__EsptouchTask;
import com.espressif.iot.esptouch.util.EspAES;
import com.espressif.iot.esptouch.util.TouchNetUtil;

import java.util.List;

public class EsptouchTask implements IEsptouchTask {
private __EsptouchTask _mEsptouchTask;
private EsptouchTaskParameter _mParameter;

/**
* Constructor of EsptouchTask
*
* @param apSsid the Ap's ssid
* @param apBssid the Ap's bssid
* @param apPassword the Ap's password
* @param context the {@link Context} of the Application
*/
public EsptouchTask(String apSsid, String apBssid, String apPassword, Context context) {
this(apSsid, apBssid, apPassword, null, context);
}

/**
* Constructor of EsptouchTask
*
* @param apSsid the Ap's ssid
* @param apBssid the Ap's bssid
* @param apPassword the Ap's password
* @param context the {@link Context} of the Application
*/
public EsptouchTask(byte[] apSsid, byte[] apBssid, byte[] apPassword, Context context) {
this(apSsid, apBssid, apPassword, null, context);
}

private EsptouchTask(String apSsid, String apBssid, String apPassword, EspAES espAES, Context context) {
if (TextUtils.isEmpty(apSsid)) {
throw new NullPointerException("SSID can't be empty");
}
if (TextUtils.isEmpty(apBssid)) {
throw new NullPointerException("BSSID can't be empty");
}
if (apPassword == null) {
apPassword = "";
}
TouchData ssid = new TouchData(apSsid);
TouchData bssid = new TouchData(TouchNetUtil.parseBssid2bytes(apBssid));
TouchData password = new TouchData(apPassword);
init(context, ssid, bssid, password, espAES);
}

public __EsptouchTask _mEsptouchTask;
private IEsptouchTaskParameter _mParameter;
private EsptouchTask(byte[] apSsid, byte[] apBssid, byte[] apPassword, EspAES espAES, Context context) {
if (apSsid == null || apSsid.length == 0) {
throw new NullPointerException("SSID can't be empty");
}
if (apBssid == null || apBssid.length == 0) {
throw new NullPointerException("BSSID can't be empty");
}
if (apPassword == null) {
apPassword = new byte[0];
}
TouchData ssid = new TouchData(apSsid);
TouchData bssid = new TouchData(apBssid);
TouchData password = new TouchData(apPassword);
init(context, ssid, bssid, password, espAES);
}

/**
* 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);
}
private void init(Context context, TouchData ssid, TouchData bssid, TouchData password, EspAES aes) {
_mParameter = new EsptouchTaskParameter();
_mEsptouchTask = new __EsptouchTask(context, ssid, bssid, password, aes, _mParameter, true);
}

/**
* 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 void interrupt() {
_mEsptouchTask.interrupt();
}
@Override
public IEsptouchResult executeForResult() throws RuntimeException {
return _mEsptouchTask.executeForResult();
}

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

@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 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);
}

@Override
public void setEsptouchListener(IEsptouchListener esptouchListener) {
_mEsptouchTask.setEsptouchListener(esptouchListener);
}
@Override
public void setPackageBroadcast(boolean broadcast) {
_mParameter.setBroadcast(broadcast);
}
}
15 changes: 7 additions & 8 deletions android/src/main/java/com/espressif/iot/esptouch/IEsptouchListener.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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);
/**
* when new esptouch result is added, the listener will call
* onEsptouchResultAdded callback
*
* @param result the Esptouch result
*/
void onEsptouchResultAdded(IEsptouchResult result);
}
50 changes: 25 additions & 25 deletions android/src/main/java/com/espressif/iot/esptouch/IEsptouchResult.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
import java.net.InetAddress;

public interface IEsptouchResult {

/**
* check whether the esptouch task is executed suc
*
* @return whether the esptouch task is executed suc
*/
boolean isSuc();

/**
* get the device's bssid
*
* @return the device's bssid
*/
String getBssid();
/**
* check whether the esptouch task is executed suc
*
* @return whether the esptouch task is executed suc
*/
boolean isSuc();

/**
* check whether the esptouch task is cancelled by user
*
* @return whether the esptouch task is cancelled by user
*/
boolean isCancelled();
/**
* get the device's bssid
*
* @return the device's bssid
*/
String getBssid();

/**
* get the ip address of the device
*
* @return the ip device of the device
*/
InetAddress getInetAddress();
/**
* check whether the esptouch task is cancelled by user
*
* @return whether the esptouch task is cancelled by user
*/
boolean isCancelled();

/**
* get the ip address of the device
*
* @return the ip device of the device
*/
InetAddress getInetAddress();
}
Loading