国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【STM32】ESP8266 WiFi模塊實(shí)時(shí)上報(bào)溫濕度及控制LED燈項(xiàng)目筆記

這篇具有很好參考價(jià)值的文章主要介紹了【STM32】ESP8266 WiFi模塊實(shí)時(shí)上報(bào)溫濕度及控制LED燈項(xiàng)目筆記。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。


一、ESP8266模塊

1.模塊介紹

本項(xiàng)目無線通訊模塊使用的是WiFi模塊ESP8266,樂鑫公司推出的高性能、低功耗串口WiFi模塊ESP8266應(yīng)該是使用最廣泛的一種WIFI模塊之一了,它自身帶有高性能的MCU(Microcontroller Unit),因此它既可以通過串口連接為外部MCU提供 WiFi通信功能,也就是我們本項(xiàng)目所用到的功能;當(dāng)然它也可以讓用戶直接在模塊內(nèi)置的MCU上基于RTOS SDK進(jìn)行軟件編程,開發(fā)出具有低功耗、低成本的WiFi連接產(chǎn)品,如市面上大部分WiFi智能插座就用了ESP8266模塊和它的這一功能。

stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)

ESP8266內(nèi)置一個(gè)Tensilica(泰思立達(dá))Xtensa架構(gòu)的32位處理器L106,具有5級(jí)流水線(ARM CortexM3是3級(jí)流水線),最大時(shí)鐘速度為160MHz,可以使用高達(dá)16MB的外部SPI Flash。該模塊采用串口與MCU(或其他串口設(shè)備)通信,內(nèi)置 TCP/IP協(xié)議棧,能夠?qū)崿F(xiàn)串口與 WiFi之間的轉(zhuǎn)換。通過該模塊,傳統(tǒng)的串口設(shè)備只需要簡單的串口配置,即可通過WiFi傳輸自己的數(shù)據(jù)。

WiFi具有兩種功能模式:一種叫AP(Access Point)模式,一種叫Station模式。AP就是我們平時(shí)所說的熱點(diǎn),如無線路由器,開了熱點(diǎn)的手機(jī)等,這些AP設(shè)備可以允許其他設(shè)備(如手機(jī),PC等)輸入熱點(diǎn)名(SSID)和密碼(也可不設(shè)置密碼)后連接上網(wǎng);Station模式則是前面說的連接AP的設(shè)備(如手機(jī),PC等)。

ESP8266除支持上述兩種模式以外,還可以支持第三種模式:AP+Station,即:將AP和Station的功能合二為一,它主要是實(shí)現(xiàn)無線橋接的功能,該模式應(yīng)用的場景不多。

STM32單片機(jī)在與ESP8266進(jìn)行串口通信時(shí)采用AT命令進(jìn)行通信,這樣想要做ESP8266 WiFi模塊的程序開發(fā)的話,那我們首先得學(xué)習(xí)并熟練掌握ESP8266 WiFi模塊的AT指令。

2.AT指令介紹

AT指令是以AT作為開頭,\r\n字符結(jié)束的字符串,每個(gè)指令執(zhí)行成功與否都有相應(yīng)的返回。其他的一些非預(yù)期的信息(如有人撥號(hào)進(jìn)來、線路無信號(hào)等),模塊將有對(duì)應(yīng)的一些信息提示,接收端可做相應(yīng)的處理。

不同模塊的AT命令可能不一樣的,這要對(duì)著模塊的AT指令手冊(cè)來查看。

AT命令可分為四類:

類型 指令格式 描述
執(zhí)行指令 AT+ 該命令用于執(zhí)行受模塊內(nèi)部程序控制的變參數(shù)不可變的功能。
測試指令 AT+=? 該命令用于該命令用于查詢?cè)O(shè)置指令的參數(shù)以及取值范圍。
查詢指令 AT+? 該命令用于返回參數(shù)的當(dāng)前值。
設(shè)置指令 AT+=<···> 該命令用于設(shè)置用戶自定義的參數(shù)值。

2.硬件連接

由于我的開發(fā)板當(dāng)中3.3V電源是LDO電路從USB TypeC接口提供的5V降壓而來,電流較低,所以連ESP8266模塊可能會(huì)導(dǎo)致它不能正常工作,所以這里我連了5V做VCC,而我所用的ESP8266能夠正常工作,具體所用的時(shí)候可以視情況而定。
stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)
提示:USB3.0的接口電流較高,如果必要用5V,最好不用USB3.0

ESP8266模塊提供TTL串口通信接口,而我所使用的開發(fā)板上的擴(kuò)展UART2串口也是TTL電平,所以直接連接如下:
stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)
stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)

二、串口轉(zhuǎn)發(fā)及調(diào)試

1.串口轉(zhuǎn)發(fā)流程

開發(fā)板的USART2串口連接了ESP8266模塊,當(dāng)然我們要通過PC來對(duì)它進(jìn)行調(diào)試,所以我們需要STM32寫一個(gè)單片機(jī)上寫一個(gè)串口接收轉(zhuǎn)發(fā)的程序如下圖:
stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)

2.串口轉(zhuǎn)發(fā)程序?qū)崿F(xiàn)

STM32CubeMX配置

stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)

修改usart.h/.c文件

對(duì)usart.h文件做如下修改:

... ...
/* USER CODE BEGIN Private defines */
extern char g_uart1_rxbuf[256];
extern uint8_t g_uart1_bytes;


#define clear_uart1_rxbuf() do { memset(g_uart1_rxbuf, 0, sizeof(g_uart1_rxbuf)); \
		g_uart1_bytes=0; } while(0)

