Open shushant43 opened 1 year ago
Can anyone help us out with this?
Hi @shushant43, can you please explain what kind of API call you need to make during provisioning?
@vikas-chandra-mnnit It’s an API call to update a few things related to our workflow.
@shushant43 Is it over BLE or simply a network call?
@vikas-chandra-mnnit A network call
@shushant43 Can you make the network call without disconnecting from the BLE device?
@vikas-chandra-mnnit No. Because at that stage the iOS device is connected to the BLE device’s access point.
@shushant43 Is it possible for you to share the code snippet here?
@vikas-chandra-mnnit
Disconnecting from the ESP device and checking for network
espDevice.disconnect()
checkForNetwork()
This works fine, the ESP device is disconnected and after the network reachability is restored, the network call is made.
After getting back the response from API, try to reconnect to the ESP device inside the success delegate
.observe(on: MainScheduler.instance)
.subscribe(onNext: { response in
self.espDevice.security = Utility.shared.espAppSettings.securityMode //secure
self.espDevice.connect(delegate: self) { status in
DispatchQueue.main.async {
switch status {
case .connected:
self.startProvisioning()
case let .failedToConnect(error):
self.step2FailedWithMessage(message: error.description)
default:
()
}
}
}
}, onError: { error in
self.step2FailedWithMessage(message: error.localizedDescription)
})
Provided POP via the delegate
extension StatusViewController: ESPDeviceConnectionDelegate {
func getProofOfPossesion(forDevice: ESPDevice, completionHandler: @escaping (String) -> Void) {
completionHandler("XXXXXX")
}
}
@shushant43 Please share the code for checkForNetwork() method.
@vikas-chandra-mnnit
let monitor = NWPathMonitor()
override func viewDidLoad() {
super.viewDidLoad()
monitor.pathUpdateHandler = { path in
let ssid = self.getWiFiName() ?? ""
if path.status == .satisfied && ssid != "" && !ssid.contains("XXXXX") {
self.monitor.cancel()
//API Calls based on some conditions
}
}
}
private func checkForNetwork() {
let queue = DispatchQueue(label: "Monitor")
monitor.start(queue: queue)
}
@vikas-chandra-mnnit What do you think?
@shushant43 Have you tried not disconnecting the BLE device and calling the checkNetwork() method? What happens in that case? I don't see any dependency between the two.
Problem
In our app, before we actually provision the device, we have to make an API call hence we have to disconnect from the ESPDevice and after making the api call, we have to connect to it again. But when we try to connect again with delegate while providing the correct POP, it doesn't connect. It fails to initialise a session because the network connection was lost.
To Reproduce
Expected behavior The device should be connected again without any issues
iOS information:
Provisioning information: