Network Interface multiple instance

Hi, actually in my Numaker project ESP an interface for WiFi communication. In the application esp should change its roll from station to access point on periodically vice-versa. Only initial mode either station or access point is working fine, the problem comes when its changes rolls. So how do I this without any issues?