123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /*
- * esp8266.c
- *
- * Created on: Jul 9, 2019
- * Author: parkyj
- */
- #include <string.h>
- #include <stdlib.h>
- #include "esp8266.h"
- void ESP8266_Initialize(void){
- volatile static bool init = false;
- volatile static uint8_t seq = 0;
- uint8_t str[100] = {0,};
- if(init == false || seq < 4){
- init = true;
- }else{
- /* * * * *DATA SEND COMMADN * * * * * */
- #if 0 // PYJ.2019.08.06_BEGIN --
- Uart2_Data_Send("AT+CIPSEND=0,4\r\n",ESP8266_Strindex("AT+CIPSEND=0,4\r\n"));
- HAL_Delay(1000);
- sprintf(str,"%d", ADC_Value_RetFunc());
- Uart2_Data_Send(str,ESP8266_Strindex(str));
- printf("%s\r\n INDEX : %d",str,ESP8266_Strindex(str));
- HAL_Delay(500);
- // Uart2_Data_Send("be\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;
- }
- #if 1 // PYJ.2019.12.13_BEGIN --
- switch(seq){
- case 0:
- Uart2_Data_Send("AT+CWMODE=3\r\n",ESP8266_StrLength("AT+CWMODE=3\r\n"));
- seq++;
- break;
- case 1:
- Uart2_Data_Send("AT+CIPMUX=1\r\n",ESP8266_StrLength("AT+CIPMUX=1\r\n"));
- seq++;
- break;
- case 2:
- Uart2_Data_Send("AT+CWSAP=\"BLUE_TEST\",\"\",5,0\r\n",ESP8266_StrLength("AT+CWSAP=\"BLUE_TEST\",\"\",5,0\r\n"));
- seq++;
- break;
- case 3:
- Uart2_Data_Send("AT+CIPSERVER=1,4000\r\n",ESP8266_StrLength("AT+CIPSERVER=1,4000\r\n"));
- HAL_Delay(5);
- Uart2_Data_Send("AT+CIFSR\r\n",ESP8266_StrLength("AT+CIFSR\r\n"));
- printf("ESP Setting Complete \r\n");
- seq++;
- break;
- default:
- break;
- }
- #endif // PYJ.2019.12.13_END --
- }
- uint8_t ESP8266_StrLength(uint8_t* str){
- return strlen(str);
- }
- uint8_t ESP8266_StrIndexSearch(uint8_t* str,uint8_t* searchstr){
- for(int i = 0; i < ESP8266_StrLength(str); i++){
- if(*(str + i) == *searchstr){
- // printf("\"%s \" index : %d \r\n",*searchstr, i);
- return i;
- }
- }
- return 0;
- }
- uint8_t ESP8266_StrFilter(uint8_t* str){
- uint8_t *ptr = strstr(str, "+IPD,0,30:"); // den으로 시작하는 문자열 검색, 포인터 반환
- uint8_t temp_index;
- uint8_t temp_length;
- uint8_t temp_str[5] = {NULL,};
- //printf("first : %s\n", ptr); // den Diary
- if(strstr(ptr, "+IPD,0,30:") != NULL){
- temp_index= ESP8266_StrIndexSearch(ptr,":");
- if(temp_index == 0 || *(ptr + (temp_index + 1)) != 0xbe){
- return 0;
- }else{
- temp_str[0] = ptr[temp_index - 2];
- temp_str[1] = ptr[temp_index - 1];
-
- temp_length = atoi(temp_str);
- // temp_length += atoi(ptr[temp_index - 1]);
- // printf("(+IPD,0,)Length%d \r\n",ESP8266_StrLength("+IPD,0,"));
- // printf("Length Result : %d \r\n",temp_length);
- //if(ptr != NULL){
- printf("\r\n %d Result : ",ESP8266_StrLength(ptr));
- for(int i = (temp_index + 1); i < temp_length + (temp_index + 1) + 9; i++)
- printf("%d ", *(ptr + i)); // den Diary
- printf("\r\n");
- //}
- }
- }else{
- // for(int i = 0; i < ESP8266_StrLength(ptr); i++)
- // printf("%c",*(ptr+ i));
- printf("I am not found\r\n");
- }
- return 0;
- }
|