Skip to content

Instantly share code, notes, and snippets.

@paulschow
Created December 6, 2014 05:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Room temp with python and phant on a beaglebone black
#!/usr/bin/env python
import phant
import time
import pywapi
import Adafruit_BBIO.ADC as ADC
ADC.setup()
# phant.py from https://github.com/matze/python-phant
# Set up phant
p = phant.Phant('public_key', 'temp',
'internettemp', private_key='xxxxx')
while True:
#read_raw returns non-normalized value
# Read the value from pin 36
# Voltage in mv
fakevoltage = ADC.read_raw("P9_36")
# Read it twice to get the actual value
# Due to a glitch in BBIO
voltage = ADC.read_raw("P9_36")
#print voltage
tempc = voltage / 10
print tempc
# Get weather from the internet
try:
#use weather.com for zip code 80918
weather_com_result = pywapi.get_weather_from_weather_com('80918')
except:
print "Internet Error"
wtemp = 0
try:
#get temperature from internet and convert to int
wtemp = int(weather_com_result['current_conditions']['temperature'])
print wtemp
except:
print "Temperature Error"
wtemp = 0
# Send data to phant
p.log(tempc, wtemp)
# Sleep for 10 minutes
time.sleep(600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment