Originally "throwback Thursday" but now often used on other days. Can now stand for "throwback to" to indicate an old photo, thought, idea, etc. Often used in social media to reminisce, as usually social media is supposed to show the "here/now/recently."
import os
import glob
import json
import urllib2
import time
import RPi.GPIO as GPIO
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'
hanaposts = 0
hanaposts2 = 0
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
# set up GPIO output channel
GPIO.setup(18, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
def blink(pin):
GPIO.output(pin,GPIO.HIGH)
time.sleep(1)
GPIO.output(pin,GPIO.LOW)
time.sleep(1)
return
def basic_authorization(user, password):
s = user + ":" + password
return "Basic " + s.encode("base64").rstrip()
def read_temp_raw():
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c
while True:
hanaposts += 1
txtTemp = read_temp()
txtDate = '/Date(' + str(int(time.time())) + ')/'
url = 'http://[SERVER IP]:[SERVER PORT]/sap/devs/demo/iot/services/iot_input.xsodata/sensor'
params = {"ID": "1", "TDATE": txtDate, "SVALUE": str(txtTemp), "SNAME": "Craig", "STYPE": "Temp" }
req = urllib2.Request(url,
headers = {
"Authorization": basic_authorization('[USER]', '[PASSWORD]'),
"Content-Type": "application/json",
"Accept": "*/*",
}, data = json.dumps(params))
f = urllib2.urlopen(req)
# LED
if hanaposts == 25:
hanaposts = 0
hanaposts2 += 1
blink(22)
if hanaposts2 == 50:
hanaposts2 = 0
blink(18)
time.sleep(1)
jsonStr = getServerResponse('http://[SERVER IP]/[XS PATH]/iot_control.xsodata/control?$format=json&$filter=SCONTROL%20eq%20%27COLD%27')
coldTemp = jsonStr['d']['results'][0]['SVALUE']
import os
import glob
import json
import urllib2
import time
import RPi.GPIO as GPIO
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'
maxtemp = 0
mintemp = 0
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
def blink(pin):
GPIO.output(pin, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(pin, GPIO.LOW)
time.sleep(0.5)
return
def temp_low():
GPIO.output(12, GPIO.HIGH)
GPIO.output(13, GPIO.LOW)
GPIO.output(15, GPIO.HIGH)
GPIO.output(16, GPIO.LOW)
return
def temp_high():
GPIO.output(12, GPIO.LOW)
GPIO.output(13, GPIO.HIGH)
GPIO.output(15, GPIO.HIGH)
GPIO.output(16, GPIO.LOW)
return
def temp_ok():
GPIO.output(12, GPIO.LOW)
GPIO.output(13, GPIO.LOW)
GPIO.output(15, GPIO.LOW)
GPIO.output(16, GPIO.HIGH)
return
# Get values from server
def getServerResponse(url):
req = urllib2.Request(url)
opener = urllib2.build_opener()
f = opener.open(req)
return json.loads(f.read())
def basic_authorization(user, password):
s = user + ":" + password
return "Basic " + s.encode("base64").rstrip()
def read_temp_raw():
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c
jsonStr = getServerResponse("http://[SERVER IP]/sap/devs/demo/iot/services/iot_control.xsodata/control?$format=json&$filter=SCONTROL%20eq%20%27COLD%27")
mintemp = jsonStr['d']['results'][0]['SVALUE']
print ('MIN Temp is set at ' + mintemp + 'c')
jsonStr = getServerResponse("http://[SERVER IP]/sap/devs/demo/iot/services/iot_control.xsodata/control?$format=json&$filter=SCONTROL%20eq%20%27HOT%27")
maxtemp = jsonStr['d']['results'][0]['SVALUE']
print ('MAX Temp is set at ' + maxtemp + 'c')
while True:
# Value of Sensor
txtTemp = read_temp()
# Timestamp
txtDate = '/Date(' + str(int(time.time())) + ')/'
# HTTP Post to HANA
url = 'http://[SERVER IP]/sap/devs/demo/iot/services/iot_input.xsodata/sensor'
params = {"ID": "1", "TDATE": txtDate, "SVALUE": str(txtTemp), "SNAME": "MySensor", "STYPE": "Temp" }
# print(params)
req = urllib2.Request(url,
headers = {
"Authorization": basic_authorization('[USER]', '[PASSWORD]'),
"Content-Type": "application/json",
"Accept": "*/*",
}, data = json.dumps(params))
f = urllib2.urlopen(req)
blink(18)
jsonStr = getServerResponse("http://[SERVER IP]/sap/devs/demo/iot/services/iot.xsodata/IOT?$orderby=ID%20desc&$top=1&$select=SVALUE&$filter=SNAME%20eq%20%27Ian%27&$format=json")
currtemp = jsonStr['d']['results'][0]['SVALUE']
if (float(currtemp) <= float(maxtemp)):
if (float(currtemp) < float(mintemp)):
print ('>>> HEATER ON ' + currtemp + "c lower than MIN temp of " + str(mintemp) + "c")
temp_low()
else:
print ('HEATER/FAN OFF ' + currtemp + "c within bounds")
temp_ok()
else:
print ('>>> FAN ON ' + currtemp + "c exceeds MAX temp of " + str(maxtemp) + "c")
temp_high()
# Loop to next reading
time.sleep(3)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 |