ESPDevice
open class ESPDevice
extension ESPDevice: ESPScanWifiListProtocol
extension ESPDevice: ESPBLEStatusDelegate
The ESPDevice
class is the main inteface for managing a device. It encapsulates method and properties
required to provision, connect and communicate with the device.
-
Session instance of device.
Declaration
Swift
var session: ESPSession!
-
Name of device.
Declaration
Swift
var deviceName: String
-
BLE transport layer.
Declaration
Swift
var espBleTransport: ESPBleTransport!
-
SoftAp transport layer.
Declaration
Swift
public var espSoftApTransport: ESPSoftAPTransport!
-
Peripheral object in case of BLE device.
Declaration
Swift
var peripheral: CBPeripheral!
-
Connection status of device.
Declaration
Swift
var connectionStatus: ESPSessionStatus
-
Completion handler for scan Wi-Fi list.
Declaration
Swift
var wifiListCompletionHandler: (([ESPWifiNetwork]?, ESPWiFiScanError?) -> Void)?
-
Completion handler for BLE connection status.
Declaration
Swift
var bleConnectionStatusHandler: ((ESPSessionStatus) -> Void)?
-
Proof of possession
Declaration
Swift
var proofOfPossession: String?
-
List of capabilities of a device.
Declaration
Swift
public var capabilities: [String]?
-
Security implementation.
Declaration
Swift
public var security: ESPSecurity
-
Mode of transport.
Declaration
Swift
public var transport: ESPTransport
-
Delegate of
ESPDevice
object.Declaration
Swift
public var delegate: ESPDeviceConnectionDelegate?
-
Security layer of device.
Declaration
Swift
public var securityLayer: ESPCodeable!
-
Storing device version information
Declaration
Swift
public var versionInfo: NSDictionary?
-
Store BLE delegate information
Declaration
Swift
public var bleDelegate: ESPBLEDelegate?
-
Store username for sec1
Declaration
Swift
public var username: String?
-
Advertisement data for BLE device This property is read-only
Declaration
Swift
public private(set) var advertisementData: [String : Any]? { get }
-
Get name of current
ESPDevice
.Declaration
Swift
public var name: String { get }
-
Create
ESPDevice
object.Declaration
Swift
public init(name: String, security: ESPSecurity, transport: ESPTransport, proofOfPossession: String? = nil, username: String? = nil, softAPPassword: String? = nil, advertisementData: [String : Any]? = nil)
Parameters
name
Name of device.
security
Mode of secure data transmission.
transport
Mode of transport.
proofOfPossession
Pop of device.
softAPPassword
Password in case SoftAP device.
-
Establish session with device to allow data transmission.
Declaration
Swift
open func connect(delegate: ESPDeviceConnectionDelegate? = nil, completionHandler: @escaping (ESPSessionStatus) -> Void)
Parameters
delegate
Class conforming to
ESPDeviceConnectionDelegate
protocol.completionHandler
The completion handler returns status of connection with the device.
-
Send data to custom endpoints of a device.
Declaration
Swift
open func sendData(path: String, data: Data, completionHandler: @escaping (Data?, ESPSessionError?) -> Swift.Void)
Parameters
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 received from the HTTP request or error if any.
-
Checks if connection is established with the device.
Declaration
Swift
public func isSessionEstablished() -> Bool
Return Value
true
if session is established,false
otherwise. -
Provision device with available wireless network.
Declaration
Swift
public func provision(ssid: String, passPhrase: String = "", completionHandler: @escaping (ESPProvisionStatus) -> Void)
Parameters
ssid
SSID of home network.
passPhrase
Password of home network.
completionHandler
The completion handler that is called when provision is completed. Parameter of block include status of provision.
-
Returns the wireless network IP 4 address after successful provision.
Declaration
Swift
public func wifiConnectedIp4Addr() -> String?
-
Disconnect
ESPDevice
.Declaration
Swift
public func disconnect()
-
Send command to device for scanning Wi-Fi list.
Declaration
Swift
public func scanWifiList(completionHandler: @escaping ([ESPWifiNetwork]?, ESPWiFiScanError?) -> Void)
Parameters
completionHandler
The completion handler that is called when Wi-Fi list is scanned. Parameter of block include list of available Wi-Fi network or error in case of failure.
-
Initialise session with
ESPDevice
.Declaration
Swift
open func initialiseSession(sessionPath: String?, completionHandler: @escaping (ESPSessionStatus) -> Void)
Parameters
sessionPath
Path for sending session related data.
completionHandler
The completion handler that is called when session is initalised. Parameter of block include status of session.
-
Undocumented
Declaration
Swift
func initSecureSession(sessionPath: String?, pop: String, completionHandler: @escaping (ESPSessionStatus) -> Void)
-
Undocumented
Declaration
Swift
func getUsernameForSecure2(sessionPath: String?, password: String, completionHandler: @escaping (ESPSessionStatus) -> Void)
-
Undocumented
Declaration
Swift
func initSecure2Session(sessionPath: String?, username: String, password: String, completionHandler: @escaping (ESPSessionStatus) -> Void)
-
Undocumented
Declaration
Swift
func initSession(sessionPath: String?, completionHandler: @escaping (ESPSessionStatus) -> Void)
-
Undocumented
Declaration
Swift
func wifiScanFinished(wifiList: [ESPWifiNetwork]?, error: ESPWiFiScanError?)
-
Declaration
Swift
func peripheralConnected()
-
Declaration
Swift
func peripheralDisconnected(peripheral: CBPeripheral, error: Error?)
-
Declaration
Swift
func peripheralFailedToConnect(peripheral: CBPeripheral?, error: Error?)