-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESPProvisionSample App : Demonstrates integration and various aspects…
… of the ESPProvision library. - Includes BLE device search - Connect to device automatically using QR code. - Supports both BLE and SoftAP device types. - Shows list of available Wi-Fi networks. - Wi-Fi provisioning. - Provisioning step indicators. - Include feature to change provisioning settings.
- Loading branch information
1 parent
3eea07c
commit 5266b9f
Showing
130 changed files
with
4,893 additions
and
0 deletions.
There are no files selected for viewing
1,167 changes: 1,167 additions & 0 deletions
1,167
Example/ESPProvisionSample/ESPProvisionSample.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...ProvisionSample/ESPProvisionSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
Example/ESPProvisionSample/ESPProvisionSample.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
Example/ESPProvisionSample/ESPProvisionSample/AppDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2020 Espressif Systems | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// AppDelegate.swift | ||
// ESPProvisionSample | ||
// | ||
|
||
|
||
import UIKit | ||
import ESPProvision | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
|
||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
// Override point for customization after application launch. | ||
// ESPProvisionManager.shared.enableLogs(true) | ||
return true | ||
} | ||
|
||
// MARK: UISceneSession Lifecycle | ||
|
||
@available(iOS 13.0, *) | ||
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { | ||
// Called when a new scene session is being created. | ||
// Use this method to select a configuration to create the new scene with. | ||
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { | ||
// Called when the user discards a scene session. | ||
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. | ||
// Use this method to release any resources that were specific to the discarded scenes, as they will not return. | ||
} | ||
|
||
|
||
} | ||
|
Binary file added
BIN
+917 Bytes
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (13).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.42 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (14).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.17 KB
...ionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (15)-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.17 KB
...ionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (15)-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.17 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (15).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.33 KB
...ionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (16)-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.33 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (16).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.5 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (17).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.19 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (18).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.18 KB
...ionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (19)-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.18 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (19).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.75 KB
...ionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (20)-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.75 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (20).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.43 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (21).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.04 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (22).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.94 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (23).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+70 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (24).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.8 KB
...isionSample/Assets.xcassets/AppIcon-BLE.appiconset/ezgif.com-gif-maker (25).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+745 Bytes
...sets.xcassets/AppIcon-SoftAP.appiconset/resize-1565086397947011712wifilogo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.27 KB
...ets.xcassets/AppIcon-SoftAP.appiconset/resize-15650864461453706150wifilogo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.93 KB
...ts.xcassets/AppIcon-SoftAP.appiconset/resize-1565086479789435725wifilogo1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.93 KB
...ts.xcassets/AppIcon-SoftAP.appiconset/resize-1565086479789435725wifilogo1-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.93 KB
...sets.xcassets/AppIcon-SoftAP.appiconset/resize-1565086479789435725wifilogo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.2 KB
...s.xcassets/AppIcon-SoftAP.appiconset/resize-15650865341171751788wifilogo1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.2 KB
...ets.xcassets/AppIcon-SoftAP.appiconset/resize-15650865341171751788wifilogo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.35 KB
...ets.xcassets/AppIcon-SoftAP.appiconset/resize-15650865501830362572wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+4.57 KB
...sets.xcassets/AppIcon-SoftAP.appiconset/resize-1565086574370460560wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+4.83 KB
...ts.xcassets/AppIcon-SoftAP.appiconset/resize-1565086586828858701wifilogo1-1.png
Oops, something went wrong.
Binary file added
BIN
+4.83 KB
...sets.xcassets/AppIcon-SoftAP.appiconset/resize-1565086586828858701wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+5.54 KB
...ets.xcassets/AppIcon-SoftAP.appiconset/resize-15650865991169979741wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+8.73 KB
...ts.xcassets/AppIcon-SoftAP.appiconset/resize-1565086616351381406wifilogo1-1.png
Oops, something went wrong.
Binary file added
BIN
+8.73 KB
...sets.xcassets/AppIcon-SoftAP.appiconset/resize-1565086616351381406wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+14 KB
...sets.xcassets/AppIcon-SoftAP.appiconset/resize-1565086637859598357wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+16 KB
...sets.xcassets/AppIcon-SoftAP.appiconset/resize-1565086662254994045wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+101 KB
...ets.xcassets/AppIcon-SoftAP.appiconset/resize-15650866731140359175wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+12 KB
...ets.xcassets/AppIcon-SoftAP.appiconset/resize-15650868851379559421wifilogo1.png
Oops, something went wrong.
Binary file added
BIN
+4.3 KB
...le/ESPProvisionSample/Assets.xcassets/ble_main_logo.imageset/293687-128 (8).png
Oops, something went wrong.
Binary file added
BIN
+9.07 KB
...le/ESPProvisionSample/Assets.xcassets/ble_main_logo.imageset/293687-256 (6).png
Oops, something went wrong.
Binary file added
BIN
+20.1 KB
...le/ESPProvisionSample/Assets.xcassets/ble_main_logo.imageset/293687-512 (6).png
Oops, something went wrong.
Binary file added
BIN
+3.24 KB
...ample/ESPProvisionSample/Assets.xcassets/bluetooth_icon.imageset/925802-128.png
Oops, something went wrong.
Binary file added
BIN
+6.82 KB
...ample/ESPProvisionSample/Assets.xcassets/bluetooth_icon.imageset/925802-256.png
Oops, something went wrong.
Binary file added
BIN
+14.1 KB
...ample/ESPProvisionSample/Assets.xcassets/bluetooth_icon.imageset/925802-512.png
Oops, something went wrong.
Binary file added
BIN
+707 Bytes
...ample/ESPProvisionSample/Assets.xcassets/checkbox_checked.imageset/checkbox.png
Oops, something went wrong.
Binary file added
BIN
+1.25 KB
...le/ESPProvisionSample/Assets.xcassets/checkbox_checked.imageset/checkbox@2x.png
Oops, something went wrong.
Binary file added
BIN
+1.93 KB
...le/ESPProvisionSample/Assets.xcassets/checkbox_checked.imageset/checkbox@3x.png
Oops, something went wrong.
Binary file added
BIN
+777 Bytes
...onSample/ESPProvisionSample/Assets.xcassets/checkbox_icon.imageset/checkbox.png
Oops, something went wrong.
Binary file added
BIN
+1.66 KB
...ample/ESPProvisionSample/Assets.xcassets/checkbox_icon.imageset/checkbox@2x.png
Oops, something went wrong.
Binary file added
BIN
+2.66 KB
...ample/ESPProvisionSample/Assets.xcassets/checkbox_icon.imageset/checkbox@3x.png
Oops, something went wrong.
Binary file added
BIN
+666 Bytes
...SPProvisionSample/Assets.xcassets/checkbox_unchecked.imageset/checkboxCopy2.png
Oops, something went wrong.
Binary file added
BIN
+1.16 KB
...rovisionSample/Assets.xcassets/checkbox_unchecked.imageset/checkboxCopy2@2x.png
Oops, something went wrong.
Binary file added
BIN
+1.89 KB
...rovisionSample/Assets.xcassets/checkbox_unchecked.imageset/checkboxCopy2@3x.png
Oops, something went wrong.
Binary file added
BIN
+324 Bytes
...rovisionSample/ESPProvisionSample/Assets.xcassets/cross_icon.imageset/cross.png
Oops, something went wrong.
Binary file added
BIN
+554 Bytes
...isionSample/ESPProvisionSample/Assets.xcassets/cross_icon.imageset/cross@2x.png
Oops, something went wrong.
Binary file added
BIN
+827 Bytes
...isionSample/ESPProvisionSample/Assets.xcassets/cross_icon.imageset/cross@3x.png
Oops, something went wrong.
Binary file added
BIN
+689 Bytes
...visionSample/ESPProvisionSample/Assets.xcassets/error_icon.imageset/xCircle.png
Oops, something went wrong.
Binary file added
BIN
+1.27 KB
...ionSample/ESPProvisionSample/Assets.xcassets/error_icon.imageset/xCircle@2x.png
Oops, something went wrong.
Binary file added
BIN
+1.91 KB
...ionSample/ESPProvisionSample/Assets.xcassets/error_icon.imageset/xCircle@3x.png
Oops, something went wrong.
Binary file added
BIN
+761 Bytes
...PProvisionSample/Assets.xcassets/hide_password.imageset/eyePrincipleFlatten.png
Oops, something went wrong.
Binary file added
BIN
+1.59 KB
...ovisionSample/Assets.xcassets/hide_password.imageset/eyePrincipleFlatten@2x.png
Oops, something went wrong.
Binary file added
BIN
+2.5 KB
...ovisionSample/Assets.xcassets/hide_password.imageset/eyePrincipleFlatten@3x.png
Oops, something went wrong.
Binary file added
BIN
+8.69 KB
...s.xcassets/main_logo.imageset/Screenshot_2020-06-24_at_9.58.14_PM_1_128x128.png
Oops, something went wrong.
Binary file added
BIN
+15.1 KB
...s.xcassets/main_logo.imageset/Screenshot_2020-06-24_at_9.58.14_PM_2_256x256.png
Oops, something went wrong.
Binary file added
BIN
+29.8 KB
...s.xcassets/main_logo.imageset/Screenshot_2020-06-24_at_9.58.14_PM_3_512x512.png
Oops, something went wrong.
Binary file added
BIN
+11.8 KB
...isionSample/ESPProvisionSample/Assets.xcassets/provision_icon.imageset/lamp.png
Oops, something went wrong.
Binary file added
BIN
+32.4 KB
...onSample/ESPProvisionSample/Assets.xcassets/provision_icon.imageset/lamp@2x.png
Oops, something went wrong.
Binary file added
BIN
+59.6 KB
...onSample/ESPProvisionSample/Assets.xcassets/provision_icon.imageset/lamp@3x.png
Oops, something went wrong.
Binary file added
BIN
+3.87 KB
...nSample/ESPProvisionSample/Assets.xcassets/refresh_icon.imageset/326679-128.png
Oops, something went wrong.
Binary file added
BIN
+8.17 KB
...nSample/ESPProvisionSample/Assets.xcassets/refresh_icon.imageset/326679-256.png
Oops, something went wrong.
Binary file added
BIN
+17.5 KB
...nSample/ESPProvisionSample/Assets.xcassets/refresh_icon.imageset/326679-512.png
Oops, something went wrong.
Binary file added
BIN
+1.11 KB
...le/ESPProvisionSample/Assets.xcassets/settings_icon.imageset/4200472-24 (1).png
Oops, something went wrong.
Binary file added
BIN
+2.43 KB
...le/ESPProvisionSample/Assets.xcassets/settings_icon.imageset/4200472-48 (1).png
Oops, something went wrong.
Binary file added
BIN
+3.28 KB
...le/ESPProvisionSample/Assets.xcassets/settings_icon.imageset/4200472-64 (1).png
Oops, something went wrong.
Binary file added
BIN
+1.02 KB
...sionSample/ESPProvisionSample/Assets.xcassets/show_password.imageset/eyeOff.png
Oops, something went wrong.
Binary file added
BIN
+2.15 KB
...nSample/ESPProvisionSample/Assets.xcassets/show_password.imageset/eyeOff@2x.png
Oops, something went wrong.
Binary file added
BIN
+3.31 KB
...nSample/ESPProvisionSample/Assets.xcassets/show_password.imageset/eyeOff@3x.png
Oops, something went wrong.
Binary file added
BIN
+4.57 KB
...ESPProvisionSample/Assets.xcassets/softap_main_logo.imageset/293687-128 (2).png
Oops, something went wrong.
Binary file added
BIN
+9.85 KB
...ESPProvisionSample/Assets.xcassets/softap_main_logo.imageset/293687-256 (2).png
Oops, something went wrong.
Binary file added
BIN
+21.4 KB
...ESPProvisionSample/Assets.xcassets/softap_main_logo.imageset/293687-512 (2).png
Oops, something went wrong.
Binary file added
BIN
+12.7 KB
...visionSample/ESPProvisionSample/Assets.xcassets/status_icon.imageset/switch.png
Oops, something went wrong.
Binary file added
BIN
+36.3 KB
...ionSample/ESPProvisionSample/Assets.xcassets/status_icon.imageset/switch@2x.png
Oops, something went wrong.
Binary file added
BIN
+68.9 KB
...ionSample/ESPProvisionSample/Assets.xcassets/status_icon.imageset/switch@3x.png
Oops, something went wrong.
Binary file added
BIN
+549 Bytes
...ionSample/ESPProvisionSample/Assets.xcassets/wifi_symbol_fair.imageset/wifi.png
Oops, something went wrong.
Binary file added
BIN
+1.14 KB
...Sample/ESPProvisionSample/Assets.xcassets/wifi_symbol_fair.imageset/wifi@2x.png
Oops, something went wrong.
Binary file added
BIN
+1.63 KB
...Sample/ESPProvisionSample/Assets.xcassets/wifi_symbol_fair.imageset/wifi@3x.png
Oops, something went wrong.
Binary file added
BIN
+569 Bytes
...ionSample/ESPProvisionSample/Assets.xcassets/wifi_symbol_good.imageset/wifi.png
Oops, something went wrong.
Binary file added
BIN
+1.15 KB
...Sample/ESPProvisionSample/Assets.xcassets/wifi_symbol_good.imageset/wifi@2x.png
Oops, something went wrong.
Binary file added
BIN
+1.64 KB
...Sample/ESPProvisionSample/Assets.xcassets/wifi_symbol_good.imageset/wifi@3x.png
Oops, something went wrong.
Binary file added
BIN
+571 Bytes
...nSample/ESPProvisionSample/Assets.xcassets/wifi_symbol_strong.imageset/wifi.png
Oops, something went wrong.
Binary file added
BIN
+1.13 KB
...mple/ESPProvisionSample/Assets.xcassets/wifi_symbol_strong.imageset/wifi@2x.png
Oops, something went wrong.
Binary file added
BIN
+1.7 KB
...mple/ESPProvisionSample/Assets.xcassets/wifi_symbol_strong.imageset/wifi@3x.png
Oops, something went wrong.
Binary file added
BIN
+537 Bytes
...ionSample/ESPProvisionSample/Assets.xcassets/wifi_symbol_weak.imageset/wifi.png
Oops, something went wrong.
Binary file added
BIN
+1.12 KB
...Sample/ESPProvisionSample/Assets.xcassets/wifi_symbol_weak.imageset/wifi@2x.png
Oops, something went wrong.
Binary file added
BIN
+1.59 KB
...Sample/ESPProvisionSample/Assets.xcassets/wifi_symbol_weak.imageset/wifi@3x.png
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
Example/ESPProvisionSample/ESPProvisionSample/BLE/BLEDeviceListViewCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2020 Espressif Systems | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// BLEDeviceListViewCell.swift | ||
// ESPProvisionSample | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
class BLEDeviceListViewCell: UITableViewCell { | ||
@IBOutlet var deviceName: UILabel! | ||
} |
190 changes: 190 additions & 0 deletions
190
Example/ESPProvisionSample/ESPProvisionSample/BLE/BLELandingViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// Copyright 2020 Espressif Systems | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// BLELandingViewController.swift | ||
// ESPProvisionSample | ||
// | ||
|
||
import CoreBluetooth | ||
import Foundation | ||
import MBProgressHUD | ||
import UIKit | ||
import ESPProvision | ||
|
||
protocol BLEStatusProtocol { | ||
func peripheralDisconnected() | ||
} | ||
|
||
class BLELandingViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | ||
var activityView: UIActivityIndicatorView? | ||
var grayView: UIView? | ||
var delegate: BLEStatusProtocol? | ||
var bleConnectTimer = Timer() | ||
var bleDeviceConnected = false | ||
var bleDevices:[ESPDevice]? | ||
var pop = "" | ||
|
||
@IBOutlet var tableview: UITableView! | ||
@IBOutlet var prefixTextField: UITextField! | ||
@IBOutlet var prefixlabel: UILabel! | ||
@IBOutlet var prefixView: UIView! | ||
@IBOutlet var textTopConstraint: NSLayoutConstraint! | ||
|
||
// MARK: - Overriden Methods | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
navigationItem.title = "Connect" | ||
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil) | ||
|
||
// Scan for bluetooth devices | ||
|
||
// UI customization | ||
prefixlabel.layer.masksToBounds = true | ||
tableview.tableFooterView = UIView() | ||
|
||
// Adding tap gesture to hide keyboard on outside touch | ||
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) | ||
tap.cancelsTouchesInView = false | ||
view.addGestureRecognizer(tap) | ||
|
||
// Checking whether filtering by prefix header is allowed | ||
prefixTextField.text = Utility.shared.deviceNamePrefix | ||
if Utility.shared.espAppSettings.allowPrefixSearch { | ||
prefixView.isHidden = false | ||
} else { | ||
textTopConstraint.constant = -10 | ||
view.layoutIfNeeded() | ||
} | ||
|
||
scanBleDevices() | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillDisappear), name: UIResponder.keyboardWillHideNotification, object: nil) | ||
} | ||
|
||
override func viewWillDisappear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil) | ||
} | ||
|
||
// MARK: - IBActions | ||
|
||
@IBAction func backButtonPressed(_ sender: Any) { | ||
navigationController?.popViewController(animated: true) | ||
} | ||
|
||
@IBAction func cancelPressed(_ sender: Any) { | ||
navigationController?.popToRootViewController(animated: true) | ||
} | ||
|
||
@IBAction func rescanBLEDevices(_: Any) { | ||
bleDevices?.removeAll() | ||
tableview.reloadData() | ||
scanBleDevices() | ||
} | ||
|
||
func scanBleDevices() { | ||
Utility.showLoader(message: "Searching for BLE Devices..", view: self.view) | ||
ESPProvisionManager.shared.searchESPDevices(devicePrefix: Utility.shared.deviceNamePrefix, transport: .ble) { bleDevices, error in | ||
DispatchQueue.main.async { | ||
Utility.hideLoader(view: self.view) | ||
self.bleDevices = bleDevices | ||
self.tableview.reloadData() | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Notifications | ||
|
||
@objc func dismissKeyboard() { | ||
view.endEditing(true) | ||
} | ||
|
||
@objc func keyboardWillDisappear() { | ||
if let prefix = prefixTextField.text { | ||
UserDefaults.standard.set(prefix, forKey: "com.espressif.prefix") | ||
Utility.shared.deviceNamePrefix = prefix | ||
rescanBLEDevices(self) | ||
} | ||
} | ||
|
||
// MARK: - Helper Methods | ||
|
||
func goToClaimVC(device: ESPDevice) { | ||
let claimVC = storyboard?.instantiateViewController(withIdentifier: "claimVC") as! ClaimViewController | ||
claimVC.espDevice = device | ||
navigationController?.pushViewController(claimVC, animated: true) | ||
} | ||
|
||
func goToProvision(device: ESPDevice) { | ||
DispatchQueue.main.async { | ||
Utility.hideLoader(view: self.view) | ||
let provisionVC = self.storyboard?.instantiateViewController(withIdentifier: "provision") as! ProvisionViewController | ||
provisionVC.espDevice = device | ||
self.navigationController?.pushViewController(provisionVC, animated: true) | ||
} | ||
} | ||
|
||
private func showBusy(isBusy: Bool, message: String = "") { | ||
DispatchQueue.main.async { | ||
if isBusy { | ||
let loader = MBProgressHUD.showAdded(to: self.view, animated: true) | ||
loader.mode = MBProgressHUDMode.indeterminate | ||
loader.label.text = message | ||
} else { | ||
MBProgressHUD.hide(for: self.view, animated: true) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - UITableView | ||
|
||
func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int { | ||
guard let peripherals = self.bleDevices else { | ||
return 0 | ||
} | ||
return peripherals.count | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: "bleDeviceCell", for: indexPath) as! BLEDeviceListViewCell | ||
if let peripheral = self.bleDevices?[indexPath.row] { | ||
cell.deviceName.text = peripheral.name | ||
} | ||
|
||
return cell | ||
} | ||
|
||
func tableView(_: UITableView, heightForRowAt _: IndexPath) -> CGFloat { | ||
return 60 | ||
} | ||
|
||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
tableView.deselectRow(at: indexPath, animated: true) | ||
Utility.showLoader(message: "Connecting to device", view: self.view) | ||
self.goToClaimVC(device: self.bleDevices![indexPath.row]) | ||
} | ||
|
||
} | ||
|
||
extension BLELandingViewController: UITextFieldDelegate { | ||
func textFieldShouldReturn(_: UITextField) -> Bool { | ||
view.endEditing(true) | ||
return false | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Example/ESPProvisionSample/ESPProvisionSample/Base.lproj/LaunchScreen.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="EHf-IW-A2E"> | ||
<objects> | ||
<viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> | ||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="53" y="375"/> | ||
</scene> | ||
</scenes> | ||
</document> |
Oops, something went wrong.