shuichan_old/V1.2/STM32F103_App1/HardWare/WIFI/esp8266.h

47 lines
2.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef ESP8266_H
#define ESP8266_H
#include "main.h"
#include <stdint.h>
/*===== 用户配置区 =====*/
/* 固定 WiFi 凭据:优先尝试连接的热点;连不上(60s)则进 Smart Config 智能配网 */
#define WIFI_SSID "TP_Link-01" /* TODO: 填入固定 WiFi 名称 */
#define WIFI_PASS "zxcvbnmm112" /* TODO: 填入固定 WiFi 密码 */
//#define WIFI_SSID "TP_Link" /* TODO: 填入固定 WiFi 名称 */
//#define WIFI_PASS "zxcvbnm888" /* TODO: 填入固定 WiFi 密码 */
/* 超时配置 */
#define WIFI_JOIN_TIMEOUT_S 40 /* 固定 WiFi 连接超时(秒) */
#define WIFI_SMART_TIMEOUT_S 60 /* Smart Config 配网超时(秒) */
#define WIFI_TCP_TIMEOUT_MS 10000 /* TCP 连接服务器超时 */
/* 波特率配置:模块出厂/RESTORE 后为 115200
* 初始化时探测并固定为 WIFI_BAUD_TARGETAT+UART_DEF 掉电保存),
* 提高吞吐(为 WiFi OTA 预留);切换失败自动维持 115200 */
#define WIFI_BAUD_DEFAULT 115200u
#define WIFI_BAUD_TARGET 921600u
/*===== ESP-01S 复位脚 (ESP_RST -> PA5) =====*/
#define ESP_RST_PIN GPIO_PIN_5
#define ESP_RST_PORT GPIOA
#define ESP_RST_LOW() HAL_GPIO_WritePin(ESP_RST_PORT, ESP_RST_PIN, GPIO_PIN_RESET)
#define ESP_RST_HIGH() HAL_GPIO_WritePin(ESP_RST_PORT, ESP_RST_PIN, GPIO_PIN_SET)
/*===== API =====*/
void esp_gpio_init(void); /* PA5 推挽输出初始化(默认拉高) */
int esp_reset(void); /* 硬件复位+波特率同步(->921600), 0=成功 */
int esp_send_cmd(const char *cmd, const char *expect, int timeout_ms); /* 发AT等关键字, 0=成功 */
int esp_join_fixed_ap(void); /* 连固定SSID(60s), 0=成功 */
int esp_wait_got_ip(int timeout_s); /* 等已存AP自动连接拿IP, 0=成功 */
int esp_smartconfig(void); /* ESP-Touch智能配网(60s), 0=成功 */
int esp_enter_transparent(const char *ip, uint16_t port); /* 连TCP并进透传, 0=成功 */
int esp_exit_transparent(void); /* "+++" 退透传+CIPCLOSE, 0=成功 */
int esp_factory_restore(void); /* AT+RESTORE 恢复出厂(忘掉已存AP), 0=成功 */
void esp_send(const uint8_t *data, uint16_t len); /* 透传模式原始数据发送 */
void esp_rx_clear(void); /* 清空共享接收缓冲 */
#endif /* ESP8266_H */