//在這里添加uar2接收 buffer相關(guān)變量聲明,并添加一個(gè)宏 clear_uart2_rxbuf()用來清除接收 buffer里的數(shù)據(jù)
extern char g_uart2_rxbuf[256];
extern uint8_t g_uart2_bytes;


#define clear_uart2_rxbuf() do { memset(g_uart2_rxbuf, 0, sizeof(g_uart2_rxbuf)); \
		g_uart2_bytes=0; } while(0)

//添加串口接收轉(zhuǎn)發(fā)函數(shù)的聲明
extern void uart_forward(void);

/* USER CODE END Private defines */
... ...

對(duì)usart.c文件做如下修改:

... ...
/* USER CODE BEGIN 0 */
static	uint8_t			s_uart1_rxch;
char					g_uart1_rxbuf[256];
uint8_t					g_uart1_bytes;

static	uint8_t			s_uart2_rxch;
char					g_uart2_rxbuf[256];
uint8_t					g_uart2_bytes;
/* USER CODE END 0 */
... ...

void MX_USART2_UART_Init(void)
{
... ...
  /* USER CODE BEGIN USART2_Init 2 */
  HAL_UART_Receive_IT(&huart2 , &s_uart2_rxch, 1);//HAL_UART_Receive_IT中斷服務(wù)處理程序
  /* USER CODE END USART2_Init 2 */

}
... ...

/* USER CODE BEGIN 1 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	if (huart->Instance == USART1)
	{
		if( g_uart1_bytes< sizeof(g_uart1_rxbuf) )
		{
			g_uart1_rxbuf[g_uart1_bytes++] = s_uart1_rxch;
		}
		HAL_UART_Receive_IT(&huart1 , &s_uart1_rxch, 1);
	}

	if (huart->Instance == USART2)
		{
			if( g_uart2_bytes< sizeof(g_uart2_rxbuf) )
			{
				g_uart2_rxbuf[g_uart2_bytes++] = s_uart2_rxch;
			}
			HAL_UART_Receive_IT(&huart2 , &s_uart2_rxch, 1);
		}
}

//添加usart1和usart2的收發(fā)轉(zhuǎn)發(fā)功能函數(shù),main()函數(shù)中調(diào)用
void uart_forward(void)
{
	if(strstr(g_uart1_rxbuf, "\r\n"))
	{
		HAL_UART_Transmit(&huart2, (uint8_t *)g_uart1_rxbuf, g_uart1_bytes,0xFF);
		clear_uart1_rxbuf();
	}

	if(g_uart2_bytes > 0)
	{
		HAL_Delay(100);/*Wait AT command reply receive over*/
		HAL_UART_Transmit(&huart1, (uint8_t *)g_uart2_rxbuf, g_uart2_bytes,0xFF);
		clear_uart2_rxbuf();
	}
}
... ...

/* USER CODE END 1 */

... ...

修改main.c文件

如下:

... ...
  while(1)
  {
	  uart_forward();//后面使用無線通訊時(shí)只需要用Socket通信,不在需要此轉(zhuǎn)發(fā)程序,如果沒有注釋掉會(huì)報(bào)錯(cuò),并不會(huì)執(zhí)行PC發(fā)的JOSN指令
#if 0
... ...
#endif
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
    }... ...
    

3.運(yùn)行測試

用串口調(diào)試工具進(jìn)行測試:
stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)

三、AT指令學(xué)習(xí)

每一個(gè)使用AT指令通信的模塊都有自己詳細(xì)的AT指令使用說明文檔,模塊里的軟件固件版本不一樣,其AT指令可能也不大一樣,可以通過你的模塊以及版本找到對(duì)應(yīng)的說明文檔對(duì)照。

對(duì)于我所使用的ESP8266 WiFi模塊:

1.WiFi初始化命令

AT命令 說明
AT AT命令用來確認(rèn)模塊是否正常工作以及串口通信是否正常
AT+GMR 獲取WiFi模塊的軟件固件版本信息
AT+RST 重啟、復(fù)位WiFi模塊
AT+CWMODE_CUR=1 設(shè)置ESP8266 WiFi模塊工作在Station模式
AT+CWDHCP_CUR=1,1 設(shè)置使能ESP8266 WiFi模塊Station模式的DHCP服務(wù)
AT+CIPSTA_CUR 靜態(tài)設(shè)置ESP8266的IP地址,子網(wǎng)掩碼和默認(rèn)網(wǎng)關(guān)

2.無線連接命令

AT命令 說明
AT+CWJAP_CUR=“Router_SSID” ,“Password” 該命令用來連接指定的無線路由器
AT+CIPSTA_CUR? 該命令用來查看ESP8266當(dāng)前的IP地址
AT+PING=“192.168.0.1” 該命令用來測試與目標(biāo)主機(jī)的連通性

3.數(shù)據(jù)收發(fā)命令

AT命令 說明
AT+CIPMUX=0 該命令用來禁用多個(gè)socket連接,一般只連接一個(gè)目標(biāo)服務(wù)器。
AT+CIPSTART=“TCP”,“192.168.0.100"”,12345 該命令用來連接指定的目標(biāo)socket 服務(wù)器
AT+CIPSEND=5 該命令用來發(fā)送5個(gè)字節(jié)的數(shù)據(jù),在收到模塊回應(yīng)的‘>’字符后,開始輸入要發(fā)送的數(shù)據(jù)內(nèi)容。
AT+CIPCLOSE 該命令用來斷開Socket連接

注意:指令帶_CUR后綴則表示只更改當(dāng)前系統(tǒng)配置,并不寫入Flash存儲(chǔ)器中,重啟復(fù)位后失效。而如果需要重啟后依然有效則用帶_DEF后綴的命令。

