• 大小: 30.09MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-14
  • 语言: 其他
  • 标签: STM32CubeMX  MQTT  ESP8266  

资源简介

本工程使用STM32CubeMX工具创建,包含DHT11温湿度传感器驱动,通过ESP8266模块,联网并通过MQTT协议栈,实现本地数据到阿里云IOT平台的MQTT订阅与发布功能。 课程地址:https://blog.csdn.net/u014779536/article/details/106326129

资源截图

代码片段和文件信息

/**
********************************************************
*
* @file      Hal_temp_hum.c
* @author    Gizwtis
* @version   V03010100
* @date      2016-07-05
*
* @brief     机智云.只为智能硬件而生
*            Gizwits Smart Cloud  for Smart Products
*            链接|增值ֵ|开放|中立|安全|自有|自由|生态
*            www.gizwits.com
*
*********************************************************/
#include “hal_temp_hum.h“
#include 

thTypedef_t temphumTypedef;

//在里面添加自定义的延时函数
void delayUs(uint32_t nus)
{
TIM1_Delay_us(nus);
}


void DHT11_IO_OUT(void)
{
GPIO_InitTypeDef myGPIO_InitStruct;
myGPIO_InitStruct.Pin = GPIO_PIN_3;
myGPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
myGPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA &myGPIO_InitStruct);
}

void DHT11_IO_IN(void)
{
GPIO_InitTypeDef myGPIO_InitStruct;
myGPIO_InitStruct.Pin = GPIO_PIN_3;
  myGPIO_InitStruct.Pull = GPIO_PULLUP;
myGPIO_InitStruct.Mode = GPIO_MODE_INPUT;
myGPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA &myGPIO_InitStruct);
}
//Reset DHT11
static void dht11Rst(void)
{
    DHT11_IO_OUT();              //SET OUTPUT
    DHT11_DQ_OUT_0;              //GPIOA.0=0
    HAL_Delay(20);               //Pull down Least 18ms
    DHT11_DQ_OUT_1;              //GPIOA.0=1
    delayUs(30);                  //Pull up 20~40us
}

static uint8_t dht11Check(void)
{
    uint8_t retry=0;
    DHT11_IO_IN();                                              //SET INPUT
    while (DHT11_DQ_IN && (retry<100))                          //DHT11 Pull down 40~80us
    {
        retry++;
        delayUs(1);
    }

    if(retry >= 100)
    {
        return 1;
    }
    else
    {
        retry=0;
    }

    while (!DHT11_DQ_IN&& (retry < 100))     //DHT11 Pull up 40~80us
    {
        retry++;
        delayUs(1);
    }

    if(retry >= 100)
    {
        return 1;                         //check error
    }        

    return 0;
}

static uint8_t dht11ReadBit(void)
{
    uint8_t retry=0;
    while(DHT11_DQ_IN && (retry<100))                           //wait become Low level
    {
        retry++;
        delayUs(1);
    }

    retry = 0;
    while(!DHT11_DQ_IN && (retry < 100))     //wait become High level
    {
        retry++;
        delayUs(1);
    }

    delayUs(30);//wait 40us

    if(DHT11_DQ_IN)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

static uint8_t dht11ReadByte(void)
{
    uint8_t idat;
    dat=0;
    for (i=0; i<8; i++)
    {
        dat<<=1;
        dat |= dht11ReadBit();
    }

    return dat;
}

static uint8_t dht11ReadData(uint8_t *temperature uint8_t *humidity)
{
    uint8_t buf[5];
    uint8_t i;
    dht11Rst(); 
    if(0 == dht11Check()) 
    {
        for(i=0; i<5; i++)
        {
            buf[i] = dht11ReadByte();
        }
        if(buf[4] == (buf[0]+buf[1]+buf[2]+buf[3]))
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-05-07 14:22  ESP826_MQTT\
     文件        6635  2020-05-07 14:22  ESP826_MQTT\.mxproject
     目录           0  2020-05-07 13:56  ESP826_MQTT\BSP\
     目录           0  2020-05-07 13:15  ESP826_MQTT\BSP\DHT11\
     文件        5452  2020-05-07 13:36  ESP826_MQTT\BSP\DHT11\hal_temp_hum.c
     文件        1078  2020-05-07 13:36  ESP826_MQTT\BSP\DHT11\hal_temp_hum.h
     目录           0  2020-05-07 13:43  ESP826_MQTT\BSP\ESP8266\
     文件        6152  2020-05-06 08:09  ESP826_MQTT\BSP\ESP8266\esp8266_at.c
     文件         795  2020-05-06 08:09  ESP826_MQTT\BSP\ESP8266\esp8266_at.h
     目录           0  2020-05-07 13:56  ESP826_MQTT\BSP\MQTT\
     文件        6914  2020-05-05 21:49  ESP826_MQTT\BSP\MQTT\esp8266_mqtt.c
     文件         606  2020-05-05 21:49  ESP826_MQTT\BSP\MQTT\esp8266_mqtt.h
     目录           0  2020-05-07 11:25  ESP826_MQTT\Drivers\
     目录           0  2020-05-07 11:26  ESP826_MQTT\Drivers\CMSIS\
     目录           0  2020-05-07 11:25  ESP826_MQTT\Drivers\CMSIS\Core\
     目录           0  2020-05-07 11:25  ESP826_MQTT\Drivers\CMSIS\Core\Include\
     文件       28208  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\cmsis_armcc.h
     文件       56497  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\cmsis_armclang.h
     文件        9014  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\cmsis_compiler.h
     文件       62344  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\cmsis_gcc.h
     文件       28414  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\cmsis_iccarm.h
     文件        1716  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\cmsis_version.h
     文件       97995  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_armv8mbl.h
     文件      168914  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_armv8mml.h
     文件       42208  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_cm0.h
     文件       50464  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_cm0plus.h
     文件       43456  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_cm1.h
     文件      104628  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_cm23.h
     文件      111854  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_cm3.h
     文件      175600  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_cm33.h
     文件      123607  2020-03-03 09:43  ESP826_MQTT\Drivers\CMSIS\Core\Include\core_cm4.h
............此处省略1148个文件信息

评论

共有 条评论