Skip to content

Commit

Permalink
Merge pull request tuanpmt#1 from hank121314/master
Browse files Browse the repository at this point in the history
add Set timeout effect
  • Loading branch information
qopqopqop committed Nov 6, 2018
2 parents 974b58f + 81c5b37 commit 09d4cc9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void stop() {
public void start(final ReadableMap options, final Promise promise) {
String ssid = options.getString("ssid");
String pass = options.getString("password");
int timeoutMillisecond=options.getInt("timeout");
Boolean hidden = false;
//Int taskResultCountStr = 1;
Log.d(TAG, "ssid " + ssid + ":pass " + pass);
Expand All @@ -73,6 +74,7 @@ public void onFinished(List<IEsptouchResult> result) {
WritableArray ret = Arguments.createArray();

Boolean resolved = false;
try{
for (IEsptouchResult resultInList : result) {
if(!resultInList.isCancelled() &&resultInList.getBssid() != null) {
WritableMap map = Arguments.createMap();
Expand All @@ -91,11 +93,14 @@ public void onFinished(List<IEsptouchResult> result) {
promise.resolve(ret);
} else {
Log.d(TAG, "Error run smartconfig");
promise.reject("new IllegalViewOperationException()");
promise.reject("Timeoutout");
}
}catch(Exception e){
Log.d(TAG, "Error, Smartconfig could not complete!");
promise.reject("Timeoutout", e);
}

}
}).execute(ssid, new String(""), pass, "YES", "1");
}).execute(ssid, new String(""), pass,String.valueOf(timeoutMillisecond) ,"YES", "1");
//promise.resolve(encoded);
//promise.reject("Error creating media file.");
//
Expand Down Expand Up @@ -141,15 +146,17 @@ protected List<IEsptouchResult> doInBackground(String... params) {
String apSsid = params[0];
String apBssid = params[1];
String apPassword = params[2];
String isSsidHiddenStr = params[3];
String taskResultCountStr = params[4];
int timeoutMillisecond = Integer.parseInt(params[3]);
String isSsidHiddenStr = params[4];
Log.d("Timeout","Timeout:"+timeoutMillisecond);
String taskResultCountStr = params[5];
boolean isSsidHidden = false;
if (isSsidHiddenStr.equals("YES")) {
isSsidHidden = true;
}
taskResultCount = Integer.parseInt(taskResultCountStr);
mEsptouchTask = new EsptouchTask(apSsid, apBssid, apPassword,
isSsidHidden, getCurrentActivity());
isSsidHidden,timeoutMillisecond, getCurrentActivity());

//mEsptouchTask.setEsptouchListener(myListener);
}
Expand Down
18 changes: 9 additions & 9 deletions ios/RCTSmartconfig/Smartconfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ @interface Smartconfig : NSObject<RCTBridgeModule>

@implementation Smartconfig
{


}

Expand Down Expand Up @@ -101,21 +101,21 @@ - (instancetype)init
[ret addObject: respData];
resolved = true;
if (![resultInArray isSuc])
break;
break;
}


}
if(resolved)
resolve(ret);
resolve(ret);
else
reject(RCTErrorUnspecified, nil, RCTErrorWithMessage(@"Timoutout or not Found"));
reject(RCTErrorUnspecified, nil, RCTErrorWithMessage(@"Timeoutout or not Found"));


});

});


}

Expand All @@ -139,11 +139,10 @@ - (NSArray *) executeForResults
NSString *ssid = [self.options valueForKey:@"ssid"];
NSString *password = [self.options valueForKey:@"password"];
NSString *bssid = [self.options valueForKey:@"bssid"];
int timeoutMillisecond = [[self.options valueForKey:@"timeout"] intValue];
BOOL hidden = [self.options valueForKey:@"hidden"];

RCTLogInfo(@"ssid %@ pass %@ bssid %@", ssid, password, bssid);
self._esptouchTask =
[[ESPTouchTask alloc]initWithApSsid:ssid andApBssid:bssid andApPwd:password andIsSsidHiden:hidden];
RCTLogInfo(@"ssid %@ pass %@ bssid %@ timeout %d", ssid, password, bssid,timeoutMillisecond);
self._esptouchTask = [[ESPTouchTask alloc]initWithApSsid:ssid andApBssid:bssid andApPwd:password andIsSsidHiden:hidden andTimeoutMillisecond:timeoutMillisecond];
// set delegate
[self._esptouchTask setEsptouchDelegate:self._esptouchDelegate];
[self._condition unlock];
Expand All @@ -153,3 +152,4 @@ - (NSArray *) executeForResults
}

@end

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-smartconfig",
"version": "0.2.2",
"version": "0.2.3",
"description": "react-native ESP8266 smartconfig module",
"nativePackage": true,
"scripts": {
Expand Down

0 comments on commit 09d4cc9

Please sign in to comment.