四、WiFi模塊實(shí)時(shí)上報(bào)溫濕度與遠(yuǎn)程控制LED燈實(shí)現(xiàn)

1.esp8266.h/.c

代碼如下:

/*
 * esp8266.h
 *
 *  Created on: 2023年2月26日
 *      Author: ASUS
 */

#ifndef INC_ESP8266_H_
#define INC_ESP8266_H_

#include <stdio.h>

#define wifi_huart			&huart2			/*wiFi模塊使用的串口*/
#define g_wifi_rxbuf		g_uart2_rxbuf	/*wiFi模塊的接收buffer */
#define g_wifi_rxbytes		g_uart2_bytes 	/*wiFi模塊接收的數(shù)據(jù)大小*/

/*清除WiFi模塊接收 buffer里的數(shù)據(jù)內(nèi)容宏,用宏不用函數(shù)是因?yàn)楹瘮?shù)調(diào)用需要額外時(shí)間開銷*/
#define clear_atcmd_buf()	do { memset(g_wifi_rxbuf, 0, sizeof(g_wifi_rxbuf));g_wifi_rxbytes=0; } while(0)

/*ESP8266 WiFi模塊發(fā)送AT命令函數(shù),返回值為О表示成功,!0表示失敗*/
#define EXPECT_OK	"OK\r\n"
extern int send_atcmd(char *atcmd, char *expect_reply, unsigned int timeout);

/*ESP8266 WiFi模塊初始化函數(shù)。返回值為0表示成功,!0表示失敗*/
extern int esp8266_module_init(void);

/*ESP8266 WiFi模塊復(fù)位重啟函數(shù)。返回值為О表示成功,!0表示失敗*/
extern int esp8266_module_reset(void);

/*ESP8266 WiFi模塊連接路由器函數(shù)。返回值為О表示成功,!0表示失敗*/
extern int esp8266_join_network( char *ssid,char *pwd) ;

/*ESP8266獲取自己的IP地址和網(wǎng)關(guān)IP地址。返回值為О表示成功,!O表示失敗*/
int esp8266_get_ipaddr(char *ipaddr, char *gateway, int ipaddr_size);

/*ESP8266 WiFi模塊做ping 命令測試網(wǎng)絡(luò)連通性。返回值為О表示成功,!0表示失敗*/
int esp8266_ping_test(char *host);

/*ESP8266 WiFi模塊建立TCP socket連接函數(shù)。返回值為О表示成功,!0表示失敗*/
extern int esp8266_sock_connect( char *servip, int port);

/* ESP8266 WiFi模塊斷開TCP socket連接函數(shù)。返回值為О表示成功,!0表示失敗*/
extern int esp8266_sock_disconnect(void);

/*ESP8266 WiFi通過 TCP Socket發(fā)送數(shù)據(jù)函數(shù)。返回值為0表示失敗,>0表示成功發(fā)送字節(jié)數(shù)*/
extern int esp8266_sock_send(unsigned char *data, int bytes);

/* ESP8266 WiFi通過TCP Socket 接收數(shù)據(jù)函數(shù)。返回值為0無數(shù)據(jù),>0表示接收到數(shù)據(jù)字節(jié)數(shù)*/
extern int esp8266_sock_recv(unsigned char *buf, int size);

#endif /* INC_ESP8266_H_ */

/*
 * esp8266.c
 *
 *  Created on: 2023年2月26日
 *      Author: ASUS
 */

#include <stdlib.h>
#include "usart.h"
#include "esp8266.h"

/*WiFi模塊驅(qū)動(dòng)調(diào)試宏,注釋下面兩個(gè)宏定義可以取消調(diào)試打印*/
//#define CONFIG_WIFI_DEBUG
#define CONFIG_WIFI_PRINT

#ifdef CONFIG_WIFI_DEBUG
#define wifi_dbg(format,args...) printf(format, ##args)
#else
#define wifi_dbg(format,args...) do{} while(0)
#endif

#ifdef CONFIG_WIFI_PRINT
#define wifi_print(format,args...) printf(format, ##args)
#else
#define wifi_print(format,args...) do{} while(0)
#endif

int send_atcmd(char *atcmd, char *expect_reply, unsigned int timeout)
{
	int				rv = 1;
	unsigned int	i;
	char			*expect;

	/*check function input arguments validation*/
	if( !atcmd || strlen(atcmd)<=0 )
	{
		wifi_print("ERROR:Invalid input arguments\r\n");
		return -1;
	}

	wifi_dbg("\r\nStart send AT command: %s",atcmd);
	clear_atcmd_buf();
	HAL_UART_Transmit(wifi_huart, (uint8_t *)atcmd, strlen(atcmd), 1000);

	expect = expect_reply ? expect_reply : "OK\r\n";

	/*Receive AT reply string by UART interrupt handler,stop by "OK/ERROR" or timeout*/
	for(i=0; i<timeout; i++)
	{
		if( strstr(g_wifi_rxbuf, expect))
		{
			wifi_dbg("AT command Got expect reply '%s'\r\n", expect);
			rv = 0;
			goto CleanUp;
		}
		if( strstr(g_wifi_rxbuf, "ERROR\r\n") || strstr(g_wifi_rxbuf, "FAIL\r\n"))
		{
			rv = 2;
			goto CleanUp;
		}

		HAL_Delay(1);
	}


CleanUp:
	wifi_dbg("<<<< AT command reply:\r\n%s", g_wifi_rxbuf);
	return rv;

}

