#' @title Encendido alumbrado estancias privadas
#'
#' @description Enciende el alumbrado de las estancias privadas
#'
#' @param campo
#'
#' @return json
#'
#' @examples encendido_alumbrado_estancias_privadas(campo=0)
#'
#' @import httr
#' jsonlite
#' rjson
#' RCurl
#' dplyr
#' lubridate
#' timeDate
#'
#' @export
encendido_alumbrado_estancias_privadas <- function(campo=0){
id_aulas <- c("f4d0d070-24dd-11eb-b605-01af9c6dd825","fa1cb5d0-24dd-11eb-b605-01af9c6dd825","feccf770-24dd-11eb-b605-01af9c6dd825","03179970-24de-11eb-b605-01af9c6dd825","083542e0-24de-11eb-b605-01af9c6dd825","0e3d9a70-24de-11eb-b605-01af9c6dd825","02d28360-2da0-11eb-b605-01af9c6dd825","0b615ec0-2da0-11eb-b605-01af9c6dd825")
id_empresas <- c("aa6cf240-24d6-11eb-b605-01af9c6dd825","af8e9350-24d6-11eb-b605-01af9c6dd825","7f2c2bf0-276a-11eb-b605-01af9c6dd825","b5fc6370-24d6-11eb-b605-01af9c6dd825","caaf8810-276a-11eb-b605-01af9c6dd825","c38cfbd0-24d6-11eb-b605-01af9c6dd825","cba93f40-24d6-11eb-b605-01af9c6dd825","cf2ac4e0-24d6-11eb-b605-01af9c6dd825","e7d0e380-24d6-11eb-b605-01af9c6dd825","ef5309d0-24d6-11eb-b605-01af9c6dd825","79a16980-2da4-11eb-b605-01af9c6dd825","f9bf09a0-24d6-11eb-b605-01af9c6dd825","00f6b970-24d7-11eb-b605-01af9c6dd825","04c79790-24d7-11eb-b605-01af9c6dd825","08af5910-24d7-11eb-b605-01af9c6dd825","575a6340-2da4-11eb-b605-01af9c6dd825")
id_despachos_pb <- c("1e6fea50-24df-11eb-b605-01af9c6dd825","229e9fe0-24df-11eb-b605-01af9c6dd825","27a84c20-24df-11eb-b605-01af9c6dd825","2c6781e0-24df-11eb-b605-01af9c6dd825","30d7fb60-24df-11eb-b605-01af9c6dd825","350fffc0-24df-11eb-b605-01af9c6dd825","39802b20-24df-11eb-b605-01af9c6dd825","43d0b3b0-24df-11eb-b605-01af9c6dd825","47b05ee0-24df-11eb-b605-01af9c6dd825","4c4e7810-24df-11eb-b605-01af9c6dd825","92a2d790-24dd-11eb-b605-01af9c6dd825")
id_seminarios <- c("a14e2ec0-24dd-11eb-b605-01af9c6dd825","b97ea830-24dd-11eb-b605-01af9c6dd825","b4f30590-24dd-11eb-b605-01af9c6dd825","a14e2ec0-24dd-11eb-b605-01af9c6dd825","cabeb400-24dd-11eb-b605-01af9c6dd825","d89f8f40-24dd-11eb-b605-01af9c6dd825","e2ca4050-24dd-11eb-b605-01af9c6dd825")
id_despachos_p1 <- c("5321b630-24de-11eb-b605-01af9c6dd825","59d9d5c0-24de-11eb-b605-01af9c6dd825","5eaeb660-24de-11eb-b605-01af9c6dd825","6311c260-24de-11eb-b605-01af9c6dd825","67f54900-24de-11eb-b605-01af9c6dd825","6d17ad60-24de-11eb-b605-01af9c6dd825","72dda4c0-24de-11eb-b605-01af9c6dd825","7d24b770-24de-11eb-b605-01af9c6dd825","817d8a40-24de-11eb-b605-01af9c6dd825","860200f0-24de-11eb-b605-01af9c6dd825","8a7fe7f0-24de-11eb-b605-01af9c6dd825","900c7fd0-24de-11eb-b605-01af9c6dd825","9fef93b0-24de-11eb-b605-01af9c6dd825")
id_dispositivos <- c(id_aulas, id_empresas, id_despachos_pb, id_seminarios, id_despachos_p1)
# ==============================================================================
# PETICIÓN TOKEN THB
# ==============================================================================
cuerpo <- '{"username":"kepa@techfriendly.es","password":"kepa_tech"}'
post <- httr::POST(url = "http://116.202.100.157:8080/api/auth/login",
add_headers("Content-Type"="application/json","Accept"="application/json"),
body = cuerpo,
encode = "json",verbose()
)
resultado_peticion_token <- httr::content(post)
auth_thb <- paste("Bearer",resultado_peticion_token$token)
# ==============================================================================
# ENCENDIDO POR HORARIO
# ==============================================================================
# Registro ON
auth_chirpstack <- "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlfa2V5X2lkIjoiOTU2OWFkODctZGQzMC00NWM3LWJiY2EtNjhiMDFhNGE5ODY2IiwiYXVkIjoiYXMiLCJpc3MiOiJhcyIsIm5iZiI6MTYxMDQzNzg1Mywic3ViIjoiYXBpX2tleSJ9.gEnEi84JHBkqZMxKiJLe8wRE-ZaNKTXmOXj4sqoGD9g"
for(i in 1:length(id_dispositivos)){
# 0) Get Dev eui de atributos
keys <- URLencode(c("dev_eui"))
url <- paste("http://116.202.100.157:8080/api/plugins/telemetry/DEVICE/",id_dispositivos[i], "/values/attributes?keys=",keys,sep = "")
get_dev_eui <- httr::GET(url = url, add_headers("Content-Type"="application/json","Accept"="application/json","X-Authorization"=auth_thb))
get_dev_eui <- jsonlite::fromJSON(rawToChar(get_dev_eui$content))
dev_eui <- get_dev_eui$value[1]
# 1) Comando alumbrado
url_downlink_chirp <- paste("http://94.130.25.30:8080/api/devices/",dev_eui,"/queue",sep = "")
post <- httr::POST(url = url_downlink_chirp,
add_headers("Content-Type"="application/json","Accept"="application/json","Grpc-Metadata-Authorization"=auth_chirpstack),
body = list(deviceQueueItem=list(confirmed= TRUE,data="MTA=",devEUI=dev_eui,fPort= 2)),
encode = "json",verbose()
)
# 2) Modificación atributo para tener registro
# GET token del dispositivo
url <- paste("http://116.202.100.157:8080/api/device/",id_dispositivos[i],"/credentials",sep = "")
get_token <- httr::GET(url = url, add_headers("Content-Type"="application/json","Accept"="application/json","X-Authorization"=auth_thb))
token <- jsonlite::fromJSON(rawToChar(get_token$content))
token <- token$credentialsId
url <- paste("http://116.202.100.157:8080/api/v1/",token,"/attributes",sep = "")
json_envio_plataforma <- paste('{"Alumbrado OFF/ON":', TRUE,'}',sep = "")
post <- httr::POST(url = url,
add_headers("Content-Type"="application/json","Accept"="application/json","X-Authorization"=auth_thb),
body = json_envio_plataforma,
verify= FALSE,
encode = "json",verbose()
)
Sys.sleep(0.1)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.