Learn R Programming

Rduinoiot

Rduinoiot provides an easy way to connect to Arduino Iot Cloud API with R. Functions allow to exploit API methods for many purposes, manage your Arduino devices and dashboards and access to the data produced by sensors and sketches. This is not an official library by Arduino.

Installation

You can install the development version of Rduinoiot from GitHub with:

# install.packages("devtools")
devtools::install_github("FlavioLeccese92/Rduinoiot")

Authentication

In order to access the API methods you need to create an API key. This can be done by logging into your Arduino Cloud account and going to the page https://cloud.arduino.cc/home/api-keys/ and retrieve corresponding ARDUINO_API_CLIENT_ID and ARDUINO_API_CLIENT_SECRET.

library(Rduinoiot)
# Sys.setenv(ARDUINO_API_CLIENT_ID = 'INSERT CLIENT_ID HERE')
# Sys.setenv(ARDUINO_API_CLIENT_SECRET = 'INSERT CLIENT_SECRET HERE')

create_auth_token()
#> v Authorization succeeded

List things associated to the user

Things associated to the user account can be easily accessed using things_list(). This function will return detailed information, in particular things_id which are needed to access to properties.

tl = things_list()
#> v Method succeeded

Real-time sensor data

Reading real-time humidity sensor of one of your devices can be done as follow:

thing_id = "b6822400-2f35-4d93-b3e7-be919bdc5eba"
property_id = "d1134fe1-6519-49f1-afd8-7fe9e891e778" # Humidity

data_ts = things_properties_timeseries(thing_id = thing_id,
                                       property_id = property_id,
                                       desc = FALSE, interval = 3600)
#> v Method succeeded

Plotting the result

A catchy representation of humidity time series can be plotted, for instance, by using the library echarts4r by John Coene:

library(echarts4r)
library(dplyr)
library(lubridate)

data_ts = data_ts %>% mutate(time = with_tz(time, tzone = Sys.timezone()))

data_ts %>%
  e_charts(time) %>%
  e_line(value, name = "Value", color = "#007BFF", showSymbol = FALSE, smooth = TRUE,
         connectNulls = TRUE, animation = FALSE, emphasis = NULL,
         lineStyle = list(width = 1)) %>%
  e_title(left = 'center', text = "Humidity",
          subtext = "Last 1000 values averaged hourly",
          textStyle = list(fontWeight = 'lighter')) %>%
  e_grid(top = 70, right = 30, left = 50, bottom = 30) %>%
  e_x_axis(show = TRUE, type = "time") %>%
  e_y_axis(show = TRUE, scale = TRUE) %>%
  e_legend(show = FALSE)

Copy Link

Version

Install

install.packages('Rduinoiot')

Monthly Downloads

197

Version

0.1.0

License

MIT + file LICENSE

Maintainer

Flavio Leccese

Last Published

September 14th, 2022

Functions in Rduinoiot (0.1.0)

devices

Devices API methods
devices_tags

Tags (of devices) API methods
things_properties_timeseries

Data from Properties (of things) API methods
things_properties

Properties (of things) API methods
devices_properties_timeseries

Data start Properties (of devices) API methods
devices_properties

Properties (of devices) API methods
series_batch

Batch queries API methods
create_auth_token

Create Auth Token for Arduino IoT Cloud API
things_tags

Tags (of things) API methods
things

Things API methods