int atcmd_send_data(unsigned char *data, int bytes, unsigned int timeout)
{
	int				rv = -1;
	unsigned int	i;

	/* check function input arguments validation */
	if( !data || bytes <= 0 )
	{
		wifi_print("ERROR: Invalid input arguments\r\n");
		return -1;
	}

	wifi_dbg("\r\nStart AT command send [%d] bytes data\n", bytes);
	clear_atcmd_buf();
	HAL_UART_Transmit(wifi_huart, data, bytes, 1000);

	/*Receive AT reply string by UART interrupt handler,stop by "OK/ERROR" or timeout */
	for(i=0; i<timeout; i++)
	{
		if(strstr(g_wifi_rxbuf, "SEND OK\r\n"))
		{
			rv = 0;
			goto CleanUp;
		}
		if(strstr(g_wifi_rxbuf, "ERROR\r\n"))
		{
			rv = 1;
			goto CleanUp;
		}

		HAL_Delay(1);
	}


CleanUp:
	wifi_dbg("<<<< AT command reply:\r\n%s", g_wifi_rxbuf);
	return rv;
}

int esp8266_module_init(void)
{
	int		i;

	wifi_print("INFO: Reset ESP8266 module now...\r\n");
	send_atcmd("AT+RST\r\n", EXPECT_OK, 500);

	for(i=0; i<6; i++)
	{
		if( !send_atcmd("AT\r\n", EXPECT_OK, 500) )
		{
			wifi_print("INFO: Send AT to ESP8266 and got reply ok \r\n");
			break;
		}

		HAL_Delay(100);
	}

	if( i>= 6 )
	{
		wifi_print("ERROR: Can't receive AT replay after reset\r\n");
		return -2;
	}

	if( send_atcmd( "AT+CWMODE=1\r\n", EXPECT_OK, 500) )
	{
		wifi_print("ERROR : Set ESP8266 work as station mode failure\r\n");
		return -3;
	}

	if( send_atcmd("AT+CWDHCP=1,1\r\n", EXPECT_OK, 500) )
	{
		wifi_print("ERROR: Enable ESP8266 Station mode DHCP failure\r\n");
		return -4;
	}

#if 0
	if( send_atcmd( "AT+GMR\r\n",EXPECT_OK,500))
	{
		wifi_print("ERROR: AT+GMR check ESP8266 reversion failure\r\n");
		return -5;
	}
#endif
	HAL_Delay(500);
	return 0;
}


