Skip to contents
library(photobiology)
#> Loading required package: SunCalcMeeus
#> Documentation at https://docs.r4photobiology.info/
library(rYoctoPuceInOut)
library(jsonlite)

The USB module settings

Module settings can be saved from the configuration web interface of the modules or using the programing API. The configuration file uses the JSON format, and its structure is a nested list with a maximum depth of three.

The package includes example configuration files for several different USB modules from YoctoPuce. The first step is to retrieve the path to the file in the current in use R library.

yocto_meteo_json.file <-
  system.file("extdata", "METEOMK2-19A230.json",
              package = "rYoctoPuceInOut", mustWork = TRUE)

We can then read the file into an R list. At the root of the list we find "module", "extras" and "files". The "module" nested-list is always present, contains whole-module settings and one nested list for each “sensor” or sensor data channel, "humidity", "pressure" and "temperature" in this case. In those modules with data logging capabilities the "dataLogger" nested list contains its settings. In this example, "extras" and "files" are empty.

meteo.settings <- read_json(yocto_meteo_json.file)
str(meteo.settings)
#> List of 3
#>  $ api   :List of 5
#>   ..$ module     :List of 13
#>   .. ..$ productName       : chr "Yocto-Meteo-V2"
#>   .. ..$ serialNumber      : chr "METEOMK2-19A230"
#>   .. ..$ logicalName       : chr "C2-Meteo"
#>   .. ..$ productId         : int 132
#>   .. ..$ productRelease    : int 1
#>   .. ..$ firmwareRelease   : chr "69970"
#>   .. ..$ persistentSettings: int 1
#>   .. ..$ luminosity        : int 50
#>   .. ..$ beacon            : int 0
#>   .. ..$ upTime            : int 32506
#>   .. ..$ usbCurrent        : int 24
#>   .. ..$ rebootCountdown   : int 0
#>   .. ..$ userVar           : int 0
#>   ..$ humidity   :List of 15
#>   .. ..$ logicalName     : chr "C2_humidity"
#>   .. ..$ advertisedValue : chr "31.6"
#>   .. ..$ unit            : chr "% RH"
#>   .. ..$ currentValue    : int 2068316
#>   .. ..$ lowestValue     : int 2068316
#>   .. ..$ highestValue    : int 2162688
#>   .. ..$ currentRawValue : int 2068316
#>   .. ..$ logFrequency    : chr "1/m"
#>   .. ..$ reportFrequency : chr "OFF"
#>   .. ..$ advMode         : int 0
#>   .. ..$ calibrationParam: chr "0,"
#>   .. ..$ resolution      : int 6553
#>   .. ..$ sensorState     : int 0
#>   .. ..$ relHum          : int 2068316
#>   .. ..$ absHum          : int 413597
#>   ..$ pressure   :List of 13
#>   .. ..$ logicalName     : chr "C2_pressure"
#>   .. ..$ advertisedValue : chr "1023"
#>   .. ..$ unit            : chr "mbar"
#>   .. ..$ currentValue    : int 67040313
#>   .. ..$ lowestValue     : int 67040247
#>   .. ..$ highestValue    : int 67044245
#>   .. ..$ currentRawValue : int 67040313
#>   .. ..$ logFrequency    : chr "1/m"
#>   .. ..$ reportFrequency : chr "OFF"
#>   .. ..$ advMode         : int 0
#>   .. ..$ calibrationParam: chr "0,"
#>   .. ..$ resolution      : int 655
#>   .. ..$ sensorState     : int 0
#>   ..$ temperature:List of 17
#>   .. ..$ logicalName     : chr "C2_temperature"
#>   .. ..$ advertisedValue : chr "22.52"
#>   .. ..$ unit            : chr "°C"
#>   .. ..$ currentValue    : int 1476067
#>   .. ..$ lowestValue     : int 1471741
#>   .. ..$ highestValue    : int 1476067
#>   .. ..$ currentRawValue : int 1476067
#>   .. ..$ logFrequency    : chr "1/m"
#>   .. ..$ reportFrequency : chr "OFF"
#>   .. ..$ advMode         : int 0
#>   .. ..$ calibrationParam: chr "0,"
#>   .. ..$ resolution      : int 655
#>   .. ..$ sensorState     : int 0
#>   .. ..$ sensorType      : int 0
#>   .. ..$ signalValue     : int 0
#>   .. ..$ signalUnit      : chr ""
#>   .. ..$ command         : chr ""
#>   ..$ dataLogger :List of 9
#>   .. ..$ logicalName    : chr "C2_Meteo_logger"
#>   .. ..$ advertisedValue: chr "ON"
#>   .. ..$ currentRunIndex: int 6
#>   .. ..$ timeUTC        : int 1769286179
#>   .. ..$ recording      : int 1
#>   .. ..$ autoStart      : int 1
#>   .. ..$ beaconDriven   : int 0
#>   .. ..$ usage          : int 1
#>   .. ..$ clearHistory   : int 0
#>  $ extras: list()
#>  $ files : list()

So, to ensure full reproducibility, when this is important, this list can be stored in the data frame containing the measured data. The only weakness is that data and settings are originally in separate files, and matching them when data are imported is not automated.

