Last active
November 23, 2018 14:21
-
-
Save rw950431/2b1a632f49e89cb0c3ac6b77433f13fa to your computer and use it in GitHub Desktop.
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 characters
import os | |
import glob | |
import time | |
import sys | |
import datetime | |
import urllib2 | |
baseURL = "https://api.thingspeak.com/update?api_key=(MY KEY)&field1=&field2=" | |
os.system('modprobe w1-gpio') | |
os.system('modprobe w1-therm') | |
# add more sensor variables here based on your setup | |
temps=[] | |
base_dir = '/sys/bus/w1/devices/' | |
device_folders = glob.glob(base_dir + '28*') | |
def read_temp_raw(device_file): | |
f = open(device_file, 'r') | |
lines = f.readlines() | |
f.close() | |
return lines | |
def read_temp(device_file): # checks the temp recieved for errors | |
lines = read_temp_raw(device_file) | |
while lines[0].strip()[-3:] != 'YES': | |
time.sleep(0.2) | |
lines = read_temp_raw(device_file) | |
equals_pos = lines[1].find('t=') | |
if equals_pos != -1: | |
temp_string = lines[1][equals_pos+2:] | |
# set proper decimal place for C | |
temp = float(temp_string) / 1000.0 | |
# Round temp to 2 decimal points | |
temp = round(temp, 1) | |
# value of temp might be unknown here if equals_pos == -1 | |
return temp | |
while True: #infinite loop | |
for sensors in range (2): # change number of sensors based on your setup | |
device_file=device_folders[sensors]+ '/w1_slave' | |
temp[sensors] = read_temp(device_file) | |
print device_file,sensors,temp[sensors] | |
g = urllib2.urlopen(baseURL + "&field1=%s&field2=%s" % (temp[0], temp[1])) | |
time.sleep(60) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import os
import glob
import time
import sys
import datetime
import urllib, urllib2
baseURL = "https://api.thingspeak.com/update?api_key=XXXXXXXXXXX"
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
add more sensor variables here based on your setup( 28-
temp=['sensor code','tttttttttt','ddddddddddd','ssssssssss']
base_dir = '/sys/bus/w1/devices/'
device_folders = glob.glob(base_dir + '28*')
def read_temp_raw(device_file):
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp(device_file): # checks the temp recieved for errors
lines = read_temp_raw(device_file)
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw(device_file)
while True: #infinite loop