#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import glob
import time
import eeml
# Setting up the temp probes
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
# The two 28-XXXX numbers below are my two temp probes
# You'll need to replace those with your own
base_dir = '/sys/bus/w1/devices/'
device1_folder = glob.glob(base_dir + '28-00000480c6e8')[0]
device1_file = device1_folder + '/w1_slave'
device2_folder = glob.glob(base_dir + '28-000004837542')[0]
device2_file = device2_folder + '/w1_slave'
# Insert your API KEY below.
API_KEY = 'PutYourAPIKeyHere,LeaveTheApostrophes'
# Replace the XX's with your FEED ID, e.g. 120160
FEED = XXXXX
API_URL = '/v2/feeds/{feednum}.xml' .format(feednum = FEED)
def read_temp_raw1():
f = open(device1_file, 'r')
lines1 = f.readlines()
f.close()
return lines1
def read_temp_raw2():
f = open(device2_file, 'r')
lines2 = f.readlines()
f.close()
return lines2
def read_temp1():
lines1 = read_temp_raw1()
while lines1[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines1 = read_temp_raw1()
equals_pos = lines1[1].find('t=')
if equals_pos != -1:
temp_string = lines1[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32
# temp_f is our temp in F, but it's a floating integer.
# we want a rounded number. Replace the number 1 below with 2
# if you want your value in hundreths not teths.
temp_r = "%.1f" % round(temp_f,1)
return temp_r
def read_temp2():
lines2 = read_temp_raw2()
while lines2[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines2 = read_temp_raw2()
equals_pos = lines2[1].find('t=')
if equals_pos != -1:
temp_string = lines2[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 31.77
# Same deal as above, we're rounding our reading for probe2
temp_r = "%.1f" % round(temp_f,1)
return temp_r
# Doing two things here, first printing the temps in the
# terminal window. Secondly, sending the data to COSM
while True:
print(read_temp1(), read_temp2())
pac = eeml.Pachube(API_URL, API_KEY)
# Change 'FermentationTemp' to whatever you want
pac.update ([eeml.Data('FermentationTemp', read_temp1(), unit=eeml.Fahrenheit())])
# FridgeTemp is my second Stream name, change as well
pac.update ([eeml.Data('FridgeTemp', read_temp2(), unit=eeml.Fahrenheit())])
pac.put()
# This polls every 7 seconds. You could go longer if you like.
time.sleep(7)