Package 'zentracloud'

Title: Access to METER ZentraCloud API
Description: Provides functions to access the METER ZENTRACLOUD API.
Authors: Carola Stolle [cre, aut], Christoph Stepper [aut], Florian Detsch [aut], Tim Appelhans [aut], Eric Scott [ctb] , Joran Beasley [ctb]
Maintainer: Carola Stolle <[email protected]>
License: MIT + file LICENSE
Version: 0.4.9
Built: 2024-11-11 06:31:11 UTC
Source: https://gitlab.com/meter-group-inc/pubpackages/zentracloud

Help Index


Clear Zentracloud Package Cache

Description

Clear package cache of files older then the specified number of days.

Usage

clearCache(
  cache_dir = getOption("ZENTRACLOUD_CACHE_DIR"),
  file_age = getOption("ZENTRACLOUD_CACHE_MAX_AGE")
)

Arguments

cache_dir

character Cache folder. Defaults to the cache directory stored in options, but can be changed if files were saved somewhere else. MUST be the highest level of the cache to run properly.

file_age

integer Number of days since today. Files older than this date will be deleted. If file_age = 0L, files from the current day will be also included.

Details

clearCache is automatically called when the package is attached.


Query Data from ZENTRACLOUD API

Description

Query data from the ZENTRA Cloud API for a specific device serial number and time period.

Usage

getReadings(
  device_sn,
  start_time,
  end_time,
  force_api = FALSE,
  ignore_cache = FALSE
)

Arguments

device_sn

character device serial number of interest.

start_time, end_time

character datetime strings in the format "YYYY-MM-DD hh:mm:ss" specifying the start/end of the requested time period. Must be in logger time zone!

force_api

logical If TRUE, API call is forced irrespective of existing cached data. Cache directory is updated with fetched API results. Default FALSE.

ignore_cache

logical If TRUE, directory path set in ZENTRACLOUD_CACHE_DIR is ignored. No data are read or permanently written to disk. Default FALSE.

Details

Options

To use getReadings(), valid values for the ZENTRACLOUD options must be set (see setZentracloudOptions()). Make sure that the token and domain match.

Cache

Per default, a cache directory is created at the location specified in the ZENTRACLOUD_CACHE_DIR option at first function-call. Here, the data are saved, sorted by device, sensor, year and month. For subsequent calls, the cache is checked for already existing data before the API is called again.

Value

A list of data.frames for the queried time period with columns for datetime and all values. One list entry for each logger. Unit and precision of each value are stored as attributes of the respective columns.

Examples

## Not run: 
setZentracloudOptions(
  token = Sys.getenv("ZENTRACLOUD_TOKEN")
)

dat = getReadings(
 device_sn = "06-01185"
 , start_time = "2022-03-20 00:00:00"
 , end_time = "2022-03-26 23:59:00"
)

## End(Not run)

Write Package Settings to Global Options

Description

Five package options are set, see Arguments. For retrieving the current set of options use getZentracloudOptions().

Usage

setZentracloudOptions(
  token,
  domain = "default",
  cache_dir = NULL,
  cache_max_age = NULL,
  cache_max_size = NULL
)

getZentracloudOptions()

Arguments

token

valid token for the ZENTRA Cloud API that is to be saved to the options.

domain

character The domain for which the token is valid. One of "default" (zentracloud.com), "tahmo", "aroya", "skala", "EU", "CN". Corresponds to the URL where the token is created.

cache_dir

directory for setting up the cache. If NULL, default is set depending on the operating system.

cache_max_age

the maximum file age allowed to be cached (in days). If NULL, set to default 7.

cache_max_size

the maximum cache size (in Kb). If NULL, set to default 500.

Details

tokens are only valid for a specific domain. Currently, the match is not verified here.

Examples

setZentracloudOptions(
  token = "tkn1!$"
  , domain = "default"
)
str(
  getZentracloudOptions()
)

Get settings from API

Description

The function accesses the v.1 ZENTRA Cloud API to read the device settings for the given serial number. Settings include information on measurement intervals, device location and time settings.

Usage

queryDeviceSettings(device_sn)

Arguments

device_sn

character serial number of the device that should be queried.

Details

To use this function, valid values for the ZENTRACLOUD options must be set (see setZentracloudOptions()). Make sure that the token and domain match.

Value

A list object with three entries, containing device settings and meta information.

Examples

## Not run: 
set = queryDeviceSettings(
 device_sn = "06-01185"
)

## End(Not run)

Read all Data from Cache

Description

Load all files that are saved in the cache.

Usage

readCache(cache_dir = getOption("ZENTRACLOUD_CACHE_DIR"))

Arguments

cache_dir

character Cache folder. Defaults to the cache directory stored in options, but can be changed if files were saved somewhere else. MUST be the highest level of the cache to run properly.

Value

A list with entries for each device that was found and all associated data, sorted by logger.

Examples

## Not run: 
all_cached = readCache(cache_dir = getOption("ZENTRACLOUD_CACHE_DIR"))

## End(Not run)

ZENTRA Data Example

Description

Subset of example data return from getReadings.

Usage

zentra_data

Format

A list with 6 elements for different sensor/port combinations, each containing a time series of the respective measurements.

Source

METERGROUP

Examples

## Not run: 
zentra_data = getReadings(
device_sn = "06-01185"
, start_time = "2022-06-01 00:00:00"
, end_time = "2022-06-14 23:59:00"
, force = FALSE
)

## End(Not run)