new DirectlyConnectedDevice(taStoreFileopt, taStorePasswordopt, gatewayopt)
A directly-connected device is able to send messages to, and receive messages from, the IoT
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.
The directly-connected device is able to activate itself using the direct activation capability. The data required for activation and authentication is retrieved from a TrustedAssetsStore generated using the TrustedAssetsProvisioner tool using the Default TrustedAssetsManager.
This object represents the low-level API for the directly-connected device and uses direct methods for sending or receiving messages.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
taStoreFile |
string |
<optional> |
The trusted assets store file path to be used for trusted assets manager creation. This is optional. If none is given the default global library parameter is used: iotcs.oracle.iot.tam.store. |
taStorePassword |
string |
<optional> |
The trusted assets store file password to be used for trusted assets manager creation. This is optional. If none is given the default global library parameter is used: iotcs.oracle.iot.tam.storePassword. |
gateway |
boolean |
<optional> |
true to indicate creation of a GatewayDevice
representation. |
Methods
(static) close()
This method will close this directly connected device (client) and all it's resources. All
monitors required by the message dispatcher associated with this client will be stopped, if
there is one.
(static) createStorageObject(arg1, arg2) → (nullable) {iotcs.StorageObject}
Create a new
iotcs.enterprise.StorageObject
.
The createStorageObject method works in two modes:
1. client.createStorageObject(name, type) - Creates a newiotcs.StorageObject
with the given object name and mime–type. Parameters: {string} name - The unique name to be used to reference the content in storage. {?string} [type] - The mime-type of the content. Iftype
isnull
orundefined
, the mime–type defaults toiotcs.StorageObject.MIME_TYPE
. Returns: {iotcs.StorageObject} A StorageObject. 2. client.createStorageObject(uri, callback) - Creates a newiotcs.StorageObject
from the URL for a named object in storage and returns it in a callback. Creates a newiotcs.ExternalObject
if using an external URI.Parameters: {string} url - The URL of the object in the storage cloud. {function(storage, error)} callback - The callback called once getting storage data completes.
Parameters:
Name | Type | Description |
---|---|---|
arg1 |
string | The first argument. |
arg2 |
string | function | The second argument. |
- See:
Returns:
a
iotcs.StorageObject
, or null
.
- Type
- iotcs.StorageObject
(static) getDeviceModel(deviceModelUrn, callback)
Get the device model for the specified device model URN.
Parameters:
Name | Type | Description |
---|---|---|
deviceModelUrn |
string | The URN of the device model. |
callback |
function | The callback function. This function is called with the
following argument: a deviceModel object holding full description e.g. { name:"",
description:"", fields:[...], created:date, isProtected:boolean, lastModified:date
... } . If an error occurs the deviceModel object is null and an
error object is passed: callback(deviceModel, error) and the reason can be taken from
the error.message. |
(static) getEndpointId() → {string}
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.
Returns:
The logical-endpoint identifier of this directly-connected device.
- Type
- string
(static) isActivated() → {boolean}
This will return the directly connected device state.
Returns:
true
if the device is activated.
- Type
- boolean
(static) offer(messages)
Offer messages to be sent to the server. Whether or not the messages are sent depends on policies that have been
configured for the attributes in the message. If there are no policies for the attributes in the message, then
this call is equivalent to calling send(Message...). Depending on the policies, it is possible that all, some, or
none of the messages will be sent.
Parameters:
Name | Type | Description |
---|---|---|
messages |
Array.<iotcs.message.Message> | The message to be offered. |
Throws:
-
Error - If all the messages cannot be added to the queue.
-
Error - If
messages
isnull
or empty.
(static) receive(timeoutopt, callback)
This method is used for retrieving messages. The DirectlyConnectedDevice uses an internal buffer
for the messages received that has a size of 4192 bytes. When this method is called and there is
at least one message in the buffer, the first message from the buffer is retrieved. If no
message is in the buffer, a force send of an empty message is tried so to see if any messages are
pending on the server side for the device and if there are, the buffer will be filled with them
and the first message retrieved.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
timeout |
number |
<optional> |
The forcing for retrieving the pending messages will be done this amount of time. |
callback |
function | The callback function. This function is called with the first message received or null is no message is received in the timeout period. |
(static) send(messages, callback)
This method is used for sending messages to the server. If the directly connected device is
not activated an exception will be thrown. If the device is not yet authenticated the method
will try first to authenticate the device and then send the messages.
Parameters:
Name | Type | Description |
---|---|---|
messages |
Array.<iotcs.message.Message> | An array of the messages to be sent. |
callback |
function | The callback function. This function is called with the messages that have been sent and in case of error the actual error from sending as the second parameter. |