ESP8266WFI模块介绍 远程无线传输

⭐概述

        ESP8266 WiFi模块是一款低成本、高集成度的无线网络解决方案,广泛应用于物联网(IoT)项目中。其核心是基于Tensilica L106超低功耗32位微控制器,具有强大的处理能力和节能特性。ESP8266支持IEEE 802.11 b/g/n无线标准,能够通过WiFi协议实现无线通信。该模块内置TCP/IP协议栈,支持UDP、TCP等网络协议,允许设备通过WiFi连接到互联网或本地网络。

        ESP8266具备多种功能,如WiFi接入点(AP)模式、站点(STA)模式和混合模式,能够根据需求灵活组网。用户可以通过AT指令集或直接编程,控制模块进行网络连接、数据传输和无线通信。其广泛用于智能家居、工业控制、远程监控等领域,凭借其低功耗、高性价比和强大的网络功能,成为物联网设备中的关键组件。通过简单的串行接口(UART)与微控制器通信,ESP8266模块提供了一种便捷、高效的无线联网方式。

⭐实物图

⭐模块代码

#include <stdio.h>
#include <string.h>
//#include "hal_key.h"
#include "gizwits_product.h"
#include "common.h"

static uint32_t timerMsCount;
uint8_t aRxBuffer;

/** User area the current device state structure*/
dataPoint_t currentDataPoint;

//extern TIM_HandleTypeDef htim2;
//extern UART_HandleTypeDef huart1;
//extern UART_HandleTypeDef huart2;

/**@} */
/**@name Gizwits User Interface
* @{
*/

/**
* @brief Event handling interface

* Description:

* 1. Users can customize the changes in WiFi module status

* 2. Users can add data points in the function of event processing logic, such as calling the relevant hardware peripherals operating interface

* @param [in] info: event queue
* @param [in] data: protocol data
* @param [in] len: protocol data length
* @return NULL
* @ref gizwits_protocol.h
*/
int8_t gizwitsEventProcess(eventInfo_t *info, uint8_t *gizdata, uint32_t len)
{
    uint8_t i = 0;
    dataPoint_t *dataPointPtr = (dataPoint_t *)gizdata;
    moduleStatusInfo_t *wifiData = (moduleStatusInfo_t *)gizdata;
    protocolTime_t *ptime = (protocolTime_t *)gizdata;
    
#if MODULE_TYPE
    gprsInfo_t *gprsInfoData = (gprsInfo_t *)gizdata;
#else
    moduleInfo_t *ptModuleInfo = (moduleInfo_t *)gizdata;
#endif

    if((NULL == info) || (NULL == gizdata))
    {
        return -1;
    }

    for(i=0; i<info->num; i++)
    {
        switch(info->event[i])
        {




        case WIFI_SOFTAP:
            break;
        case WIFI_AIRLINK:
            break;
        case WIFI_STATION:
            break;
        case WIFI_CON_ROUTER:
 
            break;
        case WIFI_DISCON_ROUTER:
 
            break;
        case WIFI_CON_M2M:
 
            break;
        case WIFI_DISCON_M2M:
            break;
        case WIFI_RSSI:
            GIZWITS_LOG("RSSI %d\n", wifiData->rssi);
            break;
        case TRANSPARENT_DATA:
            GIZWITS_LOG("TRANSPARENT_DATA \n");
            //user handle , Fetch data from [data] , size is [len]
            break;
        case WIFI_NTP:
            GIZWITS_LOG("WIFI_NTP : [%d-%d-%d %02d:%02d:%02d][%d] \n",ptime->year,ptime->month,ptime->day,ptime->hour,ptime->minute,ptime->second,ptime->ntp);
            break;
        case MODULE_INFO:
            GIZWITS_LOG("MODULE INFO ...\n");
#if MODULE_TYPE
            GIZWITS_LOG("GPRS MODULE ...\n");
            //Format By gprsInfo_t
            GIZWITS_LOG("moduleType : [%d] \n",gprsInfoData->Type);
#else
            GIZWITS_LOG("WIF MODULE ...\n");
            //Format By moduleInfo_t
            GIZWITS_LOG("moduleType : [%d] \n",ptModuleInfo->moduleType);
#endif
        break;
        default:
            break;
        }
    }

    return 0;
}

/**
* User data acquisition

* Here users need to achieve in addition to data points other than the collection of data collection, can be self-defined acquisition frequency and design data filtering algorithm

* @param none
* @return none
*/
void userHandle(u16 temperature,u16 smoke,u16 air_quality)
{
 
    currentDataPoint.valueTEMP = temperature;//Add Sensor Data Collection
    currentDataPoint.valueSMOKE = smoke;//Add Sensor Data Collection
    currentDataPoint.valueKERAN = air_quality;//Add Sensor Data Collection
    //currentDataPoint.valueBAOJING = ;//Add Sensor Data Collection

    
    
}

