/*
 * esp8266.c
 *
 *  Created on: Jul 9, 2019
 *      Author: parkyj
 */


#include "esp8266.h"


void ESP8266_Initialize(void){
	  volatile static bool init = false;
	  volatile static uint8_t seq = 0;
	  if(init == false ||  seq < 4){
		  init = true;
	  }else{
	  /* * * * *DATA SEND COMMADN * * * * * */
#if 1 // PYJ.2019.08.06_BEGIN --
          Uart2_Data_Send("AT+CIPSEND=0,9\r\n",ESP8266_Strindex("AT+CIPSEND=0,9\r\n"));
          HAL_Delay(1000);
          Uart2_Data_Send("123456789\r\n",ESP8266_Strindex("123456789\r\n"));
#endif // PYJ.2019.08.06_END -- 
//          Uart2_Data_Send("AT+CIPSEND=1,1\r\n",ESP8266_Strindex("AT+CIPSEND=1,1\r\n"));
//          HAL_Delay(5); 
//          Uart2_Data_Send("1\r\n",ESP8266_Strindex("1\r\n"));              
        return;
	  }
	  switch(seq){
	  case 0:
          Uart2_Data_Send("AT+CWMODE=3\r\n",ESP8266_Strindex("AT+CWMODE=3\r\n"));
		  seq++;
		  break;
	  case 1:
          Uart2_Data_Send("AT+CIPMUX=1\r\n",ESP8266_Strindex("AT+CIPMUX=1\r\n"));
		  seq++;
		  break;
	  case 2:
          Uart2_Data_Send("AT+CWSAP=\"BLUE_TEST\",\"\",5,0\r\n",ESP8266_Strindex("AT+CWSAP=\"BLUE_TEST\",\"\",5,0\r\n"));
		  seq++;
		  break;
	  case 3:
          Uart2_Data_Send("AT+CIPSERVER=1,4000\r\n",ESP8266_Strindex("AT+CIPSERVER=1,4000\r\n"));
          HAL_Delay(5);
          Uart2_Data_Send("AT+CIFSR\r\n",ESP8266_Strindex("AT+CIFSR\r\n"));
		  printf("ESP Setting Complete \r\n");
		  seq++;
		  break;
	  default:
		  break;
	  }

}
uint8_t ESP8266_Strindex(uint8_t* str){
    return strlen(str);
}
