Using Xively with Electric Imp

Next in this little series of interfacing with other internet services, we come to Xively, which was earlier known as Cosm, which before that was known as Pachube…

There are already a library to interface with Xively from the Electric Imp, but I don’t like it, instead I use this little piece of code to update a feed.


function addXively(csv)
    local req = http.put("" + XIVELY_FEED_ID + ".csv", {"X-ApiKey":XIVELY_API_KEY, "Content-Type":"text/csv", "User-Agent":"Xively-Imp-Lib/1.0"}, csv);
    local res = req.sendsync();

    if(res.statuscode != 200)
        server.log("error sending message: "+res.body);
      server.log("Xively updated");

To use this function to send some data points to a feed, you need to call it with a CSV formatted variable.

This could be done like this

addXively("Light," + sensorReading);

More sensors can be added like this

addXively("Light," + lightSensor + "\nTemperature," + temperatureSensor);

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.