/**
* Data point initialization function

* In the function to complete the initial user-related data
* @param none
* @return none
* @note The developer can add a data point state initialization value within this function
*/
void userInit(void)
{
    memset((uint8_t*)&currentDataPoint, 0, sizeof(dataPoint_t));
    
    /** Warning !!! DataPoint Variables Init , Must Within The Data Range **/ 
    /*
    currentDataPoint.valueTEMP = ;
    currentDataPoint.valueSMOKE = ;
    currentDataPoint.valueKERAN = ;
    currentDataPoint.valueBAOJING = ;
    */

}


/**
* @brief Millisecond timing maintenance function, milliseconds increment, overflow to zero

* @param none
* @return none
*/
void gizTimerMs(void)
{
    timerMsCount++;
}

/**
* @brief Read millisecond count

* @param none
* @return millisecond count
*/
uint32_t gizGetTimerCount(void)
{
    return timerMsCount;
}

/**
* @brief MCU reset function

* @param none
* @return none
*/
void mcuRestart(void)
{
    __set_FAULTMASK(1);
    NVIC_SystemReset();
}

/**@} */

#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
//  */
//PUTCHAR_PROTOTYPE
//{
//  /* Place your implementation of fputc here */
//  /* e.g. write a character to the USART1 and Loop until the end of transmission */
//  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
// 
//  return ch;
//}

///**
//  * @brief  Period elapsed callback in non blocking mode 
//  * @param  htim : TIM handle
//  * @retval None
//  */
//void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
//{
//	if(htim==&htim2)
//	{
//			keyHandle();
//			gizTimerMs();
//	}
//}

/**
* @brief Timer TIM3 init function

* @param none
* @return none
*/
//void timerInit(void)
//{
//	HAL_TIM_Base_Start_IT(&htim2);
//}

///**
//  * @brief  This function handles USART IDLE interrupt.
//  */
//void HAL_UART_RxCpltCallback(UART_HandleTypeDef*UartHandle)  
//{  
//    if(UartHandle->Instance == USART2)  
//    {  
//				gizPutData((uint8_t *)&aRxBuffer, 1);

//        HAL_UART_Receive_IT(&huart2, (uint8_t *)&aRxBuffer, 1);//开启下一次接收中断  
//    }  
//}  

/**
* @brief USART init function

* Serial communication between WiFi modules and device MCU
* @param none
* @return none
*/
//void uartInit(void)
//{
//	HAL_UART_Receive_IT(&huart2, (uint8_t *)&aRxBuffer, 1);//开启下一次接收中断  
//}

/**
* @brief Serial port write operation, send data to WiFi module
*
* @param buf      : buf address
* @param len      : buf length
*
* @return : Return effective data length;-1,return failure
*/
int32_t uartWrite(uint8_t *buf, uint32_t len)
{
		uint8_t crc[1] = {0x55};
    uint32_t i = 0;
	
    if(NULL == buf)
    {
        return -1;
    }

    for(i=0; i<len; i++)
    {
        USART_SendData(USART2,buf[i]);
				while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET);
				if(i>=2 && buf[i]==0xff)
				{
				USART_SendData(USART2,0X55);
				while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET);
				}
    }

#ifdef PROTOCOL_DEBUG
    GIZWITS_LOG("MCU2WiFi[%4d:%4d]: ", gizGetTimerCount(), len);
    for(i=0; i<len; i++)
    {
        GIZWITS_LOG("%02x ", buf[i]);

        if(i >=2 && buf[i] == 0xFF)
        {
            GIZWITS_LOG("%02x ", 0x55);
        }
    }
    GIZWITS_LOG("\n");
#endif
		
		return len;
}  

⭐获取更多资料

我用夸克网盘分享了「1 ESP8266.zip」,点击链接即可保存。打开「夸克APP」,无需下载在线播放视频,畅享原画5倍速,支持电视投屏。
链接:https://pan.quark.cn/s/7ef6d6df938e
提取码:YXYK