The column headings in the .CSV file containing the logged data are always the same as the names of the corresponding nested lists in the settings. Users can assign an arbitrary logical name to the sensors and set or store unit of expression as part of the settings. Thus the settings file can be used to extract these metadata and store them as data frame attributes.

Example CSV files

These files contain data logged by USB modules from YoctoPuce. These files are included for use in the documentation and for testing the package itself. They can be also useful when learning about the USB modules YoctoPuce. They have been all truncated to a header row plus 199 data rows.

system.file("extdata", package = "rYoctoPuceInOut", mustWork = TRUE) |>
  list.files(pattern = "csv$")
#>  [1] "yocto-0-10V-Rx.csv"                     
#>  [2] "yocto-bridge-missing-time.csv"          
#>  [3] "yocto-bridge-repeated-times.csv"        
#>  [4] "yocto-bridge-unsorted-time.csv"         
#>  [5] "yocto-bridge-with-weighing-platform.csv"
#>  [6] "yocto-CO2-V1.csv"                       
#>  [7] "yocto-i2c-tsl2591.csv"                  
#>  [8] "yocto-meteo-snm.csv"                    
#>  [9] "yocto-millivolt-Rx.csv"                 
#> [10] "yocto-serial.csv"                       
#> [11] "yocto-spectral-LED.csv"

Be aware that these CSV files use dots (.) as decimal marker and semicolon (;) as field separator, with no white space. Consequently, if using read.csv() it is necessary to pass sep = ";" in the call.

Example JSON files

These files contain exported settings from USB modules from YoctoPuce. These files are included for use in the documentation and for testing the package itself. They can be also useful when learning about the USB modules. They are as exported for the modules.

system.file("extdata", package = "rYoctoPuceInOut", mustWork = TRUE) |>
  list.files(pattern = "json$")
#>  [1] "METEOMK1-D15FF.json"           "METEOMK2-19A230.json"         
#>  [3] "RELAYLO1-B263A.json"           "RX010V01-1219AD.json"         
#>  [5] "RXMVOLT1-3EEE1-corrupted.json" "RXMVOLT1-3EEE1.json"          
#>  [7] "SPECTRL1-2CF3B6.json"          "YCO2MK01-39F22.json"          
#>  [9] "YI2CMK01-1214E2.json"          "YSERIAL1-EAD24.json"          
#> [11] "YWBRIDG1-12683B.json"

Example R data

A data.frame created by importing file yocto-spectral-LED.csv together with file SPECTRL1-2CF3B6.json is included as yocto_spectral.df.

head(yocto_spectral.df)
#>                  time      F1.avg      F2.avg      FZ.avg      F3.avg
#> 1 2025-12-03 19:54:00  0.00000000  0.00000000  0.01923449  0.00000000
#> 2 2025-12-03 19:55:00 14.81709593 13.26026119 10.70854803 14.03453598
#> 3 2025-12-03 19:56:00  0.20996641  0.62779851  1.43448786  1.28698813
#> 4 2025-12-03 19:57:00  0.01586413  0.01212687  0.01720980  0.01690788
#> 5 2025-12-03 19:58:00  0.01586413  0.01212687  0.01619746  0.01690788
#> 6 2025-12-03 19:59:00  0.01586413  0.01212687  0.01619746  0.01591330
#>        F4.avg      FY.avg      F5.avg     FXL.avg      F6.avg      F7.avg
#> 1  0.01892148  0.08539738  0.00000000  0.09671708  0.08235444  0.06817170
#> 2 14.68704875 14.28618803 17.99289470 19.16909935 17.43903218 68.53901431
#> 3  1.30558184  0.45975569  0.24968026  0.66015027  1.58963228 59.34804452
#> 4  0.01593387  0.01985986  0.01890010  0.02136773  0.02010981  0.02340223
#> 5  0.01493801  0.01787387  0.01691062  0.01799387  0.01436415  0.01933227
#> 6  0.01394214  0.01787387  0.01691062  0.01799387  0.01340654  0.01933227
#>        F8.avg     NIR.avg     VIS.avg
#> 1  0.00000000 0.000000000  0.08138610
#> 2 69.80591451 3.403664712 37.22971629
#> 3 57.34681909 0.720682303 50.17541353
#> 4  0.02057654 0.003291578  0.02034652
#> 5  0.01943340 0.003464819  0.01592337
#> 6  0.01943340 0.003291578  0.01503874
cat(comment(yocto_spectral.df))
#> Data logged by a YoctoPuce USB module.
#> Data file "yocto-spectral-LED.csv" created on 2026-01-25 23:48:09.
#> Metadata file "SPECTRL1-2CF3B6.json" created on 2026-01-25 23:48:09.
#> Imported on 2026-01-25 23:50:24 using TZ = "UTC" with 'rYoctoPuceInOut' (== 0.0.1.1).
cat(how_measured(yocto_spectral.df))
#> USB module named 'spectrl-01' type 'Yocto-Spectral',
#> s.n. 'SPECTRL1-2CF3B6' with firmware '69970'.
#> Units: not available.

All the data objects included in the package can be listed.

data(package='rYoctoPuceInOut') |>
repr::repr_text() |> cat()
#> Data sets in package 'rYoctoPuceInOut':
#> 
#> y_spectral.descriptor (modules-metadata)
#>                         Metadata for YoctoPuce modules
#> yocto_spectral.df (yocto-spectral-df)
#>                         Example of imported spectral data