Exemple #1
0
bool Sprinkler::load_sensors_config() {
	StringBuffer sb;
		Vector<SensorPtr> new_sensors;


	// Load sensors
	bool ret = Communication::GetWebPage(SENSORS_CONFIGURATION_URL, sb);
	if (ret)
			ret = JSON::parse_sensors(sb.GetBuffer(), new_sensors);
	if(ret)
	{
		// Check if need to update sensors.
		if(sensors.size() != new_sensors.size()) {
			sensors = new_sensors;
		}
		else {
			const unsigned int number_of_sensors = sensors.size();
			for(unsigned int sensor_index = 0 ; sensor_index < number_of_sensors ; sensor_index++) {
				if(sensors[sensor_index]->UpdateFrom(new_sensors[sensor_index].get())) {
					sensors[sensor_index] = new_sensors[sensor_index];
				}
			}
		}
		
		// assign listener
		const unsigned int number_of_sensors = sensors.size();
		for(unsigned int sensor_index = 0 ; sensor_index < number_of_sensors ; sensor_index++)
			sensors[sensor_index]->SetListener(this);
	}
	
	return ret;
}
Exemple #2
0
bool Sprinkler::load_sprinkler_config()
{
	StringBuffer sb;
	bool ret = Communication::GetWebPage(SPRINKLER_CONFIGURATION_URL, sb);
	if (ret)
		ret = JSON::parse_sprinkler_configuration(sb.GetBuffer(), *this); // I'll go to hell bcz of this circular dependency.
	
	return ret;
}
Exemple #3
0
bool Sprinkler::load_valves_config() 
{
	StringBuffer sb;
	bool ret = Communication::GetWebPage(SPRINKLER_VALVES_URL, sb);
	if (ret) {
		Vector<ValfPtr> new_valves;
		ret = JSON::parse_valves(sb.GetBuffer(), new_valves);
		if(ret)
			valves = new_valves;
	}

	return ret;
}
Exemple #4
0
bool Sprinkler::load_time()
{
	bool ret;
	StringBuffer sb;

	Logger::AddLine("Sprinkler::load_time : Updating clock.", Logger::DUMP);
	ret = Communication::GetWebPage(TIME_URL, sb);
	if (ret) {
		unsigned int current_time = 0;
		ret = JSON::parse_time(sb.GetBuffer(), current_time);
		if(ret)
			TimeManager::SetSystemTime(current_time);
	}

	if(!ret) {
			Logger::AddLine("sprinkler_load_irrigations : failed load irrigations instructions.", Logger::ERROR);
	}
	return ret;

}
Exemple #5
0
bool Sprinkler::load_irrigations_instructions() {
	// load irrigation definitions
	bool ret;
	StringBuffer sb;

	Logger::AddLine("sprinkler_load_irrigations : Loading irrigations instructions.", Logger::DUMP);
	ret = Communication::GetWebPage(SPRINKLER_IRRIGATION_URL, sb);
	if (ret) {
		Vector<Irrigation> new_irrigations;
		ret = JSON::parse_irrigations(sb.GetBuffer(), new_irrigations);
		if(ret) {
			last_irrigation_load_time = TimeManager::GetSystemTime();
			irrigations = new_irrigations;
		}
	}

	if(!ret) {
			Logger::AddLine("sprinkler_load_irrigations : failed load irrigations instructions.", Logger::ERROR);
	}
	return ret;
}