def temperature_set(): # Load database configuration settings config_section_db = loadconfig('DB') # Load configuration settings config_section_temperature = loadconfig('TEMPERATURE') # Get temperature data from hardware probes, store in json json_data['temperature'] = ds18b20.main() # Add JSON value for temperature probe description if defined in config file for key in config_section_temperature.keys(): if key is not "__name__": try: # Errors if key does not exsist json_data['temperature'][key].update({"description":config_section_temperature.get(key)}) except: # Ignore and move on pass # Pull db name and table name from config file, sql.py will create files if non exsist. db_database = config_section_db.get('database_name') db_table = config_section_db.get('table_name') sql.temperature(db_database, db_table, json_data['temperature']) # Defined in ds18b20.py script return jsonify(json_data), 200
def temperature_get(): # Load configuration settings config_section_temperature = loadconfig('TEMPERATURE') # Load Callibration settings for defined probes config_section_callibrate = loadconfig('CALLIBRATE') # Define JSON key and load data from ds18b20 json_data['temperature'] = ds18b20.main() if config_section_temperature.get('dht22_enabled') == "1": # Load DHT22 temperature if enabled in config, will cause 30s delay if sensor does not exsist! json_data['temperature'].update(dht22.main()) else: # Ignore getting DHT22 data and move on pass # Add JSON value for temperature probe description if defined in config file for key in config_section_temperature.keys(): if key is not "__name__": try: # Errors if key does not exsist json_data['temperature'][key].update({"description":config_section_temperature.get(key)}) except: # Ignore and move on pass # Does some math to alter the readings if sensor is off for key in config_section_callibrate.keys(): if key is not "__name__": try: # Pulls the correction value from config file per sensor name correction_value = float(config_section_callibrate[key]) # Current and incorrect temperature value original_celsius = float(json_data['temperature'][key]['celsius']) # Find new celsius value correct_celsius = original_celsius + correction_value # Calculate new fahrenheit values correct_fahrenheit = 9.0/5.0 * correct_celsius + 32 # Update the JSON with correct values json_data['temperature'][key].update({"celsius":round(correct_celsius,2)}) json_data['temperature'][key].update({"fahrenheit":round(correct_fahrenheit,2)}) except: # Ignore and move on, write message to console pass # Load cache file data temperature_file = config_section_temperature.get('file') # Write output to file with open(temperature_file , 'w') as outfile: json.dump(json_data, outfile) # Defined in ds18b20.py script return jsonify(json_data), 200