Skip to content

2. Environment

Lorenzo Pasco edited this page Sep 10, 2021 · 16 revisions

environment_img

Border router

Border router is needed to guarantee communication between sensors and actuators. Then it's needed to control the environment with the Cloud Computing application, thanks to CoAP protocol.

Resources consistency

To recreate a real simulation, the consistency among the resources is guaranteed. In fact, if at some time T0 the grass humidity detected was equal to 60% and the sprinkler was ON, in a successive point in time T1 the humidity grass will be necessarily greater than before. In base to the temperature detected, the increase (or decrease) would be more or less signifying:

  • If grass humidity is equal or higher the threshold and temperature is higher or equal the threshold setted, the sprinkler is ON because the high temperature detected and the successive grass humidity will be slightly higher than before: from 0% to 3%.
  • If grass humidity is equal or higher the threshold and temperature is lower the threshold setted, the sprinkler is OFF because the high grass humidity detected and the successive grass humidity will be lower: from 1% to 8%.
  • If grass humidity is lower the threshold and the temperature is higher or equal the threshold setted, the sprinkler is ON because both the low grass humidity detected and the high temperature, but the successive grass humidity will be slightly higher than before (due to high temperature): from 0% to 3%.
  • If grass humidity is lower the threshold and the temperature is lower the threshold setted, the sprinkler is ON because the low grass humidity detected and the successive grass humidity will be significantly higher than before: from 1% to 8%.

This is the function used to adapt the new humidity value in base of previous conditions detected:

    int handle_humidity(){
	int ret;
	if(handler == -1) //during app warm up	
		return 50;
	else if(handler == 0){//higher decrease (from 1 to 8 percentuals points)
		rnd_val_hum = rand()% 8 + 1;
		ret = hum_value - rnd_val_hum;
		if(ret < 0)
			ret = 0;
	}else if(handler == 1){//higher increase (from 1 to 8 percentuals points)
		rnd_val_hum = rand()% 8 + 1;
		ret = hum_value + rnd_val_hum;
		if(ret > 100)
			ret = 100;
	}else if(handler == 2){//lower increase (from 0 to 3 percentuals points)
		rnd_val_hum = rand()% 3;
		ret = hum_value + rnd_val_hum;
		if(ret > 100)
			ret = 100;
	}
	return ret;
     }

Now we can see how we set ON or OFF the sprinkler in base of the temperature or humidity detected:

//if sprinkler is manually off, grass humidity decrease
if(!is_on){
	handler = 0;
	leds_set(LEDS_NUM_TO_MASK(LEDS_RED)); 
}else{
	//if grass humidity is higher than the threshold
	if(hum_value >= threshold_hum){
		//if temperature is higher the threshold sprinkler is on and grass humidity increases gradually
		if(temp_value >= threshold_temp){
			handler = 2;
			leds_set(LEDS_NUM_TO_MASK(LEDS_GREEN));
			is_sprinkling=true;
		// if temperature is lower the threshold sprinkler is off and grass humidity decreases
		} else{
			handler = 0;
			leds_set(LEDS_NUM_TO_MASK(LEDS_YELLOW));
			is_sprinkling=false;
		}
	}
	//if grass humidity is lower than the threshold in any case sprinkler is on
	if(hum_value < threshold_hum){
		//if temperature is higher than the threshold, grass humidity increases gradually
		if(temp_value >= threshold_temp){
			handler = 2;
		//if temperature is lower than the thresold, grass humidity increases
		} else{
			handler = 1;
		}
		leds_set(LEDS_NUM_TO_MASK(LEDS_GREEN));
		is_sprinkling=true;
	}
}

During the time, temperature varies in a small range (between 1 and 3 degrees, upper or lower a fixed temperature) and after 10 iterations both fixed temperature and grass humidity vary significantly to simulate a change in time and weather (another season or day/night).

Sensors

There are two different types of sensors: one to get the temperature and the other one to get field's humidity every 10 seconds. When we start the sensors, for the first 10 second they are off, then they are ready to start. Both sensors performs three types of operations: get, post and they can work as observing resources.

  • GET: with this operation we can get the temperature or the humidity from the sensor.
  • POST: with this operation we can set a threshold to permit or not the sprinkler to release water.
  • OBSERVING RESOURCES: every 10 seconds resources are updated with the new temperature or humidity detected. In our Cloud Computing application, when we are in observing mode, only the grass humidity detected is shown due to its importance for the irrigation.

Actuator

The actuator is the sprinkler, the object which releases water under certain condition. The actuator can be turn off: in this case we can see the red led on and in this case the sprinkler doesn't release water. If the actuator is on, it can release or not the water (green and yellow led respectively), depending to the threshold setted in the sensor and following the explanation already made in section Resources consistency.

Both the thresholds can be setted manually by the farmer, according to the crops. The operations permitted by the actuator are post, get and it can works observing resource:

  • GET: with this operation we can see if the sprinkler is turn off or if it's sprinkling or not. In other words, we can see the leds' colors.
  • POST: with this operation we can turn on or off the sprinkler.
  • OBSERVING RESOURCES: every 10 seconds the sprinklers are update with the current state.
Clone this wiki locally