int esp8266_join_network(char *ssid, char *pwd)
{
	char			atcmd[128] = {0x00};
	int				i;

	if( !ssid || !pwd )
	{
		wifi_print( "ERROR:Invalid input arguments\r\n");
		return -1;
	}

	snprintf(atcmd, sizeof(atcmd), "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
	if( send_atcmd(atcmd, "CONNECTED", 10000) )
	{
		wifi_print("ERROR: ESP8266 connect to '%s' failure\r\n", ssid);
		return -2 ;
	}
	wifi_print("INFO: ESP8266 connect to '%s' ok\r\n", ssid);

	/*check got IP address or not by netmask (255.)*/
	for(i=0; i<10; i++)
	{
		if( !send_atcmd( "AT+CIPSTA_CUR?\r\n", "255.", 1000))
		{
			wifi_print( "INFO: ESP8266 got Ip address ok\r\n" );
			return 0;
		}

		HAL_Delay(300);
	}

	wifi_print("ERROR: ESP8266 assigned IP address failure\r\n");
	return -3;
}

/*
+CIPSTA_CUR:ip: "192.168.0.120"
+CIPSTA_CUR:gateway: "192.168.0.1"
*/
static int util_parser_ipaddr(char *buf, char *key, char *ipaddr, int size)
{
	char		*start;
	char		*end;
	int			len;

	if(!buf || !key || !ipaddr)
	{
		return -1;
	}
	/*find the key string */
	start = strstr(buf, key);
	if( !start )
	{
		return -2;
	}

	start+=strlen(key) + 1;/*Skip ”*/
	end = strchr(start,'"');/*find last " */
	if( !end )
	{
		return -3;
	}

	len = end - start;
	len = len>size ? size : len;

	memset(ipaddr, 0, size);
	strncpy(ipaddr, start, len);

	return 0;
}

int esp8266_get_ipaddr(char *ipaddr, char *gateway, int ipaddr_size)
{
	if( !ipaddr || !gateway || ipaddr_size<7 )
	{
		wifi_print("ERROR: Invalid input arguments\r\n");
		return -1;
	}

	if( send_atcmd( "AT+CIPSTA_CUR?\r\n", "255.", 1000) )
	{
		wifi_print("ERROR: ESP8266 AT+CIPSTA_CUR? command failure\r\n");
		return -2;
	}

	if( util_parser_ipaddr(g_wifi_rxbuf, "ip:", ipaddr, ipaddr_size) )
	{
		wifi_print("ERROR: ESP8266 AT+CIPSTA_CUR? parser IP address failure\r\n");
		return -3;
	}

	if( util_parser_ipaddr(g_wifi_rxbuf, "gateway:", gateway, ipaddr_size))
	{
		wifi_print("ERROR: ESP8266 AT+CIPSTA_CUR? parser gateway failure\r\n");
		return -4;
	}

	wifi_print("INFO: ESP8266 got IP address[%s] gateway[%s] ok\r\n", ipaddr, gateway);
	return 0;
}

int esp8266_ping_test(char *host)
{
	char			atcmd[128]={0x00};

	if(!host)
	{
		wifi_print( "ERROR: Invalid input arguments\r\n" );
		return -1;
	}

	snprintf(atcmd, sizeof(atcmd), "AT+PING=\"%s\"\r\n", host);
	if( send_atcmd( atcmd, EXPECT_OK, 3000) )
	{
		wifi_print("ERROR: ESP8266 ping test [%s ] failure\rin", host);
		return -2;
	}

	wifi_print("INFO: ESP8266 ping test [%s ] ok\r\n", host);
	return 0;
}

int esp8266_sock_connect(char *servip, int port)
{
	char			atcmd[128] = {0x00};

	if( !servip || port<=0 )
	{
		wifi_print("ERROR: Invalid input arguments\rin");
		return -1;
	}

	send_atcmd ( "AT+CIPMUX=0\r\n", EXPECT_OK, 1500);

	snprintf(atcmd, sizeof(atcmd), "AT+CIPSTART=\"TCP\",\"%s\",%d\r\n", servip, port);
	if(send_atcmd(atcmd,"CONNECT\r\n", 1000) )
	{
		wifi_print("ERROR: ESP8266 socket connect to [%s:%d] failure\r\n", servip, port);
		return -2;
	}

	wifi_print("INFO: ESP8266 socket connect to [%s:%d] ok\r\n", servip, port);
	return 0;
}

int esp8266_sock_disconnect(void)
{
	send_atcmd("AT+CIPCLOSE\r\n", EXPECT_OK, 1500);
	return 0;
}

int esp8266_sock_send(unsigned char *data, int bytes)
{
	char			atcmd[128] = {0x00};

	if( !data || bytes<=0)
	{
		wifi_print("ERROR: Invalid input arguments\r\n");
		return -1;
	}

	snprintf(atcmd, sizeof(atcmd),  "AT+CIPSEND=%d\r\n", bytes);
	if( send_atcmd(atcmd, ">", 500))
	{
		wifi_print("ERROR: AT+CIPSEND command failure\rin");
		return 0;
	}

	if( atcmd_send_data((unsigned char *)data, bytes, 1000))
	{
		wifi_print("ERROR: AT+CIPSEND send data failure\r\n");
		return 0;
	}

	return bytes;
}

int esp8266_sock_recv( unsigned char *buf, int size)
{
	char			*data = NULL;
	char			*ptr = NULL;

	int				len;
	int				rv;
	int				bytes;

	if( !buf || size <= 0)
	{
		wifi_print("ERROR: Invalid input arguments\r\n");
		return -1;
	}

	if( g_wifi_rxbytes <= 0 )
	{
		return 0;
	}

	/*No data arrive or not integrated */
	if( !(ptr=strstr(g_wifi_rxbuf, "+IPD,")) || !(data=strstr( ptr, ":")) )
	{
		return 0;
	}

	data++;
	bytes = atoi(ptr+strlen("+IPD,"));

	len = g_wifi_rxbytes - (data-g_uart2_rxbuf);

	if( len < bytes )
	{
		wifi_dbg("+IPD data not receive over, receive again later ...\r\n");
		return 0;
	}

	memset(buf, 0, size);
	rv = bytes>size ? size : bytes;
	memcpy(buf, data, rv);

	clear_atcmd_buf();

	return rv;
}




2.main.c

代碼如下:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2022 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <string.h>
#include <stdio.h>
#include "dht11.h"
#include "sht30.h"
#include "core_json.h"
#include "oled.h"
#include "esp8266.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
#define FLAG_WIFI_CONNECTED		(1<<0)	/* WiFi連接路由器標(biāo)志位*/
#define FLAG_SOCK_CONNECTED 	(1<<1)  /* Socket連接服務(wù)器標(biāo)志位*/
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
static int report_tempRH_json(void);
static int parser_led_json(char *json_string, int bytes);
static void proc_uart1_recv(void);
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

//  uint32_t		lux,noisy;
//  uint32_t		start = 0;
//  uint32_t		light_status = 0;
//  float temperature, humidity;

	uint32_t		last_time = 0; /*每隔3s上報(bào)一次,上一次上報(bào)的時(shí)間*/
	unsigned char	buf[256]; /*WiFi模塊socket接收的buffer */
	int				rv;

	char			ipaddr[16];
	char			gateway[16];
	unsigned char	wifi_flag = 0;

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM6_Init();
  MX_USART1_UART_Init();
  MX_ADC1_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  //sysled_hearbeat();
  //beep_start(3,300);
  printf("Start BearKE1 5G NB_IoT Board Example Program v1.0\r\n");
  printf("Welcome Mr.deng!\r\n");

  OLED_Init();
  OLED_ShowBanner(TIME_1S*2);

  esp8266_module_init();

  while(1)
  {
	  /*wiFi沒有連接上無線路由器的話,開始連接無線路由器并ping測試*/
	  if(!(wifi_flag&FLAG_WIFI_CONNECTED))
	  {
		  if(esp8266_join_network("SSID", "password"))//填寫自己的WiFi信息
		  {
			  esp8266_module_init();
			  HAL_Delay(2000);
			  continue;
		  }
		  if(esp8266_get_ipaddr(ipaddr, gateway, sizeof(ipaddr)))
		  {
			  HAL_Delay(1000);
			  continue;
		  }
		  if(esp8266_ping_test(gateway))
		  {
			  HAL_Delay(1000);
			  continue;
		  }
		  wifi_flag |= FLAG_WIFI_CONNECTED; /* set wifi connected flag */
	  }

	  /*網(wǎng)絡(luò)socket沒有連接上Socket服務(wù)器的話就開始連接Socket服務(wù)器 */
	  if(!(wifi_flag&FLAG_SOCK_CONNECTED))
	  {
		  if(esp8266_sock_connect("192.168.0.120", 12345))//修改為自己對(duì)應(yīng)的IP與端口
		  {
			  HAL_Delay(1000);
			  continue;
		  }
		  wifi_flag |= FLAG_SOCK_CONNECTED; /* set wifi connected flag */
	  }
	  /*接收并且打印Socket服務(wù)器發(fā)送過來的數(shù)據(jù)*/
//	  rv = esp8266_sock_recv(buf, sizeof(buf));
//	  printf(("%d\n"), rv);
	  if( (rv=esp8266_sock_recv(buf, sizeof(buf))) > 0 )
	  {
		  parser_led_json((char *)buf, rv);
		  printf("ESP8266 socket receive %d bytes data: %s\n", rv, buf);
	  }


	  /*定時(shí)發(fā)數(shù)據(jù)到Socket服務(wù)器*/
	  if(time_after(HAL_GetTick(), last_time+3000))
	  {
		  rv = report_tempRH_json();
		  if( rv == 0 )
		  {
			  printf("ESP8266 socket send message ok\n");
		  }
		  else
		  {
			  printf("ESP8266 socket send message failure, rv=%d\n", rv);
			  wifi_flag &= ~FLAG_SOCK_CONNECTED;/* clear socket connected flag */

			  if(esp8266_ping_test(gateway))
			  {
				  wifi_flag &= ~FLAG_WIFI_CONNECTED;/* clear wifi connected flag */
			  }
		  }

		  last_time = HAL_GetTick();/*update last report time */
	  }
//	  uart_forward();//后面使用無線通訊時(shí)只需要用Socket通信,不在需要此轉(zhuǎn)發(fā)程序,如果沒有注釋掉會(huì)報(bào)錯(cuò),并不會(huì)執(zhí)行PC發(fā)的JOSN指令
#if 0
	  /*sht30*/
	  report_tempRH_json();
	  HAL_Delay(3000);

	  /*json上報(bào)*/
	  proc_uart1_recv();
	  if( report_tempRH_json() < 0 )
	  {
		  printf("ERROR: UART report temperature and relative humidity failure\r\n");
	  }
	  HAL_Delay(3000);

//	  if( DHT11_SampleData(&temperature, &humidity) < 0 )
//	  {
//		  printf("ERROR: DHT11 Sample Data failure\r\n");
//	  }
//	  else
//	  {
//		  printf("DHT11 Sample Temperature: %.3f Relative Humidity: %.3f\r\n", temperature, humidity);
//	  }
//
//
//	  HAL_Delay(1000);

//Tag:燈光
//	if( OFF == light_status )
//	{
//		adc_sample_lux_noisy(&lux, &noisy);
//		printf("Lux[%lu] Noisy[%lu]\r\n", lux, noisy);
//		if( lux<400 && noisy>800 )
//		{
//			printf("Turn Light on\r\n");
//			turn_relay(Relay2,ON);
//			turn_led(GreenLed,ON);//還得寫turn_Led()
//			light_status = ON;
//
//			start = HAL_GetTick();
//		}
			HAL_Delay(5000);
//	}
//
//	else
//	{
//		if( time_after(HAL_GetTick(), start+15000) )
//		{
//			printf("Turn Light off\r\n");
//			turn_relay(Relay2,OFF);
//			turn_led(GreenLed,OFF);
//			turn_led(RedLed,ON);
//
//			HAL_Delay(1000);
//			turn_led(RedLed,OFF);
//
//			light_status = OFF;
//		}
//
//	}
//
//	HAL_Delay(10);
#endif
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 1;
  RCC_OscInitStruct.PLL.PLLN = 20;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  {
    Error_Handler();
  }
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2
                              |RCC_PERIPHCLK_ADC;
  PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
  PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE;
  PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
  PeriphClkInit.PLLSAI1.PLLSAI1N = 9;
  PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
  PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
  PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV6;
  PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_ADC1CLK;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure the main internal regulator output voltage
  */
  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */
int parser_led_json(char *json_string, int bytes)
{
	JSONStatus_t result;
	char save;
	char *value;
	size_t valen;
	int i;

	printf("DBUG: Start parser JSON string: %s\r\n", json_string);
	result = JSON_Validate(json_string, bytes);
	/* JSON document is valid so far but incomplete */
	if( JSONPartial == result )
	{
		printf("WARN: JSON document is valid so far but incomplete!\r\n");
		return 0;
	}

	/* JSON document is not valid JSON */
	if( JSONSuccess != result )
	{
		printf("ERROR: JSON document is not valid JSON!\r\n");
		return -1;
	}
	/* Parser and set LED status */
	for(i=0; i<LedMax; i++)
	{
		result = JSON_Search( json_string, bytes, leds[i].name, strlen(leds[i].name), &value, &valen);
		if( JSONSuccess == result )
		{
			save = value[valen];
			value[valen] = '\0';

			if( !strncasecmp(value, "on", 2) )
			{
				printf("DBUG: turn %s on\r\n", leds[i].name);
				turn_led(i, ON);
			}
			else if( !strncasecmp(value, "off", 3) )
			{
				printf("DBUG: turn %s off\r\n", leds[i].name);
				turn_led(i, OFF);
			}

			value[valen] = save;
		}
	}
	return 1;
}

void proc_uart1_recv(void)
{
	if( g_uart1_bytes > 0 )
	{
		HAL_Delay(200);
		if( 0 != parser_led_json(g_uart1_rxbuf, g_uart1_bytes) )
		{
			clear_uart1_rxbuf();
		}
	}
}

/*json上報(bào)*/
//int report_tempRH_json(void)
//{
//	char buf[128];
//	float temperature, humidity;
//
//
//	if ( DHT11_SampleData(&temperature, &humidity) < 0 )
//	{
//		printf("ERROR: DHT11 Sample data failure\n");
//		return -1;
//	}
//
//
//	memset(buf, 0, sizeof(buf));
//	snprintf(buf, sizeof(buf), "{\"Temperature\":\"%.2f\", \"Humidity\":\"%.2f\"}", temperature, humidity);
//
//	HAL_UART_Transmit(&huart1 , (uint8_t *)buf, strlen(buf), 0xFFFF);
//
//	return 0;
//}

/*sht30采樣*/
int report_tempRH_json(void)
{
	char buf[128];
	float temperature, humidity;
	uint32_t temp, humd;
	int	rv;

	if ( SHT30_SampleData(&temperature, &humidity) < 0 )
	{
		printf("ERROR: SHT30 Sample data failure\n");
		return -1;
	}


	memset(buf, 0, sizeof(buf));
	snprintf(buf, sizeof(buf), "{\"Temperature\":\"%.2f\", \"Humidity\":\"%.2f\"}", temperature, humidity);

	temp = (int)(temperature*100);
	humd = (int)(humidity*100);
	OLED_ShowTempHumdity(temp, humd, TIME_1S*2);

	rv = esp8266_sock_send((uint8_t *)buf, strlen(buf));
//	HAL_UART_Transmit(&huart1 , (uint8_t *)buf, strlen(buf), 0xFFFF);

	return rv>0 ? 0 : -2;
}
/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

注意:需要注釋掉轉(zhuǎn)發(fā)程序,不然無法控制Led燈

3.運(yùn)行測試

stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)
stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)

