Skip to content

Instantly share code, notes, and snippets.

@sweemeng
Created March 20, 2014 13:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sweemeng/9663343 to your computer and use it in GitHub Desktop.
Save sweemeng/9663343 to your computer and use it in GitHub Desktop.
Xively demo with tgs2600
#!/usr/bin/python/
# Get xively library in https://github.com/xively/xively-python
import xively
import datetime
def main():
now = datetime.datetime.utcnow()
earliest = now - datetime.timedelta(minutes=30)
api = xively.XivelyAPIClient("SL2N1SZTVFZHxb2p2DXq1GdtaKInCpv521mFtOxwmkrrBvsL")
feed = api.feeds.get("1068165020")
datastreams = feed.datastreams.get("sensor1",start=earliest, end = now)
for data in datastreams.datapoints:
print data.at, data.value
if __name__ == "__main__":
main()
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char xivelyKey[] = "You Key";
char sensorId[] = "sensor1";
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
XivelyFeed feed(feed_id_here, datastreams, 1);
EthernetClient client;
XivelyClient xivelyclient(client);
void setup(){
Serial.begin(9600);
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP");
}
}
void loop(){
int sensor_value = analogRead(2);
datastreams[0].setFloat(sensor_value);
Serial.println(datastreams[0].getFloat());
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("Xivelyclient.put returned:");
Serial.println(ret);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment