Skip to content

Commit

Permalink
Merge branch 'bugfix/softap_prov_issue' into 'master'
Browse files Browse the repository at this point in the history
Bugfix: Added permission for local network usage.

See merge request idf/esp-idf-provisioning-ios!18
  • Loading branch information
shahpiyushv committed Feb 26, 2021
2 parents 5258d54 + 85eb362 commit 8045ded
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ESPProvision.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "ESPProvision"
spec.version = "2.0.8"
spec.version = "2.0.9"
spec.summary = "ESP-IDF provisioning in Swift"
spec.description = "It provides mechanism to provide network credentials and/or custom data to an ESP32, ESP32-S2 or ESP8266 devices"
spec.homepage = "https://github.com/espressif/esp-idf-provisioning-ios"
Expand Down
6 changes: 3 additions & 3 deletions ESPProvision/Crypto/ESPSecurity0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
enum Security0SessionState: Int {
/// Initial state of a session.
case State0
/// State of session after first response is recieved.
/// State of session after first response is received.
case State1
}

Expand Down Expand Up @@ -73,7 +73,7 @@ class ESPSecurity0: ESPCodeable {
/// Send unsecured data.
///
/// - Parameter data: Data from device.
/// - Returns: Data as recieved in the argument.
/// - Returns: Data as received in the argument.
func decrypt(data: Data) -> Data? {

ESPLog.log("Decrypted data security 0.")
Expand Down Expand Up @@ -102,7 +102,7 @@ class ESPSecurity0: ESPCodeable {
return request
}

/// Processes data recieved as reponse of Step 0 request.
/// Processes data received as reponse of Step 0 request.
///
/// - Parameter response: Step 0 response.
/// - Throws: Security errors.
Expand Down
12 changes: 6 additions & 6 deletions ESPProvision/Crypto/ESPSecurity1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import SwiftProtobuf
enum Security1SessionState: Int {
/// Initial resuest of a session.
case Request1
/// Recieved response for first state.
/// Received response for first state.
case Response1Request2
/// Response recieved for second state.
/// Response Receive for second state.
case Response2
/// Handshake finished.
case Finished
Expand Down Expand Up @@ -89,7 +89,7 @@ class ESPSecurity1: ESPCodeable {
return request
}

/// Encrypt data recieved in argument.
/// Encrypt data received in argument.
///
/// - Parameter data: Data to be sent.
/// - Returns: Encrypted data.
Expand All @@ -101,7 +101,7 @@ class ESPSecurity1: ESPCodeable {
return cryptoAES.encrypt(data: data)
}

/// Decrypt data recieved in argument.
/// Decrypt data received in argument.
///
/// - Parameter data: Data to be sent.
/// - Returns: Decrypted data.
Expand Down Expand Up @@ -176,7 +176,7 @@ class ESPSecurity1: ESPCodeable {
}
}

/// Processes data recieved as reponse of Step 0 request.
/// Processes data received as reponse of Step 0 request.
///
/// - Parameter response: Step 0 response.
/// - Throws: Security errors.
Expand Down Expand Up @@ -216,7 +216,7 @@ class ESPSecurity1: ESPCodeable {
}
}

/// Processes data recieved as reponse of Step 1 request.
/// Processes data received as reponse of Step 1 request.
///
/// - Parameter response: Step 1 response.
/// - Throws: Security errors.
Expand Down
6 changes: 3 additions & 3 deletions ESPProvision/ESPDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public class ESPDevice {
/// - path: Enpoint of device.
/// - data: Data to be sent to device.
/// - completionHandler: The completion handler that is called when data transmission is successful.
/// Parameter of block include response recieved from the HTTP request or error if any.
/// Parameter of block include response received from the HTTP request or error if any.
public func sendData(path:String, data:Data, completionHandler: @escaping (Data?, ESPSessionError?) -> Swift.Void) {
if session == nil, !session.isEstablished {
completionHandler(nil,.sessionNotEstablished)
Expand Down Expand Up @@ -282,7 +282,7 @@ public class ESPDevice {
provision = ESPProvision(session: session)
ESPLog.log("Configure wi-fi credentials in device.")
provision.configureWifi(ssid: ssid, passphrase: passPhrase) { status, error in
ESPLog.log("Recieved configuration response.")
ESPLog.log("Received configuration response.")
switch status {
case .success:
self.provision.applyConfigurations(completionHandler: { _, error in
Expand Down Expand Up @@ -457,7 +457,7 @@ public class ESPDevice {
/// Process response for version information request.
///
/// - Parameters:
/// - response: Response recieved from version info request..
/// - response: Response received from version info request..
/// - error: Error encountered if any.
/// - completionHandler: Invoked when error is encountered while processing version information.
private func processVersionInfoResponse(response: Data?, error: Error?, completionHandler: @escaping (ESPSessionStatus) -> Void) {
Expand Down
6 changes: 3 additions & 3 deletions ESPProvision/ESPProvision.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ESPProvision {
completionHandler(Espressif_Status.internalError, error)
return
}
ESPLog.log("Recieved response.")
ESPLog.log("Received response.")
let status = self.processSetWifiConfigResponse(response: response)
completionHandler(status, nil)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class ESPProvision {
completionHandler(Espressif_Status.internalError, error)
return
}
ESPLog.log("Recieved response.")
ESPLog.log("Received response.")
let status = self.processApplyConfigResponse(response: response)
completionHandler(status, nil)
self.pollForWifiConnectionStatus { wifiStatus, failReason, error in
Expand Down Expand Up @@ -132,7 +132,7 @@ class ESPProvision {
return
}

ESPLog.log("Response recieved.")
ESPLog.log("Response received.")
do {
let (stationState, failReason) = try
self.processGetWifiConfigStatusResponse(response: response)
Expand Down
2 changes: 1 addition & 1 deletion ESPProvision/ESPProvisionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public class ESPProvisionManager: NSObject, AVCaptureMetadataOutputObjectsDelega
guard let stringValue = readableObject.stringValue else { return }
captureSession.stopRunning()
parseQrCode(code: stringValue)
ESPLog.log("Recieved QR code response.")
ESPLog.log("Received QR code response.")
}
}

Expand Down
2 changes: 1 addition & 1 deletion ESPProvision/ESPSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ESPSession {
return
}

ESPLog.log("Recieved response.")
ESPLog.log("Received response.")
if let responseData = responseData {
self.initialize(response: responseData,
completionHandler: completionHandler)
Expand Down
2 changes: 1 addition & 1 deletion ESPProvision/Transport/ESPCommunicable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protocol ESPCommunicable {
/// - Parameters:
/// - path: Endpoint of base url.
/// - data: Config data to be sent.
/// - completionHandler: Handler called when data is successfully sent and response is recieved.
/// - completionHandler: Handler called when data is successfully sent and response is received.
func SendConfigData(path: String, data: Data, completionHandler: @escaping (Data?, Error?) -> Swift.Void)

/// Check device configuration status.
Expand Down
8 changes: 4 additions & 4 deletions ESPProvision/Utility/ESPErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ public enum ESPProvisionError: ESPError {
case .wifiStatusError(let error):
return "Unable to fetch wifi status with error: \(error.localizedDescription)"
case .wifiStatusDisconnected:
return "Wi-Fi status disconnected"
return "Wi-Fi status: disconnected"
case .wifiStatusAuthenticationError:
return "Wi-Fi status authentication error"
return "Wi-Fi status: authentication error"
case .wifiStatusNetworkNotFound:
return "Wi-Fi status netowrk not found"
return "Wi-Fi status: network not found"
case .wifiStatusUnknownError:
return "Wi-Fi status unknown error"
return "Wi-Fi status: unknown error"
case .unknownError:
return "Unknown error"
}
Expand Down
2 changes: 2 additions & 0 deletions Example/ESPProvisionSample/ESPProvisionSample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<string>Connect with BLE Compatible devices for Provisioning</string>
<key>NSCameraUsageDescription</key>
<string>Reading QR code</string>
<key>NSLocalNetworkUsageDescription</key>
<string>App requires access to local network in order to connect to SoftAP devices.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App requires your location permission in order to get current WiFi network ssid</string>
<key>UIApplicationSceneManifest</key>
Expand Down
12 changes: 4 additions & 8 deletions Example/ESPProvisionSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ There are multiple app variants that you can build using this repository. You ca
|`ESP Allow QR Code Scan`|`true`, `false`|`true`|Set false when QR code is not available or supported for device|
|`ESP Allow Prefix Search`|`true`, `false`|`true`|Set false when search by prefix is not required for BLE devices|

## Permissions

- Since iOS 13, apps that want to access SSID (Wi-Fi network name) are required to have the location permission. Allow location access in app in order to verify that iOS device is currently connected with the SoftAP.








- Since iOS 14, apps that communicate over local network are required to have the local network permission. Allow access to this permission in app in order to send/receive provisioning data with SoftAP devices.


# Resources
Expand All @@ -88,4 +84,4 @@ There are multiple app variants that you can build using this repository. You ca



* If you're interested in contributing to ESP-IDF, please check the [Contributions Guide](https://docs.espressif.com/projects/esp-idf/en/latest/contribute/index.html).
* If you're interested in contributing to this project, please check the [Contributions Guide](https://docs.espressif.com/projects/esp-idf/en/latest/contribute/index.html).
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ espDevice.provision(ssid: ssid, passPhrase: passphrase) { status in

```

## Permissions

- Since iOS 13, apps that want to access SSID (Wi-Fi network name) are required to have the location permission. Add key `NSLocationWhenInUseUsageDescription` in Info.plist with proper description. This permission is required to verify iOS device is currently connected with the SoftAP.

- Since iOS 14, apps that communicate over local network are required to have the local network permission. Add key `NSLocalNetworkUsageDescription` in Info.plist with proper description. This permission is required to send/receive provisioning data with the SoftAP devices.



## License

ESPProvision is released under the Apache License Version 2.0.

0 comments on commit 8045ded

Please sign in to comment.