def read(serial):
    temp_f = serial.readline()
    # Adjust the temperature according to the configured offset.
    temp_f_adjusted = temp_f + config["temp_offset"]
    temp = "{0:.2f}".format(temp_f_adjusted)

    date = datetime.utcnow()
    time = calendar.timegm(date.utctimetuple())

    # Send data to temperature logger.
    postTempData(config["sensor_id"], temp, time)

    # Log data to command line.
    print "{0}, {1}".format(date, temp.rstrip())
def read(serial):
    temp_f = serial.readline()
    # Adjust the temperature according to the configured offset.
    temp_f_adjusted = temp_f + config["temp_offset"]
    temp = "{0:.2f}".format(temp_f_adjusted)

    date = datetime.utcnow()
    time = calendar.timegm(date.utctimetuple())

    # Send data to temperature logger.
    postTempData(config["sensor_id"], temp, time)

    # Log data to command line.
    print "{0}, {1}".format(date, temp.rstrip())
Esempio n. 3
0
    device_folder = glob.glob(base_dir + '28*')[0]
    device_file_path = device_folder + '/w1_slave'
    device_file = open(device_file_path, "r")
    text = device_file.read()
    device_file.close()

    # Grab the second line, parse it, and find the temperature value.
    temp_line = text.split("\n")[1]
    temp_data = temp_line.split(" ")[9]
    temp_c = float(temp_data[2:]) / 1000
    temp_f = temp_c * 9.0 / 5.0 + 32.0
    # Adjust the temperature according to the configured offset.
    temp_f_adjusted = temp_f + config["local_temp_offset"]
    temp = "{0:.2f}".format(temp_f_adjusted)
    return temp

while True:
    # Get current temperature and timestamp.
    temp = readTempFromGPIO()
    date = datetime.utcnow()
    timestamp = calendar.timegm(date.utctimetuple())

    # Send data to temperature logger.
    postTempData(config["local_sensor_id"], temp, timestamp)

    # Log data to command line.
    print "{0}, {1}".format(date, temp.rstrip())

    # Wait [local_temp_read_delay] seconds.
    time.sleep(config["local_temp_read_delay"])
# Current time (UNIX timestamp).
date = datetime.utcnow()
time = calendar.timegm(date.utctimetuple())

# Current temperature.
uri = 'http://api.openweathermap.org/data/2.5/weather?id=' + city_id
req = requests.get(uri)

if req.status_code != requests.codes.ok:
    print "Could not retrieve current weather data."
    exit(1)

# Get JSON as an object.
data = req.json()

# Log the data if it was returned successfully.
if ('main' in data.keys()) and ('temp' in data['main'].keys()):
    temp_k = data['main']['temp']
    temp_f = (temp_k * 9 / 5.0) - 459.67
    temp = "{0:.2f}".format(temp_f)

    # Send data to temperature logger.
    postTempData(sensor_id, temp, time, exit_on_error=True)

else:
    print "Could not retrieve data from Open Weather Map API."
    exit(1)

# Log the successfully-posted data.
print "{0}, {1}".format(time, temp.rstrip())
# Current time (UNIX timestamp).
date = datetime.utcnow()
time = calendar.timegm(date.utctimetuple())

# Current temperature.
uri = 'http://api.wunderground.com/api/' + wu_api_key + '/conditions/q/' + wu_location + '.json'
req = requests.get(uri)

if req.status_code != requests.codes.ok:
    print "Could not retrieve current weather data."
    exit(1)

# Get JSON as an object.
data = req.json()

# Log the data if it was returned successfully.
if ('current_observation' in data.keys()) and ('temp_f' in data['current_observation'].keys()):
    temp_f = data['current_observation']['temp_f']
    temp = "{0:.2f}".format(temp_f)

    # Send data to temperature logger.
    postTempData(config["wu_sensor_id"], temp, time, exit_on_error=True)

else:
    print "Could not retrieve data from Weather Underground API."
    exit(1)

# Log the successfully-posted data.
print "{0}, {1}".format(date, temp.rstrip())
Esempio n. 6
0
    device_folder = glob.glob(base_dir + '28*')[0]
    device_file_path = device_folder + '/w1_slave'
    device_file = open(device_file_path, "r")
    text = device_file.read()
    device_file.close()

    # Grab the second line, parse it, and find the temperature value.
    temp_line = text.split("\n")[1]
    temp_data = temp_line.split(" ")[9]
    temp_c = float(temp_data[2:]) / 1000
    temp_f = temp_c * 9.0 / 5.0 + 32.0
    # Adjust the temperature according to the configured offset.
    temp_f_adjusted = temp_f + config["local_temp_offset"]
    temp = "{0:.2f}".format(temp_f_adjusted)
    return temp

while True:
    # Get current temperature and timestamp.
    temp = readTempFromGPIO()
    date = datetime.utcnow()
    timestamp = calendar.timegm(date.utctimetuple())

    # Send data to temperature logger.
    postTempData(config["local_sensor_id"], temp, timestamp)

    # Log data to command line.
    print "{0}, {1}".format(date, temp.rstrip())

    # Wait [local_temp_read_delay] seconds.
    time.sleep(config["local_temp_read_delay"])
Esempio n. 7
0
    print "NEST_ACCESS_TOKEN and NEST_THERMOSTAT_ID env vars must be set."
    exit(1)

# Current time (UNIX timestamp).
date = datetime.utcnow()
time = calendar.timegm(date.utctimetuple())

# Log into Nest API.
uri = 'https://developer-api.nest.com/devices/thermostats/' + nest_thermostat_id
payload = {'auth': nest_access_token}
headers = {'Accept': 'application/json'}
req = requests.get(uri, params=payload, headers=headers)

if req.status_code != requests.codes.ok:
    print "Could not retrieve thermostat information from Nest API."
    exit(1)

data = req.json()
if ('ambient_temperature_f' in data.keys()):
    temp = "{0:.2f}".format(data['ambient_temperature_f'])

    # Send data to temperature logger.
    postTempData(config["nest_sensor_id"], temp, time, exit_on_error=True)

else:
    print "Could not retrieve temperature data from Nest API."
    exit(1)

# # Log the successfully-posted data.
print "{0}, {1}".format(time, temp.rstrip())