Skip to content

Instantly share code, notes, and snippets.

@jwygralak67
Last active December 26, 2015 02:19
Show Gist options
  • Save jwygralak67/7078118 to your computer and use it in GitHub Desktop.
Save jwygralak67/7078118 to your computer and use it in GitHub Desktop.
Gather temperature data and log it online in a Google Docs spreadsheet. I've munged the URLs so no one else can start logging their data to my spreadsheet.
#
# A temperature logger
#
import httplib
import urllib
from serial import Serial
from time import sleep
ser = Serial(port='com4', timeout=5)
ser.write('f\n')
while 1:
# sending 'f<cr>' to the arduino causes it to respond with the current temperature in deg F
ser.write('f\n')
resp = ser.readline().strip()
if resp == '':
continue
print "Temperature: {}".format(resp)
params = urllib.urlencode({'entry.355915883': resp})
#change this------------------------^^^^^^^^^^^^^^^
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
conn = httplib.HTTPSConnection("docs.google.com")
conn.request("POST", "/forms/d/1wn-gxf67pF1SdC4-PVh03w3TgKcVZTedX3P6JCXphm0/formResponse", params, headers)
#and change this-----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
sleep(300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment