GatewayDevice
public class GatewayDevice : DirectlyConnectedDevice
A GatewayDevice is capable of registering indirectly–connected devices and proxies messages for indirectly-connected devices.
-
The
manufacturer
attribute. This attribute is to be used when setting themanufacturer
value in the meta-data.Declaration
Swift
public static let MANUFACTURER: String
-
The
modelNumber
attribute. This attribute is to be used when setting themodelNumber
value in the meta-data.Declaration
Swift
public static let MODEL_NUMBER: String
-
The
serialNumber
attribute. This attribute is to be used when setting theserialNumber
value in the meta-data.Declaration
Swift
public static let SERIAL_NUMBER: String
-
The
deviceClass
attribute. This attribute is to be used when setting thedeviceClass
value in the meta-data.Declaration
Swift
public static let DEVICE_CLASS: String
-
The
protocol
attribute. This attribute is to be used when setting theprotocol
value in the meta-data.Declaration
Swift
public static let PROTOCOL: String
-
The
protocolDeviceClass
attribute. This attribute is to be used when setting theprotocolDeviceClass
value in the meta-data.Declaration
Swift
public static let PROTOCOL_DEVICE_CLASS: String
-
The
protocolDeviceId
attribute. This attribute is to be used when setting theprotocolDeviceId
value in the meta-data.Declaration
Swift
public static let PROTOCOL_DEVICE_ID: String
-
Constructs a new
GatewayDevice
instance that will use the given path and password to provision aGatewayDevice
instanceThrows
ClientError.file
if the provisioning file is not presentClientError.security
if the provisioning file cannot be decrypted or there is invalid information in the file
Declaration
Swift
public init(path: String, password: String) throws
Parameters
path
the path to the provisioning file
password
the password to protect the provisioning file during the creation of the file
-
Register an indirectly-connected device with the cloud service and specifiy whether the gateway device is required to have the appropriate credentials for activating the indirectly-connected device.
The
restricted
parameter controls whether or not the client library is required to supply credentials for activating the indirectly-connected device. The client library will always supply credentials for an indirectly-connected device whose trusted assets have been provisioned to the client. If, however, the trusted assets of the indirectly-connected device have not been provisioned to the client, the client library can create credentials that attempt to restrict the indirectly connected device to this gateway device.Pass
true
for therestricted
parameter to ensure the indirectly-connected device cannot be activated by this gateway device without presenting credentials. Ifrestricted
istrue
, the client library will provide credentials to the server. The server will reject the activation request if the indirectly connected device is not allowed to roam to this gateway device.Pass
false
to allow the indirectly-connected device to be activated without presenting credentials if the trusted assets of the indirectly-connected device have not been provisioned to the client. Ifrestricted
isfalse
, the client library will provide credentials if, and only if, the credentials have been provisioned to the client. The server will reject the activation if credentials are required but not supplied, or if the provisioned credentials do not allow the indirectly connected device to roam to this gateway device.The
hardwareId
is a unique identifier within the cloud service instance and may not benil
. If one is not present for the device, it should be generated based on other metadata such as: model, manufacturer, serial number, etc.The
metaData
Map should typically contain all the standard metadata (the constants documented in this class) along with any other vendor defined metadata.Throws
throws:
ClientError.state
if device is already activated or the shared secret has not been set for the deviceClientError.network
if there was a problem with the network call
Declaration
Swift
public func registerDevice(restricted: Bool = false, hardwareId: String, metaData: [String:String], deviceModels: String..., callback: @escaping (String?, ClientError?) -> ()) throws
Parameters
restricted
indicate whether or not credentials are required for activating the indirectly connected device This is an optional parameter, the default is
false
.hardwareId
an identifier unique within the cloud service instance
metaData
The meta-data of the device
deviceModels
should contain the device model type URNs supported by the indirectly connected device
callback
closure to be called after registration with the endpoint id of the indirectly-connected device If registration is not successful then the object will be
nil
and an error object is passed in the formcallback(endpointId, error)
and the reason can be taken from error