### 基于STM32的节能风扇智能控制系统硬件设计方案 #### 一、系统总体架构 本系统以STM32F103系列微控制器为核心,通过传感器采集环境参数,结合PWM调速、低功耗算法和通信模块,实现风扇的智能节能控制。硬件设计需满足以下功能: - **环境感知**:温度、人体红外检测 - **动态调速**:基于环境参数自动调节PWM输出 - **人机交互**:OLED显示+按键输入 - **节能模式**:待机休眠、自适应调压 - **通信扩展**:Wi-Fi/蓝牙远程控制 --- #### 二、关键硬件模块设计 1. **主控单元** - **芯片选型**:STM32F103C8T6(72MHz Cortex-M3,64KB Flash,20KB RAM,支持低功耗模式) - **供电设计**: - 主电源:12V锂电池组(兼容9-24V宽压输入) - 电压转换: - **LM2596**(12V→5V,电机驱动电路供电) - **AMS1117-3.3V**(5V→3.3V,MCU及传感器供电) - **低功耗实现**: - 配置STM32进入Stop模式(功耗<20μA),通过外部中断(人体传感器/按键)唤醒 2. **环境感知模块** - **温度检测**: - **DS18B20**(单总线接口,±0.5℃精度) - 电路设计:4.7KΩ上拉电阻+0.1μF去耦电容 - **人体检测**: - **HC-SR501**红外传感器(检测距离7m,可调延时) - 输出信号经光耦隔离后接入STM32 PA0 - **光照检测**(可选): - **BH1750**(I2C接口,0-65535 lx量程) 3. **电机驱动模块** - **驱动方案**: - **L298N双H桥**(支持最大46V/2A,搭配STM32 PWM输出) - **节能优化**: - 采用**IRF3205 MOSFET**替换传统H桥(降低导通损耗) - 增加**电流采样电阻(0.1Ω/5W)**+INA219芯片实现实时功率监控 - **PWM接口**: - 使用TIM1_CH1(PA8)输出PWM信号(频率16kHz,占空比0-100%可调) - 配置互补输出+死区控制(防止H桥直通) 4. **人机交互模块** - **显示单元**: - **0.96寸OLED**(SSD1306驱动,I2C接口) - 连接引脚:SCL→PB6,SDA→PB7 - **按键输入**: - 4×4矩阵键盘(PA1-PA4行扫描,PA5-PA8列检测) - 硬件消抖:0.1μF电容并联按键 5. **通信模块** - **无线传输**: - **ESP-01S WiFi模块**(AT指令,透传模式) - 接口设计:USART2(PA2-TX,PA3-RX)+CH340G电平转换 - **本地通信**(可选): - **HC-05蓝牙模块**(配对手机APP控制) 6. **电源监控模块** - **电池管理**: - **TP4056**充电管理芯片(支持4.2V锂电充电) - **XL6009升压模块**(5V→12V,效率>92%) - **电压检测**: - 分压电路(100K+100K电阻)+STM32 ADC1_IN1(PA1) --- #### 三、典型电路设计要点 1. **电机驱动保护电路** ```plaintext +12V ──┬─ L298N VS │ │ ├─ 100μF电解电容 └─ TVS二极管(P6KE15A) ``` - 在电机电源输入端并联100μF铝电解电容+0.1μF陶瓷电容 - 每个H桥输出端增加**续流二极管(1N5822)** 2. **低噪声ADC电路** ```plaintext DS18B20 DATA ──┬─ 4.7KΩ上拉 └─ 100nF电容接地 ``` - 模拟信号走线远离PWM线路 - 在VREF+引脚添加10μF钽电容+0.1μF陶瓷电容 3. **EMC设计** - 电机驱动部分与数字电路**物理隔离** - 关键信号线串联22Ω电阻+并联100pF电容滤波 --- #### 四、硬件选型清单 | 模块 | 型号 | 关键参数 | |--------------|---------------------|--------------------------| | 主控芯片 | STM32F103C8T6 | 72MHz, 64KB Flash | | 温度传感器 | DS18B20 | 单总线, ±0.5℃ | | 电机驱动 | L298N+IRF3205 | 46V/5A, Rds(on)=8mΩ | | 无线模块 | ESP-01S | 802.11 b/g/n, UART | | 显示屏 | SSD1306 0.96" OLED | 128×64, I2C | | 电源管理 | LM2596+AMS1117 | 3A降压, 3.3V LDO | --- #### 五、节能优化设计 1. **动态电压调节** - 根据负载情况自动切换供电模式: - 轻载(<30% PWM):切换至9V供电 - 重载(>70% PWM):启用12V供电 - 实现方式:通过MOSFET控制XL6009的反馈电阻网络 2. **智能休眠机制** - 无人状态持续5分钟→进入Stop模式 - 温度低于25℃且无人→关闭电机 - 唤醒响应时间<200ms 3. **PWM波形优化** - 使用STM32的**互补PWM输出**模式 - 配置死区时间(约500ns)防止H桥直通 - 调整PWM频率至16kHz(超出人耳听觉范围) --- ### 设计验证建议 1. **功耗测试**: - 使用万用表测量不同模式下的电流: - 休眠模式:<50μA - 低速运行:<300mA - 高速运行:<1.2A 2. **温升测试**: - 红外热像仪监测L298N和MOSFET温度 - 要求连续工作1小时温升<30℃ 3. **EMI测试**: - 使用频谱分析仪检测PWM谐波 - 在电机线缆上加装磁环抑制高频干扰 --- 续写
最新发布
05-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值