airvantage.asset
Interface to ReadyAgent asset management.
airvantage.asset
airvantage.asset.newasset(id) | Creates and returns a new #asset instance. |
asset
asset:close() | Closes the racon.asset. |
asset.newTable(path, columns, storage, sendPolicy) | Creates and returns a airvantage.table#table instance. |
asset:pushData(path, data, sendpolicy) | Pushes some unstructured data to the agent. |
asset:setUpdateHook(hook) | Changes the hook function to be called when the asset receives a software update request from the portal. |
asset:start() | Registers a newly created racon.asset with the ReadyAgent. |
asset.tree | airvantage.asset data tree. |
airvantage.asset
airvantage.asset.newasset(id)
id
:
string defining the assetid identifying the instance of this new asset.
asset
@type asset
asset:close()
"ok" on success.
asset.newTable(path, columns, storage, sendPolicy)
path
:
(relative to the asset root) where the data will be sent.
columns
:
list of either racon.table.columnspec or column names (to
use default values).
storage
:
either "file" or "ram", how the table must be persisted.
sendPolicy
:
name of the policy controlling when the table content is
sent to the server.
asset:pushData(path, data, sendpolicy)
path
:
the datastore path under which data will be stored relative to the asset node.
data
:
a table of key/value pairs or a simple value (not a table)
sendpolicy
:
name of the policy controlling when the data is sent to the server.
asset:setUpdateHook(hook)
Notes:
- There can be only one SoftwareUpdate request at a time.
- Only one hook can be registered for the whole asset
- It is not possible to signify asynchronous reporting of update status, for now the only way to send update result is to return the status in the hook.
- If no user update hook is set: then the error code 472 meaning not supported / not implemented will be returned.
- Any error coming from this update request means that the whole update process will be set as failed.
- When an update request asks for installing a version that is already installed then the application should return success value.
In deed, in some cases ReadyAgent won't received the update hook result, e.g. asset reboot, device reboot etc, in those cases,
the update request will be sent again to the asset with same hook parameters,
and the asset hook is expected to answer with success code when that request have been executed successfully before.
hook
:
the new function to handle software update request.
hook signature: hook(componentname, version, path, parameters)
- componentname (a string) is the identifier of the component to update,
the name is defined in update manifest file, here it is provided
without the assetid at the beginning.
- version (a string) is the version of the component to install
version can be empty string (but not nil!) to specify de-installation
request, non empty string for regular update/install of software
component.
- path (a string) can be empty when version is empty too, otherwise path
will be a non empty string defining the absolute path of the file/folder
to use to update the application.
- parameters (a table), can be nil, when set it contains the content
of parameters, those params provide a way to give application specific
update paramaters.
- return value: an integer, 200 for success, any other value means error.
Values from 480 to 499 are reserved for applicative error codes,
so it is highly recommanded to use one (or more) of those to signify
an error coming from this update hook.
Non-integer return values will be rejected and be replaced by
default value 471.
asset:start()
asset.tree
tree
.
When the server sends data to an asset, the way it reacts is determined by the tree:
__default
field in a prefix of the data's path, this generic handler is used. If
several generic handlers are found, the one corresponding to the longest
prefix is chosen. For instance, if the server sends myAsset.foo.bar=123
:
myAsset.tree.foo.bar,myAsset.tree.foo
or
myAsset.tree
, this function is called;myAsset.tree.foo.__default
or myAsset.tree.__default
, the one
with the longest path is called;123
is written in myAsset.tree.foo.bar
.Handlers are function which receive as parameters:
They must return:
* the status code 0
to indicate success;
* a non-zero numeric status code to indicate failure, optionally followed
by an error message.
The data tree comes with a pre-wired functions on the special path
id.commands
(i.e ReadNode
on id.commands.ReadNode
).
Handler functions should be installed on the data tree before the asset is started: otherwise, some server messages might be lost.