Type: | Package |
Title: | 'ThingsBoard' API |
Version: | 0.2.7 |
Date: | 2022-01-18 |
Description: | The goal of 'Rthingsboard' is to provide interaction with the API of 'ThingsBoard' (https://thingsboard.io/), an open-source IoT platform for device management, data collection, processing and visualization. |
License: | AGPL-3 |
Encoding: | UTF-8 |
Imports: | httr, logger, methods, dplyr |
Suggests: | badger, ggplot2, testthat |
RoxygenNote: | 7.1.2 |
URL: | https://ddorch.github.io/Rthingsboard/, https://github.com/DDorch/Rthingsboard#readme |
BugReports: | https://github.com/DDorch/Rthingsboard/issues |
NeedsCompilation: | no |
Packaged: | 2022-01-18 11:19:01 UTC; david.dorchies |
Author: | David Dorchies |
Maintainer: | David Dorchies <david.dorchies@inrae.fr> |
Repository: | CRAN |
Date/Publication: | 2022-01-19 16:42:42 UTC |
Convert a date into an epoch in milliseconds
Description
This function allows to convert epoch timestamp in seconds to an epoch in milliseconds
Usage
Date2EpochMilli(ts)
## S3 method for class 'POSIXt'
Date2EpochMilli(ts)
## S3 method for class 'numeric'
Date2EpochMilli(ts)
Arguments
ts |
Value
a character of the epoch in milliseconds
Examples
Date2EpochMilli(as.numeric(Sys.time()))
Convert an epoch in milliseconds into a date
Description
Convert an epoch in milliseconds into a date
Usage
EpochMilli2Date(x, timezone = "GMT")
Arguments
x |
A character or a numeric representing an epoch in milliseconds |
timezone |
A character with the time zone used for the conversion |
Value
A POSIXct, the date corresponding to the epoch
Examples
epoch <- Date2EpochMilli(as.numeric(Sys.time()))
EpochMilli2Date(epoch)
Thingboard API Class
Description
Thingboard API Class
Fields
url
character URL of the 'ThingsBoard' IoT platform.
publicId
character the public ID of the device
token
character the current token
tokenTimeOut
A numeric contains the time out of a token in seconds (default 300)
tokenEpiration
A numeric with the Epoch of the expiration date time of current token
See Also
The ThingsboardApi
class methods :
-
ThingsboardApi_checkToken for checking and refreshing the token
-
ThingsboardApi_getToken for getting authorisation token from Thingsboard server for a specific device
-
ThingsboardApi_getKeys for fetching data keys of an entity
-
ThingsboardApi_getValues and ThingsboardApi_getTelemetry for fetching telemetry of an entity
Examples
thinksboard_api = tryCatch(
{
ThingsboardApi(url="http://scada.g-eau.fr",
publicId="299cedc0-f3e9-11e8-9dbf-cbc1e37c11e3")
},
error = function(e) {
message("An error occured:\n", e)
return(FALSE)
}
)
Check if the token is timeouted and refresh it if necessary
Description
This method is automatically call by each other methods of the class ThingsboardApi. So, except for debugging purpose, it's not useful to call directly.
Value
Fetch data keys for an entity
Description
Fetch data keys for an entity
Arguments
entityId |
character entity ID |
entityType |
character (default "DEVICE") |
Details
The description of this operation in API documentation is here: https://thingsboard.io/docs/user-guide/telemetry/#get-telemetry-keys
Value
A vector of character with the keys available for the requested device.
Fetch telemetry
Description
Fetch telemetry data of an entity.
It uses the following API: https://thingsboard.io/docs/user-guide/telemetry/#get-telemetry-values
The method getValues
has a strong limitation as the 'ThingsBoard' API only send the
100 last values of each key. The method getTelemetry
overcomes this limitation by
automatically by calling getValues
in a loop.
Arguments
entityId |
A character with the entity ID given (See https://thingsboard.io/docs/user-guide/entity-views/) |
keys |
Vector of character with the list of keys from which getting the telemetry values |
entityType |
A character (default "DEVICE") |
startTs |
A numeric or a POSIXct representing respectively the epoch or the date of the start of data extraction period |
endTs |
A numeric or a POSIXct representing respectively the epoch or the date of the end of data extraction period |
Value
A data.frame with one row per data and 3 columns:
-
key
: a character with the key -
ts
: a POSIXct with the timestamp of the data -
value
: a numeric with the value of the data
Get authorisation token from thingsboard server for a specific device
Description
This method is automatically called by ThingsboardApi_checkToken, and so by any other methods of the class ThingsboardApi as needed. Except for debugging purpose, it's not useful to call directly.
Arguments
timeOut |
numeric number of second before token timeout (default field |
Value
A list with keys 'token' and 'refreshtoken'