1. Introduction to ESP8266
The ESP8266 module is a widely used single-chip WIFI communication module. The following mainly describes how to implement the communication of ESP8266 on STM32.
2. AT command core
initialization
//ESP初始化
SendATCmd("+++",500); //退出透传模式
SendATCmd("AT\r\n",500); //测试ESP01模块是否存在
SendATCmd("ATE0\r\n",500); //关闭模块回显
SendATCmd("AT+GMR\r\n",500); //查看模块版本信息
SendATCmd("AT+CWMODE=3\r\n",500); //开启STA+AP模式
SendATCmd("AT+CIPMUX=0\r\n",500); //关闭多连接
char str[200];
sprintf(str,"AT+CWJAP=\"%s\",\"%s\"\r\n","这里输入热点名称","这里输入热点密码"); //账号和密码的输入,建议使用2.4Ghz频段
SendATCmd(str,3000); //连接无线路由器或者手机热点,等待十秒
Every 10s, access XinzhiWeather through the API interface to obtain the json string of real-time weather
if(osKernelGetTickCount()>tick_for_weather)
{
tick_for_weather=osKernelGetTickCount()+10000;
SendATCmd("AT+CIPSTART=\"TCP\",\"api.seniverse.com\",80\r\n",2000);//连接心知天气TCP服务器
SendATCmd("AT+CIPMODE=1\r\n",500); //开启透传模式
SendATCmd("AT+CIPSEND\r\n",500); //开启透传
SendATCmd("GET https://api.seniverse.com/v3/weather/now.json?key=Srb4ras_BDB82jLDh&location=hangzhou&language=en&unit=c\r\n",3000);
SendATCmd("+++",500); //退出透传模式
}
3. Auxiliary function
void SendATCmd(char *cmd,int waitms) //发送AT指令给串口6
{
if(NULL!=cmd)
{
HAL_UART_Transmit(&huart6,(uint8_t*)cmd,strlen(cmd),0xFFFF);
if(waitms>0)
osDelay(waitms);//延时等待ESP01模块应答时间
}
}
Fourth, the effect map
If you don't understand, please leave a message.