A low cost air quality sensor (AQE) sends its data to the opensensors.io server. Every x seconds it sends a string of information (timestamp, pollutant concentration, etc). The data can be retrieved structured as a json file. Opensensors terminology uses devices
, topics
, organizations
, and payloads
. I have figured out how to set up a curl handle and use the curl package to download a csv file. Here's the code
curl_download(url = myURL2, destfile = "curlDownloadTest.csv", mode = "w", handle = myCurlHandle)
An example of the downloaded data is at https://github.com/GeraldCNelson/AQEAnalysis/commit/c6ee29545d07835c5a920bf2b37625adb78462aa
I use fromJSON
in the jsonlite package to transform this
temp <- fromJSON("curlDownloadTest.csv", simplifyDataFrame = FALSE)
The output (temp
) is a large list with 2 elements - messages and next. messages
contains all the data; next
is a link to use to get the next set of data (it's not all downloaded at once).
The messages list consists of multiples sets of lists (one for each set of uploaded data); each set has five elements - device
, owner
, topic
, date
, and payload
. Payload is a list of 3 - encoding
(always chr utf-8), content-type
(always chr "application/json"), and text
. The text list looks like its in json format (here's a string fragment - "{\"serial-number\":\"egg00802aaa019b0111\",\"converted-value\":69.52,\"converted-units\":\"degF\")
I want to restructure this data into a data frame (or data table) that has
the date information as a column and the test information from payload as the remaining columns (serial-number
, converted value
, etc...
I can't figure out how to convert the text list in the payload list from its current (json?) structure to something I can rbind to a data frame.