Development of control system for the optimization of irrigation consumption and nitrogen leaching in agriculture