Tim
Tim

Reputation: 11

Nested arguments RCurl

I like to know if someone can help me with this problem. I have a Iungo energy logger and like to extract logged values from its memory. Its producer gave me a curl code but I like to extract it using R because I have no experience with curl. The curl code is:

curl -X POST -d '{"seq":1,"method":"datalog_get","arguments":{"t1":"1458663908", "t2":"1458664000", "oid": "538d72d9", "prop":"T1"}}'
http://192.168.178.22/iungo/api_request

From what I could find on Stackoverflow I composed a R code:

library(RCurl)
data = postForm("http://192.168.178.41/iungo/api_request",
                 .opts = list(seq="1", method="datalog_get",
                 arguments=c(t1="1458169200", t2="1458255600", 
                 oid= "7bbf70c3",   prop="T1")))

But all variations I tried resulted in a crash. I suspect the problem is in the nested arguments, any suggestions? Thanks, Tim.

Upvotes: 0

Views: 1405

Answers (1)

hrbrmstr
hrbrmstr

Reputation: 78832

Try:

library(httr)

res <- POST("http://192.168.178.22/iungo/api_request",
            body=list(seq = 1L,
                      method = "datalog_get", 
                      arguments = list(t1 = "1458663908", 
                                       t2 = "1458664000", 
                                       oid = "538d72d9", 
                                       prop = "T1")))
content(res, as="parsed")

Upvotes: 2

Related Questions