 				break;
 	 	    case ACI_EVT_DATA_RECEIVED:
 		        Serial.println(F("DATA RECEIVED"));
-		        Serial.print(F("Pipe #: 0x"));
-		        Serial.println(aci_evt->params.data_received.rx_data.pipe_number, HEX);
+		        // Serial.print(F("Pipe #: 0x"));
+		        // Serial.println(aci_evt->params.data_received.rx_data.pipe_number, HEX);
 		        
 				uint16_t value;
 		        switch(aci_evt->params.data_received.rx_data.pipe_number) {
 		        	case PIPE_CONNECTIONCONTROL_CONNECTIONINTERVAL_RX_ACK_AUTO:
-		        		Serial.println(F("CONNECTION_INTERVAL: "));
+		        		Serial.print(F("CONNECTION_INTERVAL: "));
 		        		// printData(aci_evt);
 
 		        		// Two bytes
  						// big-endian !!!!
 						value = aci_evt->params.data_received.rx_data.aci_data[1] + ((uint16_t)aci_evt->params.data_received.rx_data.aci_data[0] << 8);
-		        		Serial.print(F("Value: "));
+						connection_interval = value;
 		        		Serial.println(value);
 		        		break;
 		        	case PIPE_CONNECTIONCONTROL_SLAVELATENCY_RX_ACK_AUTO:
-		        		Serial.println(F("SLAVELATENCY: "));
+		        		Serial.print(F("SLAVELATENCY: "));
 		        		// printData(aci_evt);
 
 		        		// One byte
  						// big-endian !!!!
-						value = aci_evt->params.data_received.rx_data.aci_data[1];
-						Serial.print(F("Value: "));
+						value = aci_evt->params.data_received.rx_data.aci_data[0];
+						slave_latency = value;
 		        		Serial.println(value);
 		        		break;	
 		        	case PIPE_CONNECTIONCONTROL_SAMPLINGRATE_RX_ACK_AUTO:
-		        		Serial.println(F("SAMPLING_RATE: "));
+		        		Serial.print(F("SAMPLING_RATE: "));
 		        		// printData(aci_evt);
 						
 						// 4 Bytes
  						// big-endian !!!!
-						value = aci_evt->params.data_received.rx_data.aci_data[1] + ((uint16_t)aci_evt->params.data_received.rx_data.aci_data[0] << 8);
-		        		Serial.print(F("Value: "));
+ 						if(aci_evt->len - 2 > 1) {
+							value = aci_evt->params.data_received.rx_data.aci_data[1] + ((uint16_t)aci_evt->params.data_received.rx_data.aci_data[0] << 8);
+ 						} else {
+							value = aci_evt->params.data_received.rx_data.aci_data[0];
+ 						}
+						sampling_rate = value;
 		        		Serial.println(value);
+
+						Serial.print(F("SLEEPING_TIME: "));
+						sleep_time = ((1/ (double) sampling_rate) * 1000000);
+		        		Serial.println(sleep_time);
+		        		break;
+		        	case PIPE_CONNECTIONCONTROL_BUFFERLIMIT_RX_ACK_AUTO:
+						Serial.print(F("BUFFER_LIMIT: "));
+		        		// printData(aci_evt);
+						
+						// 1 Byte
+ 						// big-endian !!!!
+						value = aci_evt->params.data_received.rx_data.aci_data[0];
+						if(value > 0) {
+							buffer_limit = value;
+		        			Serial.println(value);
+						} else {
+							Serial.println(F("<invalid>"));
+						}
 		        		break;
 		        	default:
 		        		printData(aci_evt);

	lib_aci_init(&aci_state);
	heart_rate_init();
	buffer_init();
}

void aci_loop()

	
	if (isChannelOpen())
	{
		handleCommands();
		if(checkTransmissionCriteria()) {
			sendData();
		}
	}
	if(sleep_time < 16383) {
		delayMicroseconds(sleep_time);
	} else {
		delay(sleep_time / 1000);
	}
}

