Skip to content

Commit

Permalink
ESPProvisionSample App : Demonstrates integration and various aspects…
Browse files Browse the repository at this point in the history
… 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
vikas-chandra-mnnit committed Jun 30, 2020
1 parent 3eea07c commit 5266b9f
Show file tree
Hide file tree
Showing 130 changed files with 4,893 additions and 0 deletions.
1,167 changes: 1,167 additions & 0 deletions Example/ESPProvisionSample/ESPProvisionSample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions Example/ESPProvisionSample/ESPProvisionSample/AppDelegate.swift
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.
}


}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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!
}
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
}
}
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>
Loading

0 comments on commit 5266b9f

Please sign in to comment.