function get_sensor_name_by_id ($sensor_id) {
	// get sensor name list 
	$sensor_list = get_sensor_name_list();
	
	//return the sensor name if that is found in the list. Othervise return the sensor ID
	
	return  (array_key_exists($sensor_id, $sensor_list)) ?  $sensor_list[$sensor_id] : $sensor_id;
	
	//return  ($sensor_list[$sensor_id] != null) ? $sensor_list[$sensor_id] : $sensor_id;
}
function read_thermometers ($use_sensor_names = true) {

//$the_data = exec ("sudo python /home/pi/remote_pi/read_thermometers.py"); 
// get this data from APC
$latest_sensor_data  = apc_fetch('latest_sensor_data');


if ($latest_sensor_data) {
		$the_data = $latest_sensor_data['data'];
		//var_dump ($latest_sensor_data);
		if ($use_sensor_names) {

			$sensor_list = get_sensor_name_list();
			
			foreach ($sensor_list as $key => $value) 
					$the_data = str_replace($key,$value,$the_data);
			}
		return $the_data;
	}
}
    $return_data["rawdata"] = $response_to_client;
    print json_encode($return_data);
    exit;
}
if ($request_action == "try_to_log_in" and $login_status == "login_good") {
    $response_to_client['response_code'] = "OK";
    $response_to_client['response_data'] = "";
}
// process various API requests.
if ($request_action == "get_realtime_data" or $request_action == "get_realtime_data_series_increment") {
    $response_code = "OK";
    require_once "read_thermometers.php";
    require_once "sensor_names.php";
    $the_data = read_thermometers(false);
    $array_of_readings = json_decode($the_data);
    $sensor_name_list = get_sensor_name_list();
    foreach ($array_of_readings as $key => $value) {
        $sensor_id = $key;
        //foreach ($sensor_list as $key => $value)
        if (isset($sensor_name_list[$key])) {
            $sensor_array['sensor_name'] = $sensor_name_list[$key];
        } else {
            $sensor_array['sensor_name'] = $key;
        }
        $sensor_array['value'] = $value;
        $output_new[$sensor_id] = $sensor_array;
    }
    $response_to_client['response_code'] = $response_code;
    $response_to_client['response_data'] = $output_new;
}
if ($request_action == "get_GPIO_list") {