I bought my first Electric Imp some time ago and it works like a charm. I’ve written a number of simple agent and device code segments and they work as expected. Now I’m ready to post data to the Sparkfun data stream. I have read the Electric imp http api documents and I still can’t figure it out. I know that this URL will post data to my Sparkfun data stream: http://data.sparkfun.com/input/mysparkfundatastreamid?private_key=myprivatekey&test1=testdata1&test2= testdata2
Can someone write two or three specific lines of agent code that will send this data to Sparkfun? If I can get one URL to work, I can go from there. Thanks for any suggestions.
I’m new to this too. What was your problem. My data uploads when I use a URL but not when I use the Imp, not entirely sure that I’m using the imp correctly.
Sorry, I didn’t realize that my email notification was off. Here is working code to post data to Sparkfun if you are still interested:
//Agent Code: Read imp voltage and lightlevel every 15 seconds and post data online
//SparkFun Data parameters
SFpublicKey <- “0123456789”; SFprivateKey <- “0123456789”; (change these keys)
URL <- “https://data.sparkfun.com/input/” + SFpublicKey;
label1 <- “voltage=”; label2<- "&light="
headers <- {“Phant-Private-Key”: SFprivateKey, “connection”: “close”};
function PostData(darray) {
local datavalue=label1 + darray[0] + label2 + darray[1]
local request = http.post(URL,headers,datavalue);
local response = request.sendsync();
server.log(“SparkFun Response: " + response.body+” "+darray[2] )
}
function receivedata(darray) { PostData(darray) }
device.on(“data”,receivedata)
function Loop() {device.send(“readdata”,“unused”); imp.wakeup(15,Loop) }
Loop()
//Device Code: Read imp voltage and lightlevel and post data online
function getdata(unused)
{ agent.send(“data”,[hardware.voltage(),hardware.lightlevel(),“this is a comment”]) }
agent.on(“readdata”,getdata )