DirectlyConnectedDevice
public class DirectlyConnectedDevice : Client
A directly-connected device is able to send messages to, and receive messages from, the IoT server. A directly-connected device has a physical-device identifier that is registered with the server. When the directly-connected device is activated on the server, the server assigns a logical-endpoint identifier. This logical-endpoint identifier is required for sending messages to, and receiving messages from, the server.
-
Constructs a new
DirectlyConnectedDeviceinstance that will load the device configuration from the given path and password.Throws
ClientError.fileif the provisioning file is not presentClientError.securityif the provisioning file can’t be decrypted or there are invalid information in the file
Declaration
Swift
public convenience init(path: String, password: String) throwsParameters
paththe path to the provisioning file
passwordthe password to protect the provisioning file during the creation of the file
-
Activate the device. The device will be activated on the server if necessary. When the device is activated on the server, the server assigns an endpoint identifier to the device.
If the device is already activated, this method will throw an
ClientError.state. The user should call theisActivated()method prior to calling activate.The
callbackclosure can run any code that is required after device activation, such as device registration (indirect enrollment).Throws
ClientError.stateif the device is already activated or ifclosehas been called.Seealso
isActivatedDeclaration
Swift
public func activate(deviceModels:[String]? = nil, callback: @escaping (String?, ClientError?) -> ()) throwsParameters
deviceModelsshould contain the device model type URNs of this directly connected device. The device is activated with the given device models. The
deviceModelsparameter is zero or more, comma separated, device model URNs.callbackThe function to be executed after completion of activation. If activation is not successful then the object will be
niland an error object is passed in the formcallback(endpoint, error)and the reason can be taken from error -
Returns whether the device has been activated against IOT CS server.
Declaration
Swift
public func isActivated() -> BoolReturn Value
whether the device has been activated against IOT CS server.
-
Return the logical-endpoint identifier of this directly-connected device. The logical-endpoint identifier is assigned by the server as part of the activation process.
If
closehas been called, the return value is undefined.Seealso
activate(callback:deviceModels:)Declaration
Swift
public func getEndpointId() -> StringReturn Value
the logical-endpoint identifier of this directly-connected device.
-
Create an
AbstractVirtualDeviceinstance with the given device model for the given device identifier. This method creates a newVirtualDeviceinstance for the given parameters. The client library does not cache previously created VirtualDevice objects.Throws
ClientError.networkif aVirtualDevicecannot be created.ClientError.stateifclosehas been called.
Declaration
Swift
public func createVirtualDevice(deviceId: String, deviceModel: DeviceModel) throws -> VirtualDeviceParameters
deviceIdThe device identifier of the device being modeled
deviceModelThe device model URN that this device implements
Return Value
a new
VirtualDevice -
Get the
DeviceModelfor the device model urn. This method may returnnilif there is no device model for the URN.nilmay also be returned if the device model is a “draft” and the propertyConfig.ALLOW_DRAFT_DEVICE_MODELSis set tofalse, which is the default.Throws
throws:
ClientError.stateifclosehas been called
On error
callbackreceives aClientError.networkerror if: the object is not found (StatusCode.NOT_FOUND), the request fails (!StatusCode.OK), or if the returned data isnilor JSON parsing failsDeclaration
Swift
public func getDeviceModel(deviceModelUrn: String, callback: @escaping (DeviceModel?, ClientError?) -> Void) throwsParameters
deviceModelUrnThe URN of the device model
callbackThis function is called with the retrieved device model.If retrieving the device model is not successful then the object will be
niland an error object is passed in the formcallback(device, error)and the reason can be taken from error -
Release the resources held by the client This call is idempotent
Throws
ClientError.networkif aMessageDispatchercannot be obtained.Declaration
Swift
public func close() throws -
Create a new
StorageObjectthat will have a name with the given object name prefixed with the device’s endpoint ID and a directory separator. The prefix addition can be disabled by setting theConfig.DISABLE_STORAGE_OBJECT_PREFIXtotrue.If
contentTypeis nil, the mime-type defaults to “application/octet-stream”.return a
StorageObject
Throws
throws:
- `ClientError.network if there is an exception raised by the runtime, or an abnormal response from the storage cloud
ClientError.securityif there is an exception establishing a secure connection to the storage cloudClientError.stateifclosehas been called
Declaration
Swift
public func createStorageObject(name:String, contentType:String? = StorageObject.OCTET_STREAM) throws -> StorageObjectParameters
namethe unique name to be used to reference the content in storage
contentTypeThe mime-type of the content or
nil -
Undocumented
Declaration
Swift
public func offer(message: Message) throws
DirectlyConnectedDevice Class Reference