Created
November 17, 2012 23:01
Revisions
-
glisha revised this gist
Nov 17, 2012 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,16 +34,19 @@ if not line or line == '\r\n': break line = line.strip() if line == "OPEN": hacklab_status = 1 else: hacklab_status = 0 print line url="http://api.cosm.com/v2/feeds/%s/datastreams/%s/datapoints" % (cosm['feed_id'],"hacklab_status") headers = {'X-ApiKey':cosm['api_key']} payload={'datapoints': [{'at': curr_time, 'value': hacklab_status}]} print url print json.dumps(payload) r = requests.post(url, data=json.dumps(payload), headers=headers) -
glisha created this gist
Nov 17, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ #!/usr/bin/env python2.7 """ Reads out the temp sensors from serial and posts them to https://cosm.com/feeds/86779 """ import serial import json import requests import time import ConfigParser import os import sys pwd = os.path.dirname(os.path.realpath(sys.argv[0])) config_file = os.path.join(pwd,"readout_tocosm.cfg") config = ConfigParser.ConfigParser() config.read(config_file) cosm = dict(config.items("cosm")) #set up the serial and ask for data ser = serial.Serial("/dev/ttyUSB0", timeout=10) ser.flushInput() time.sleep(10) ser.write("a") #current time will be the same for all uploads curr_time = time.strftime("%Y-%m-%dT%H:%M:%SZ%z", time.gmtime()) #read the data while True: line = ser.readline() if not line or line == '\r\n': break if line == 'OPEN\r\n': hacklab_status = 1 else: hacklab_status = 0 url="http://api.cosm.com/v2/feeds/%s/datastreams/%s/datapoints" % (cosm['feed_id'],"hacklab_status") headers = {'X-ApiKey':cosm['api_key']} payload={'datapoints': [{'at': curr_time, 'value': hacklab_status}]} print url print json.dumps(payload) r = requests.post(url, data=json.dumps(payload), headers=headers) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ [cosm] feed_id=86779 api_key=<COSM KEY>