Package 'Rthingsboard'

Title: 'ThingsBoard' API
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.
Authors: David Dorchies [aut, cre]
Maintainer: David Dorchies <[email protected]>
License: AGPL-3
Version: 0.2.7
Built: 2024-11-24 03:54:53 UTC
Source: https://github.com/ddorch/rthingsboard

Help Index


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

a numeric representing an epoch in seconds or a POSIXt date

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)

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

NULL


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 tokenTimeOut)

Value

A list with keys 'token' and 'refreshtoken'


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 :

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)
  }
)