R/system_essid.R

Defines functions system_essid

Documented in system_essid

#' Function to return a system's extended service set identification (ESSID) 
#' names. 
#' 
#' @author Stuart K. Grange
#' 
#' @return Tibble. 
#' 
#' @export
system_essid <- function() {
  
  # Get and clean system commands
  suppressWarnings(
    text <- system("iwgetid", intern = TRUE)
  )
  
  # Check return and if nothing return empty data frame
  if (length(text) == 0) {
    
    warning("No valid adaptors detected...", call. = FALSE)
    return(tibble())
    
  }
  
  text_split <- stringr::str_split(text, " ")[[1]]
  text_split <- text_split[!text_split == ""]
  
  # Clean pieces
  adapter <- text_split[1]
  essid <- text_split[2]
  essid <- stringr::str_split_fixed(essid, ":", 2)[, 2]
  essid <- stringr::str_replace_all(essid, '"', "")
  
  # Build data frame
  df <- tibble(adapter = adapter, essid = essid)
  
  return(df)
  
}
skgrange/systemr documentation built on April 18, 2024, 2:23 a.m.