esp8266.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "esp8266.h"
  2. void esp_8266_task(void)
  3. {
  4. INT8U err = 0;
  5. UartFrame_TypeDef *msg;
  6. INT8U esp_state = 0;
  7. while (1) //等待倒计时
  8. {
  9. iwdg_feed(UART6_DOG);
  10. switch (esp_state)
  11. {
  12. case ESP_CWMODE:
  13. uart6_dma_send("AT+CWMODE=1\r\n", sizeof("AT+CWMODE=1\r\n"));
  14. OSTimeDly(1000);
  15. break;
  16. case ESP_RST:
  17. uart6_dma_send("AT+RST\r\n", sizeof("AT+RST\r\n"));
  18. OSTimeDly(1000);
  19. OSTimeDly(1000);
  20. OSTimeDly(1000);
  21. break;
  22. case ESP_CWJAP:
  23. uart6_dma_send("AT+CWJAP=\"FCC\",\"347470868\"\r\n", sizeof("AT+CWJAP=\"FCC\",\"347470868\"\r\n"));
  24. OSTimeDly(100);
  25. break;
  26. case ESP_MUX:
  27. uart6_dma_send("AT+CIPMUX=1\r\n", sizeof("AT+CIPMUX=1\r\n"));
  28. OSTimeDly(100);
  29. break;
  30. case ESP_SERVER:
  31. uart6_dma_send("AT+CIPSERVER=1,8086\r\n", sizeof("AT+CIPSERVER=1,8086\r\n"));
  32. OSTimeDly(100);
  33. break;
  34. case ESP_SEND_STATE:
  35. uart6_dma_send("AT+CIPSEND=0,25\r\n", sizeof("AT+CIPSEND=0,25\r\n"));
  36. OSTimeDly(200);
  37. break;
  38. case ESP_SEND_WORK:
  39. uart6_dma_send("dsadsadsadsadsadasds\r\n", sizeof("sadsadsadsadsadasds\r\n"));
  40. OSTimeDly(100);
  41. break;
  42. default:
  43. break;
  44. }
  45. msg = (UartFrame_TypeDef *)OSMboxPend(uart6_mbox, 500, &err);
  46. if ((err == OS_ERR_NONE) && (msg->len >= 0))
  47. {
  48. if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_CWMODE)
  49. {
  50. esp_state = ESP_RST;
  51. }
  52. else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_RST)
  53. {
  54. // printf(msg->buf);
  55. esp_state = ESP_CWJAP;
  56. }
  57. else if (strstr((const char *)msg, (const char *)"WIFI GOT IP") && esp_state == ESP_CWJAP)
  58. {
  59. printf(msg->buf);
  60. esp_state = ESP_MUX;
  61. }
  62. else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_MUX)
  63. {
  64. printf(msg->buf);
  65. esp_state = ESP_SERVER;
  66. }
  67. else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_SERVER)
  68. {
  69. printf(msg->buf);
  70. esp_state = ESP_SEND_STATE;
  71. }
  72. else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_SEND_STATE)
  73. {
  74. printf(msg->buf);
  75. esp_state = ESP_SEND_WORK;
  76. }
  77. else if (strstr((const char *)msg, (const char *)"OK") && esp_state == ESP_SEND_WORK)
  78. {
  79. printf(msg->buf);
  80. esp_state = ESP_SEND_STATE;
  81. }
  82. else
  83. {
  84. printf(msg->buf);
  85. // return;
  86. }
  87. }
  88. OSTimeDly(100);
  89. }
  90. }