stm32溫濕度檢測 wifi遠(yuǎn)程通信,網(wǎng)絡(luò)Socket,STM32,stm32,單片機(jī),嵌入式硬件,網(wǎng)絡(luò)


總結(jié)

首先,對(duì)于STM32單片機(jī)在寫博客之前學(xué)習(xí)了,所以沒有,之后可能也會(huì)對(duì)之前的內(nèi)容整理為博客,包括Led、DHT11、SHT30、I2C協(xié)議、SPI協(xié)議及JSON格式遠(yuǎn)程控制等,所以之前內(nèi)容并未包括在此篇當(dāng)中。

本篇為ESP8266 WiFi模塊實(shí)時(shí)上報(bào)溫濕度及控制LED燈項(xiàng)目筆記,主要介紹和應(yīng)用了ESP8266 WiFi模塊,編寫了串口轉(zhuǎn)發(fā)程序,學(xué)習(xí)了AT命令等,最終實(shí)現(xiàn)了ESP8266 WiFi模塊實(shí)時(shí)上報(bào)溫濕度及控制LED燈項(xiàng)目。

別忘了點(diǎn)贊 關(guān)注 收藏呀!文章來源地址http://www.zghlxwxcb.cn/news/detail-811587.html

到了這里,關(guān)于【STM32】ESP8266 WiFi模塊實(shí)時(shí)上報(bào)溫濕度及控制LED燈項(xiàng)目筆記的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • STM32+ESP8266上傳溫濕度到onenet(HTTP)新手易懂指南

    STM32+ESP8266上傳溫濕度到onenet(HTTP)新手易懂指南

    哎,上云很簡單的,但是我花了好幾天因?yàn)楦鞣N莫名其妙的錯(cuò)誤耽誤了大量時(shí)間。所有很有必要總結(jié)一下 咳咳。但是我也比新手好不了多少, 以免誤導(dǎo)新人,只教操作,理由核心不闡述,自己csdn找。 一、首先創(chuàng)建個(gè)HTTP協(xié)議onenet云平臺(tái)(不會(huì),就csdn里找,一堆堆) 對(duì)于初學(xué)

    2024年02月05日
    瀏覽(24)
  • STM32+ESP8266+QT客戶端上位機(jī)顯示DHT11溫濕度與點(diǎn)燈

    STM32+ESP8266+QT客戶端上位機(jī)顯示DHT11溫濕度與點(diǎn)燈

    目錄 1、簡介 2、硬件連接 3、上位機(jī)源碼 3.1?widget.h 3.2?widget.c? 3.3?顯示圖 ?4、下位機(jī)源碼 4.1 cubemax配置 ?4.2 keil源碼 本文使用STM32F103C8T6單片機(jī)使用單片機(jī)通過ESP8266WIFI模塊與QT設(shè)計(jì)的上位機(jī)進(jìn)行通訊,ESP8266設(shè)置AP模式。實(shí)現(xiàn)DHT11傳感器溫濕度的顯示與遠(yuǎn)程控制LED小燈的亮滅

    2024年02月06日
    瀏覽(67)
  • STM32+ESP8266+APP連接阿里云監(jiān)測環(huán)境溫濕度系列筆記1:阿里云物聯(lián)網(wǎng)平臺(tái)配置及數(shù)據(jù)上傳

    STM32+ESP8266+APP連接阿里云監(jiān)測環(huán)境溫濕度系列筆記1:阿里云物聯(lián)網(wǎng)平臺(tái)配置及數(shù)據(jù)上傳

    ????????在數(shù)據(jù)傳遞過程中阿里云物聯(lián)網(wǎng)平臺(tái)相當(dāng)于服務(wù)器,ESP8266為客戶端,通過路由器連接服務(wù)器時(shí)需要在物聯(lián)網(wǎng)平臺(tái)創(chuàng)建設(shè)備,具體過程如下: 1. 首先 在物聯(lián)網(wǎng)平臺(tái)創(chuàng)建公共實(shí)例,并點(diǎn)擊進(jìn)入, 圖1 2.可見設(shè)備接入物聯(lián)網(wǎng)平臺(tái)的整體流程如圖2中紅色方框所示, 接下

    2024年02月04日
    瀏覽(34)
  • STM32---WIFI模塊ESP8266

    STM32---WIFI模塊ESP8266

    模塊連接時(shí)基于串口方式連接,其模塊與電腦(服務(wù)器)之間數(shù)據(jù)的發(fā)送與接收也是基于串口。 mode=1 :Station模式(連接到WIFI) mode=2:AP模式(自己作為WIFI源供其他連接) mode=3:AP+Station模式(以上兩者模式的合并) 透傳模式就是單片機(jī)通過串口形式與模塊連接,而模塊與上位

    2024年02月03日
    瀏覽(26)
  • STM32-連接wifi模塊(esp8266)

    STM32-連接wifi模塊(esp8266)

    目錄 1. ESP8266模塊介紹 1.1. 系統(tǒng)結(jié)構(gòu)圖 1.2. 功能介紹 ?1.3. AT指令說明 ?2. STM32連接ESP8266 3. ESP8266示例 3.1. ESP8266透傳模式 ?3.2. ESP8266上傳數(shù)據(jù)例程 樂鑫智能互聯(lián)平臺(tái)——ESP8266 擁有高性能無線 SOC,是一個(gè)完整且自成體系的 WiFi 網(wǎng)絡(luò)解決方案,能夠獨(dú)立運(yùn)行,也可以作為 slave 搭

    2024年01月16日
    瀏覽(39)
  • 【STM32訓(xùn)練—WiFi模塊】第二篇、STM32驅(qū)動(dòng)ESP8266WiFi模塊獲取天氣

    【STM32訓(xùn)練—WiFi模塊】第二篇、STM32驅(qū)動(dòng)ESP8266WiFi模塊獲取天氣

    目錄 第一部分、前言 1、獲取心知天氣API接口 2、硬件準(zhǔn)備 第二部分、電腦串口助手調(diào)試WIFI模塊獲取天氣 1、ESP8266獲取天氣的流程 2、具體步驟 第三部分、STM32驅(qū)動(dòng)ESP8266模塊獲取天氣數(shù)據(jù) 1、天氣數(shù)據(jù)的解析 1.1、什么函數(shù)來解析天氣數(shù)據(jù)? 2.1、解析后的數(shù)據(jù)如何使用? ?2、

    2024年02月09日
    瀏覽(22)
  • 基于stm32 ESP8266WiFi模塊的基本通信

    基于stm32 ESP8266WiFi模塊的基本通信

    本篇涉及到的模塊與工具為: 1. ATK-ESP8266wifi模塊 2. USB-UART模塊 3. 串口調(diào)試助手 提取鏈接:https://pan.baidu.com/s/17xRlpnjp8j-VvyD2VDxNXw?pwd=ufms 提取碼:ufms 4. 網(wǎng)絡(luò)調(diào)試助手 提取鏈接:https://pan.baidu.com/s/10spxZmwMGI70USlzkOzdxg?pwd=fmxe 提取碼:fmxe 程序源碼提取連接放置文章底部,需者自提

    2024年02月02日
    瀏覽(29)
  • stm32 的 ESP8266 wifi 模塊 (ESP - 12s) 的使用

    stm32 的 ESP8266 wifi 模塊 (ESP - 12s) 的使用

    1. ESP8266 的器件介紹 2. ESP2866外設(shè)? 的引腳? 3. 我所用的的ESP2866 的引腳圖 4. 代碼 編程的串口 5.wifi 的指令 1.?AT? ? ?測試指令 2.?AT+RST? ?重啟模塊 3.?AT+GMR??查看版本信息 4.?AT+RESTORE???恢復(fù)出廠設(shè)置 5.??AT+UART=115200,8,1,0,0? ?串口設(shè)置? 串口號(hào), 數(shù)據(jù)位, 停止位,? 6.?

    2024年02月02日
    瀏覽(27)
  • 猿創(chuàng)征文 | 【STM32】ESP8266 wifi模塊創(chuàng)建阿里云產(chǎn)品

    猿創(chuàng)征文 | 【STM32】ESP8266 wifi模塊創(chuàng)建阿里云產(chǎn)品

    ??博客主頁:@丘比特懲罰陸 ??歡迎關(guān)注:點(diǎn)贊收藏?留言? ??系列專欄:嵌入式、web前端、筆記專欄 ?? 加入社區(qū): 灌水樂園 ??人生格言:選對(duì)方向,每走一步都是進(jìn)步! ??歡迎大佬指正,一起學(xué)習(xí)!一起加油! ?? 希望大家能小手一動(dòng),幫忙點(diǎn)個(gè)贊! ??資源郵箱

    2023年04月18日
    瀏覽(20)
  • STM32--ESP8266物聯(lián)網(wǎng)WIFI模塊(貝殼物聯(lián))--遠(yuǎn)程無線控制點(diǎn)燈

    STM32--ESP8266物聯(lián)網(wǎng)WIFI模塊(貝殼物聯(lián))--遠(yuǎn)程無線控制點(diǎn)燈

    本文適用于STM32F103C8T6等MCU,其他MCU可以移植,完整資源見文末鏈接 一、簡介 隨著移動(dòng)物聯(lián)網(wǎng)的發(fā)展,各場景下對(duì)于物聯(lián)控制、數(shù)據(jù)上傳、遠(yuǎn)程控制的訴求也越來越多,基于此樂鑫科技推出了便宜好用性價(jià)比極高的wifi物聯(lián)模塊——ESP8266,話不多少我們先來看看這個(gè)神奇的模

    2024年02月08日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包