aws / amazon-freertos-ble-ios-sdk

iOS SDK for FreeRTOS Bluetooth Devices
Apache License 2.0
42 stars 31 forks source link

Return error when incorrect password is provided #17

Closed johntvogt closed 3 years ago

johntvogt commented 3 years ago

When calling AmazonFreeRTOSManager.shared.devices[uuid]?.saveNetwork() there is no return for that if the password is incorrect, this does not work in the demo app for iOS either. It would be very helpful if we could get that added to both so we can implement the same feature that the Android SDK already supports.

ravibhagavandas commented 3 years ago

@johntvogt Thanks for raising this. We will work on adding this feature to IOS SDK.

dgranahan commented 3 years ago

Is this different than setting connect: true in SaveNetworkReq?

johntvogt commented 3 years ago

From what I can tell wouldn't that just reconnect if there is a failure and in the case of a incorrrect password that would just constantly keep trying again with no reason or action to take for the user. The Android sdk has a status it returns in the SaveNetworkResp to let you know that the password was incorrect (0 appears to be a good status which is a little odd).

Looking for something similar to this but it would be much better if the response could just be a code or an object instead of a string that you have to parse the status off of: https://github.com/aws/amazon-freertos-ble-android-sdk/blob/master/amazonfreertossdk/src/main/java/software/amazon/freertos/amazonfreertossdk/networkconfig/SaveNetworkResp.java#L42

ignasbol commented 3 years ago

I second, this would be very helpful. Returning status such as 0, 1 ir -1 is very important to make any app work properly.

@johntvogt I've actually made a change to the Android repo you're referencing above to be able to use getStatus() method, instead of parsing the string. However, we have to wait for a new release to be able to use it from Maven or to build the SDK locally.

@dgranahan connect: true means that it will try to connect to the network immediately and false will save it for later.

dgranahan commented 3 years ago

@ignasbol yes that is correct.

On iOS there is an afrDidSaveNetwork notification that you can subscribe to:

https://github.com/aws/amazon-freertos-ble-ios-sdk/blob/master/AmazonFreeRTOS/AmazonFreeRTOSManager.swift#L561-L567

The SaveNetworkResp has a status field that will be 0 or 1 that will indicate if it was able to connect to the network successfully or not:

https://github.com/aws/amazon-freertos-ble-ios-sdk/blob/master/AmazonFreeRTOS/Services/NetworkConfig/SaveNetworkResp.swift#L8

ignasbol commented 3 years ago

@dgranahan that is very useful, thank you.

On another note, would you know what's the best way to see if the device was Paired successfully (after pairing request with Cancel or Pair options appears). I get device.peripheral.state == .connected as soon as it establishes connection, but that happens before the pairing request.

ravibhagavandas commented 3 years ago

@johntvogt PR #22 shows the sample usage of how to get the status of a wifi save network operation in the application. WiFi network save operation happens asynchronously. The response for the operation is posted as a notification which the user can register for using NotificationCenter.

@ignasbol You are correct that peripheral state changes to .connected as soon as device is connected before any pairing happens. To wait for pairing to complete applications can register for afrPeripheralDidDiscoverCharacteristics notification. For a list of all notifications which application can subscribe to, refer the file NSNotification.Name+AmazonFreeRTOS.swift

ravibhagavandas commented 3 years ago

Closing this issue as the fix has been merged. Please open a new issue if you have further questions.