Open vt-vaio opened 3 years ago
I am a Flutter developer I use iOS 14.6 version. My app is working.
The problem is solved.
I needed to include [self._esptouchTask setPackageBroadcast:true];
Have a nice day!!
Hi, @vt-vaio could you share where did you put that "[self._esptouchTask setPackageBroadcast:true]" im trying to work with esptouch but its not working.
Im getting: "can't find variable Esptouch"
Hi @jorgeangulo97, actually, I did a bit more. 1) Added SmartConfig plugin to my IONIC 5 project 2) When you compile the project for iOS, IONIC/Cordova automatically create an XCode project. In that XCode project, you will find The Esptouch.Framework along with two files espSmartconfig.h and espSmartconfig.m. 3) Downloaded the newest version (collection of m and h files) of ESPTouch and embedded into the XCode project 4) Removed Esptouch.Framework from Xcode project but kept the espSmartconfig.h and espSmartconfig.m files 5) Changed the espSmartconfig.m to point to the newest ESPTouch version from (3) 6) Below is the copy of the changed espSmartconfig.m file
#import "espSmartconfig.h"
@interface EspTouchDelegateImpl : NSObject<ESPTouchDelegate>
@property (nonatomic, strong) CDVInvokedUrlCommand *command;
@property (nonatomic, weak) id <CDVCommandDelegate> commandDelegate;
@end
@implementation EspTouchDelegateImpl
-(void) onEsptouchResultAddedWithResult: (ESPTouchResult *) result
{
NSString *InetAddress=[ESP_NetUtil descriptionInetAddr4ByData:result.ipAddrData];
NSString *text=[NSString stringWithFormat:@"bssid=%@,InetAddress=%@",result.bssid,InetAddress];
CDVPluginResult* pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: text];
[pluginResult setKeepCallbackAsBool:true];
//[self.commandDelegate sendPluginResult:pluginResult callbackId:self.command.callbackId]; //add by lianghuiyuan
}
@end
@implementation espSmartconfig
- (void) startConfig:(CDVInvokedUrlCommand *)command{
[self.commandDelegate runInBackground:^{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
[self._condition lock];
NSString *apSsid = (NSString *)[command.arguments objectAtIndex:0];
NSString *apBssid = (NSString *)[command.arguments objectAtIndex:1];
NSString *apPwd = (NSString *)[command.arguments objectAtIndex:2];
NSString *isSsidHiddenStr=(NSString *)[command.arguments objectAtIndex:3];
BOOL isSsidHidden = true;
if([isSsidHiddenStr compare:@"NO"]==NSOrderedSame){
isSsidHidden=false;
}
int taskCount = [[command.arguments objectAtIndex:4] intValue];
NSLog(@"ssid: %@, bssid: %@, apPwd: %@", apSsid, apBssid, apPwd);
// self._esptouchTask =
// [[ESPTouchTask alloc]initWithApSsid:apSsid andApBssid:apBssid andApPwd:apPwd andIsSsidHiden:isSsidHidden]; // deprecated
self._esptouchTask =
[[ESPTouchTask alloc]initWithApSsid:apSsid andApBssid:apBssid andApPwd:apPwd];
EspTouchDelegateImpl *esptouchDelegate=[[EspTouchDelegateImpl alloc]init];
esptouchDelegate.command=command;
esptouchDelegate.commandDelegate=self.commandDelegate;
[self._esptouchTask setEsptouchDelegate:esptouchDelegate];
[self._esptouchTask setPackageBroadcast:true];
[self._condition unlock];
NSArray * esptouchResultArray = [self._esptouchTask executeForResults:taskCount];
dispatch_async(queue, ^{
// show the result to the user in UI Main Thread
dispatch_async(dispatch_get_main_queue(), ^{
ESPTouchResult *firstResult = [esptouchResultArray objectAtIndex:0];
// check whether the task is cancelled and no results received
if (!firstResult.isCancelled)
{
//NSMutableString *mutableStr = [[NSMutableString alloc]init];
//NSUInteger count = 0;
// max results to be displayed, if it is more than maxDisplayCount,
// just show the count of redundant ones
//const int maxDisplayCount = 5;
if ([firstResult isSuc])
{
// for (int i = 0; i < [esptouchResultArray count]; ++i)
// {
// ESPTouchResult *resultInArray = [esptouchResultArray objectAtIndex:i];
// [mutableStr appendString:[resultInArray description]];
// [mutableStr appendString:@"\n"];
// count++;
// if (count >= maxDisplayCount)
// {
// break;
// }
// }
//
// if (count < [esptouchResultArray count])
// {
// [mutableStr appendString:[NSString stringWithFormat:@"\nthere's %lu more result(s) without showing\n",(unsigned long)([esptouchResultArray count] - count)]];
// }
ESPTouchResult *resultInArray = [esptouchResultArray objectAtIndex:0];
NSString *ipaddr = [ESP_NetUtil descriptionInetAddr4ByData:resultInArray.ipAddrData];
// device0 I think is suppose to be the index
NSString *result = [NSString stringWithFormat:@"Finished: device0,bssid=%@,InetAddress=%@.", resultInArray.bssid, ipaddr];
// NSDictionary* returnObj = @{@"ipaddr": ipaddr};
CDVPluginResult* pluginResult = nil;
// pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnObj];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:result];
[pluginResult setKeepCallbackAsBool:true];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
else
{
CDVPluginResult* pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @"Esptouch fail"];
[pluginResult setKeepCallbackAsBool:true];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}
});
});
}];
}
- (void) stopConfig:(CDVInvokedUrlCommand *)command{
[self._condition lock];
if (self._esptouchTask != nil)
{
[self._esptouchTask interrupt];
}
[self._condition unlock];
CDVPluginResult* pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @"cancel success"];
[pluginResult setKeepCallbackAsBool:true];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- (void)getNetworklist:(CDVInvokedUrlCommand*)command {
CDVPluginResult *pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not supported"];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:command.callbackId];
}
@end
The [self._esptouchTask setPackageBroadcast:true]; is on line #50.
Hi, @vt-vaio sorry for bother you again, i have been trying to setup like you said, but i dont find that "Esptouch.Framework" file.
If im not wrong i think it should be here right?
And ty for your help! :)
Hi, @vt-vaio sorry for bother you again, i have been trying to setup like you said, but i dont find that "Esptouch.Framework" file.
If im not wrong i think it should be here right?
And ty for your help! :)
HI @jorgeangulo97,
Just to make sure we have the same environment.
I am using cordova-plugin-smartconfig plugin for SmarConfig in my IONIC 5 app; Programming language: Angular (Type Script). After adding iOS platform and compiling the project (running ionic cordova run ios), I get a new Framework added to the automatically generated XCode project "Esptouch.Framework". The rest of what I did in the previous post.
I hope it is helpful.
V
Hi @vt-vaio its been a while. I was using ionic react for my app, but i swapped it to angular now cause of this plugin.
Could you tell me or show where did you put the h and m files? I mean the smarftconfig.h, smarftconfig.m and the ESPTouch h and m files are ESPTouchDelegate.h, ESPTouchTask.h and ESPTouchResult.h??
Did you put all together in the Plugins folder or?
Ty for your help! :)
Hi @jorgeangulo97, I will try to recall everything I did.
Pre-requisites: IONIC 5 app with Angular.
1) Added iOS platform
2) Install cordova-plugin-smartconfig plugin (I believe it comes from here: https://github.com/IOCare/cordova-plugin-smartconfig.git)
3) ionic cordova run ios (previously configured XCode, certificates, ...)
4) Opened XCode
5) Downloaded the newest version (collection of m and h files) of ESPTouch and embedded into the XCode project
6) Removed Esptouch.Framework (this framework, I believe, was automatically added to XCode project after I installed cordova-plugin-smartconfig plugin) from Xcode project but kept the espSmartconfig.h and espSmartconfig.m files
7) Changed the espSmartconfig.m to point to the newest ESPTouch version from (added in step 5)
This what I was doing as far as I can remember. To be honest, I spend two weeks until I got it working.
Perhaps you could do an experiment 1) Create a completely new IONIC 5 project 2) Add iOS platform 3) Configure XCode, make sure that you can install the app on the phone (SmartConfig won't work in simulator) 4) Add cordova-plugin-smartconfig plugin to your IONIC 5 project 5) Compile the iOS app and try to run it 6) Open XCode -> I would assume you should be able to locate Esptouch in your XCode project
Hope above is helpful. V.
Hi @vt-vaio i was following your first explanation and i couldn't do it work, but yesterday i realised about something. I swapped the files from the Esptouch.Framework and i added the Esptouch.Framework manually to the xcode because i couldn't get it automaticaly added.
After doing some test, this morning i tried again and it was working!! :D
I tried in the xcode Iphone X simulator and it works but obviously your cant connect an iot device but it was just for test, then i installed the app in the phone and it works.
To be honest i dont know if this is the best solution, I spend 1 month for it but atleast it works for now!
Ty for all your help it was really helpful :)
@jorgeangulo97, I am happy to hear that you've resolved the problem. I agree it is not an ideal solution, especially from a maintenance point of view. Building a plug-in would be the best solution I guess. I don't have time to do that at the moment. But would be happy to contribute in the future if you decide to build one yourself.
unsubscribe
At 2021-07-09 16:57:54, "vt-vaio" @.***> wrote:
@jorgeangulo97, I am happy to hear that you've resolved the problem. I agree it is not an ideal solution, especially from a maintenance point of view. Building a plug-in would be the best solution I guess. I don't have time to do that at the moment. But would be happy to contribute in the future if you decide to build one yourself.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
The code has been updated to try.
My iOS app that is using the ESPTouch framework does no longer work - it compiles without errors, but the SmartConfig does not seem to reach the ESP32 anymore. The iOS version is 14.6. I am using IONIC 5 with Angular for development.
Anyone facing the same issues? Any suggestions on how to fix it?
Thank you.