stm32——esp8266 Internet of Things development, connect to onenet cloud platform (http) to make smart home (1)

Here I would like to thank the up master of station b—there is light on the other side and we have a boat (I think the lecture is as good as the teacher of Jiangke University, if you are used to the lectures of Jiangke University teacher, you can take a look at it) for the tutorial provided and the original punctuality The source code of the atom, because I am studying the stm32 of Jiangke University, so I made some adaptations and some annotations. Here I simplify the video content and conduct a simple review.

Foreword:

This experiment is divided into three major stages: 1. Use esp8266 to connect to the onenet cloud platform; 2. Use the cloud platform to make a visual interface and obtain data into stm32; 3. The WeChat applet obtains and controls stm32 through the onenet cloud platform.

This experiment uses the usart transmission mode of esp8266 to connect to the cloud platform. This blog will describe the first step: use esp8266 to connect to the onenet cloud platform.

If there is a similarity, it may not be a coincidence hahaha.

  1. Start from creating onenet~

A. Onenet entry

Enter onenet directly in the browser to enter the cloud platform

As shown in the figure, after registering and logging in to onenet, click the console. Then click Multi-Protocol Access. In multi-protocol access

Click Add Product, in Add Product

In addition to the following networking method, select wifi, device access select http, operating system select Android, and operator to choose at will.

Then click Add Device. in the device list

The name and number can be written freely.

Just add the device.

B. The onenet cloud platform needs to write down things.

  1. master—apikey。

  1. device id.

The initial content of onenet is almost the same.

  1. Use esp8266 to upload messages to onenet

The transmission of esp8266 is used in this experiment usart3

Let's briefly talk about the idea of ​​​​the code

The four indispensable files of this code: time (interrupt, using Tim2), usart3 (esp8266 upload), sys (I don’t know what this file is for, if you can optimize this code and remove sys from the project Thank you for taking it away), esp8266 (initialization)

The main code function has been written in the comments

c file of usart

#include "usart3.h"

#define USART3_RXBUF_LEN 15
u8 t;
u8 USART3_RX_BUF[USART3_MAX_RECV_LEN];                 //接收缓冲,最大USART3_MAX_RECV_LEN个字节.
u8 USART3_TX_BUF[USART3_MAX_SEND_LEN];                 //发送缓冲,最大USART3_MAX_SEND_LEN字节

vu16 USART3_RX_STA=0;

//初始化串口3,使用9600波特率,和esp8266设备进行通信 
//bound:波特率
void Usart3_Init(void)
    {
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);            //此处使用的是USART3,是APB2时钟的外设
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);            //使能USART3和上面的GPIOB时钟
    
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                    //复用推挽输入,用于发送
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                        //引脚的Tx
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;                    //上拉输入,用于接收或者浮空输入
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;                        //引脚的Rx
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    USART_InitTypeDef USART_InitStructure;                            //USART的配置
    USART_InitStructure.USART_BaudRate = 115200;//通常esp8266为115200的波特率
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
    USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;//收发模式
    USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
    USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
    USART_Init(USART3, &USART_InitStructure);                        //USART3
    
    USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启串口接受中断
    
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    
    NVIC_InitTypeDef NVIC_InitStructure;                            //中断
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                //IRQ通道使能
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;    //抢占优先级3
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;            //子优先级3
    NVIC_Init(&NVIC_InitStructure);
    
    USART_Cmd(USART3, ENABLE); //使能串口3
    TIM2_Int_Init(1000-1,7200-1);        //10ms中断
    USART3_RX_STA=0;        //清零
    TIM_Cmd(TIM2,DISABLE);            //关闭定时器2
}

//串口3的发送函数 len=USART_RX_STA&0x3fff;
//得到此次接收到的数据长度USART_SendData(USART1, USART_RX_BUF[t]);
void Uart3_SendStr(u8* SendBuf,u8 len)
{
    //len=SendBuf&0x3fff;//得到此次接收到的数据长度
    for(t=0;t<len;t++)
    {
        USART_SendData(USART3, SendBuf[t]);//向串口1发送数据
        while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
    }
    printf("\r\n\r\n");//插入换行
}

//串口3,printf 函数
//确保一次发送数据不超过USART3_MAX_SEND_LEN字节
void u3_printf(char* fmt,...)
{
    
    u16 i,j; 
    va_list ap; 

    va_start(ap,fmt);
    vsprintf((char*)USART3_TX_BUF,fmt,ap);
    va_end(ap);
    i=strlen((const char*)USART3_TX_BUF);        //此次发送数据的长度
    for(j=0;j<i;j++)                            //循环发送数据
    {
      while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET); //循环发送,直到发送完毕   
        USART_SendData(USART3,USART3_TX_BUF[j]); 
    }
}

// 当串口三收到数据, 系统自动调用此中断函数
void USART3_IRQHandler(void)
{
    u8 res = 0;    
    
    if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)//接收到数据
    {     
        res = USART_ReceiveData(USART3);    
        
        if((USART3_RX_STA&(1<<15))==0)//接收完的一批数据,还没有被处理,则不再接收其他数据
        {
            if(USART3_RX_STA<USART3_MAX_RECV_LEN)    //还可以接收数据
            {
                TIM_SetCounter(TIM2,0);//计数器清空                          //计数器清空
                if(USART3_RX_STA==0)                 //使能定时器7的中断 
                {
                    TIM_Cmd(TIM2,ENABLE);//使能定时器7
                }
                USART3_RX_BUF[USART3_RX_STA++]=res;    //记录接收到的值
            } else 
            {
                USART3_RX_STA|=1<<15;                //强制标记接收完成
            }
        }
    }                                                                
}

// void USART3_IRQHandler(void)
// {
//     u8 Res;
//     if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)//接收到数据
//     {
//         Res =USART_ReceiveData(USART3);
//         if((USART3_RX_STA&0x8000)==0)//接收完的一批数据,还没有被处理,则不再接收其他数据
//         {
//             if((USART3_RX_STA&0X7FFF)<USART3_MAX_RECV_LEN)    //还可以接收数据
//                 {
//                     if(Res!='!')
//                     {
//                         USART3_RX_BUF[USART3_RX_STA++]=Res;    //记录接收到的值
// //                        printf("%c\r\n",Res);
//                     }
//           else
//                     {
//                         USART3_RX_STA|=0x8000;    //则信息接收完成了
//                     }
//                 }
//                 else
//                 {
//                     USART3_RX_STA|=0x8000;    //则信息接收完成了
//                 }
//         }
//         USART3_RX_Data();
//     }
// }

The header file of usart↓

#ifndef __USART3_H
#define __USART3_H


#include <stdarg.h>
#include <stdio.h>          
#include <string.h>     
#include "sys.h"
//#include "usart.h"        //可解冻
#include "Delay.h"
#include "timer.h"


#define USART3_MAX_RECV_LEN 1024
#define USART3_MAX_SEND_LEN 1024

extern vu16 USART3_RX_STA;                 //接收状态标记
extern u8 USART3_RX_BUF[USART3_MAX_RECV_LEN];         //接收缓冲,最大USART3_MAX_RECV_LEN个字节.
extern u8 USART3_TX_BUF[USART3_MAX_SEND_LEN];         //发送缓冲,最大USART3_MAX_SEND_LEN字节

void Usart3_Init(void);
void u3_printf(char* fmt,...);
void Uart3_SendStr(u8* SendBuf,u8 len);
#endif

Then there is an interruption↓

#include "timer.h"
 
extern vu16 USART3_RX_STA;
 
//定时器2中断服务程序            
void TIM2_IRQHandler(void)
{     
    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)//是更新中断
    {                    
        USART3_RX_STA|=1<<15;    //标记接收完成
        TIM_ClearITPendingBit(TIM2, TIM_IT_Update  );  //清除TIM2更新中断标志    
        TIM_Cmd(TIM2, DISABLE);  //关闭TIM2
    }        
}
 
//通用定时器7中断初始化,这里时钟选择为APB1的2倍
//arr:自动重装值 psc:时钟预分频数
//定时器溢出时间计算方法:Tout=((arr+1)*(psc+1))/Ft us.
//Ft=定时器工作频率,单位:Mhz 
//通用定时器中断初始化 
void TIM2_Int_Init(u16 arr,u16 psc)
{    
    NVIC_InitTypeDef NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);//TIM2时钟使能    
    
    //定时器TIM2初始化
    TIM_TimeBaseStructure.TIM_Period = arr; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值    
    TIM_TimeBaseStructure.TIM_Prescaler =psc; //设置用来作为TIMx时钟频率除数的预分频值
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM向上计数模式
    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
 
    TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE ); //使能指定的TIM2中断,允许更新中断
    
    TIM_Cmd(TIM2,ENABLE);//开启定时器2
    
    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0 ;//抢占优先级0
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;        //子优先级2
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;            //IRQ通道使能
    NVIC_Init(&NVIC_InitStructure);    //根据指定的参数初始化VIC寄存器
}

Tim Header ↓

#ifndef __TIMER_H
#define __TIMER_H
#include "sys.h"
#include "stm32f10x_tim.h"
void TIM2_Int_Init(u16 arr,u16 psc);
#endif

sys file↓

#include "sys.h"

//采用如下方法实现执行汇编指令WFI,执行wfi指令
void WFI_SET(void)
{
    __ASM volatile("wfi");          
}
//关闭所有中断
void INTX_DISABLE(void)
{          
    __ASM volatile("cpsid i");
}
//开启所有中断
void INTX_ENABLE(void)
{
    __ASM volatile("cpsie i");          
}

//设置addr为栈顶地址
__asm void MSR_MSP(u32 addr) 
{
    MSR MSP, r0             //set Main Stack value
    BX r14
}

sys header file↓

#ifndef __SYS_H
#define __SYS_H
#include "stm32f10x.h"
//该代码改编自正点原子

#define SYSTEM_SUPPORT_OS        0        //定义系统文件夹是否支持UCOS 0,不支持ucos 1,支持ucos
                                                                        
//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 
//IO口地址映射
#define GPIOA_ODR_Addr    (GPIOA_BASE+12) //0x4001080C 
#define GPIOB_ODR_Addr    (GPIOB_BASE+12) //0x40010C0C   

#define GPIOA_IDR_Addr    (GPIOA_BASE+8) //0x40010808 
#define GPIOB_IDR_Addr    (GPIOB_BASE+8) //0x40010C08  
 
//IO口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout(n)   BIT_ADDR(GPIOA_ODR_Addr,n)  //输出 
#define PAin(n)    BIT_ADDR(GPIOA_IDR_Addr,n)  //输入 

#define PBout(n)   BIT_ADDR(GPIOB_ODR_Addr,n)  //输出 
#define PBin(n)    BIT_ADDR(GPIOB_IDR_Addr,n)  //输入 

//以下为汇编函数
void WFI_SET(void);        //执行WFI指令
void INTX_DISABLE(void);//关闭所有中断
void INTX_ENABLE(void);    //开启所有中断
void MSR_MSP(u32 addr);    //设置堆栈地址

#endif

The next step is the most important esp8266 code, I will explain it carefully

首先是第三行的devices后面有***的内容,此处需要输入刚才记下的设备id号

然后是第四行的api-key,换成自己的即可

接下来是102行,此处管的是esp8266接上wifi。wifi名称,密码输入就行了。

(小彩蛋:因为esp8266上传时用的是字符串,所以需要把数字变成字符串,为此特地写了一个简单的转换小模块捏)

#include "esp8266.h"

char *str[4] = {"POST /devices/10*****/datapoints HTTP/1.1",
                "api-key:************=",
                "Host:api.heclouds.com",
                ""};
char strValue[8] = {0};

// 向onenet发送数据
uint8_t *esp8266_str_data(char *key, char *value)
{
    uint8_t i;
    uint8_t *back;
    char temp[512];
    char temp3[64];        // 长度
    char temp5[128];        // 发送值

    // 拼接post报文
    strcpy(temp5, "{\"datastreams\":[{\"id\":\"");
    strcat(temp5, key);
    strcat(temp5, "\",\"datapoints\":[{\"value\":");
    strcat(temp5, value);
    strcat(temp5, "}]}]}");

    strcpy(temp3, "Content-Length:");
    sprintf(temp, "%d", strlen(temp5) + 1);
    strcat(temp3, temp);

    strcpy(temp, "");
    for (i = 0; i < 3; i++)
    {
        strcat(temp, str[i]);
        strcat(temp, "\r\n");
    }
    strcat(temp, temp3);
    strcat(temp, "\r\n\r\n");
    strcat(temp, temp5);
    strcat(temp, "\r\n");

    back = esp8266_send_data((uint8_t *)temp, 50);
    // printf("server:%s\r\n", back);                
    if (strstr((char *)back, "ERROR"))        //发送失败, 重新初始化,发送
    {
        esp8266_send_cmd("AT+CIPMUX=0", "OK", 50);
        while (esp8266_send_cmd("AT+CIPSTART=\"TCP\",\"183.230.40.33\",80", "CONNECT", 100));
        esp8266_send_cmd("AT+CIPMODE=1", "OK", 50);
        esp8266_send_cmd("AT+CIPSEND", "OK", 20);
        return esp8266_send_data((uint8_t *)temp, 50);
    }
    return back;
}

// 向esp8266请求数据
uint16_t esp8266_get_data(char *vStr)
{
    uint8_t i;
    uint16_t value = 0;
    char *back;
    char temp[160] = "GET /devices/1042144877/datastreams/";

    // 拼接请求报文
    strcat(temp, vStr);
    strcat(temp, " HTTP/1.1\r\n");
    for (i = 1; i < 4; i++)
    {
        strcat(temp, str[i]);
        strcat(temp, "\r\n");
    }

    // 发送报文, 获取返回字符串
    back = (char *)esp8266_send_data((uint8_t *)temp, 50);
    // printf("server:%s\r\n", back);
    
    // 在回送报文中截取出数值
    back = strchr(strstr(back, "\"current_value\":"), ':') + 1;
    while (*back != '}')
    {
        if(*back == '\"'){
            back++;
            continue;
        }
        value = value * 10 + (*back - '0');
        back++;
    }

    return value;
}

//ESP8266模块和PC进入透传模式
void esp8266_start_trans(void)
{
    //设置工作模式 1:station模式   2:AP模式  3:兼容 AP+station模式
    esp8266_send_cmd("AT+CWMODE=1", "OK", 50);

    //让Wifi模块重启的命令
    esp8266_send_cmd("AT+RST", "OK", 50);

    Delay_ms(1000); //延时2S等待重启成功
    Delay_ms(1000);

    //让模块连接上自己的路由WIFI GOT IP
    while (esp8266_send_cmd("AT+CWJAP=\"名称\",\"密码\"", "WIFI GOT IP", 500)){
        Delay_ms(1);
    };

    //=0:单路连接模式     =1:多路连接模式
    esp8266_send_cmd("AT+CIPMUX=0", "OK", 50);
    Delay_ms(1);

    //建立TCP连接  这四项分别代表了 要连接的ID号0~4   连接类型  远程服务器IP地址   远程服务器端口号
    while (esp8266_send_cmd("AT+CIPSTART=\"TCP\",\"183.230.40.33\",80", "CONNECT", 200)){
        Delay_ms(1);
    };

    //产品ID     386234 设备ID   719623723    鉴权信息  202515
    //【Receive from 183.230.40.40 : 1811 】: receivedreceived
    //while(esp8266_send_cmd("*386234#202515#test*","receivedreceived",200));

    //是否开启透传模式  0:表示关闭 1:表示开启透传
    esp8266_send_cmd("AT+CIPMODE=1", "OK", 50);
    Delay_ms(1);

    //透传模式下 开始发送数据的指令 这个指令之后就可以直接发数据了
    esp8266_send_cmd("AT+CIPSEND", "OK", 50);
    Delay_ms(1);
}

//ESP8266退出透传模式   返回值:0,退出成功;1,退出失败
//配置wifi模块,通过想wifi模块连续发送3个+(每个+号之间 超过10ms,这样认为是连续三次发送+)
uint8_t esp8266_quit_trans(void)
{
    uint8_t result = 1;
    u3_printf("+++");
    Delay_ms(1000);                               //等待500ms太少 要1000ms才可以退出
    result = esp8266_send_cmd("AT", "OK", 20); //退出透传判断.
    if (result)
        printf("quit_trans failed!");
    else
        printf("quit_trans success!");
    return result;
}

//向ESP8266发送命令
//cmd:发送的命令字符串;ack:期待的应答结果,如果为空,则表示不需要等待应答;waittime:等待时间(单位:10ms)
//返回值:0,发送成功(得到了期待的应答结果);1,发送失败
uint8_t esp8266_send_cmd(uint8_t *cmd, uint8_t *ack, uint16_t waittime)
{
    uint8_t res = 0;
    USART3_RX_STA = 0;
    u3_printf("%s\r\n", cmd); //发送命令
    Delay_ms(1);
    if (ack && waittime)      //需要等待应答
    {
        while (--waittime) //等待倒计时
        {
            Delay_ms(10);
            if (USART3_RX_STA&0X8000) //接收到期待的应答结果
            {
                
                if (esp8266_check_cmd(ack))
                {
                    //printf("%s\r\n", (uint8_t *)USART3_RX_BUF);            //这个函数是串口一在电脑上看的
                    break; //得到有效数据
                }
                USART3_RX_STA = 0;
                //strcpy((char *)USART3_RX_BUF, "");        // 清空接收缓存区
            }
        }
        if (waittime == 0) res = 1;
    }
    return res;
}

//ESP8266发送命令后,检测接收到的应答
//str:期待的应答结果
//返回值:0,没有得到期待的应答结果;其他,期待应答结果的位置(str的位置)
uint8_t *esp8266_check_cmd(uint8_t *str)
{
    char *strx = 0;
    if (USART3_RX_STA & 0X8000) //接收到一次数据了
    {
        USART3_RX_BUF[USART3_RX_STA & 0X7FFF] = 0; //添加结束符
        strx = strstr((const char *)USART3_RX_BUF, (const char *)str);
    }
    return (uint8_t *)strx;
}

//向ESP8266发送数据
//cmd:发送的命令字符串;waittime:等待时间(单位:10ms)
//返回值:发送数据后,服务器的返回验证码
uint8_t *esp8266_send_data(uint8_t *cmd, uint16_t waittime)
{
    char temp[1024];
    char *ack = temp;
    USART3_RX_STA = 0;
    u3_printf("%s", cmd); //发送命令
    Delay_ms(1);
    if (waittime)          //需要等待应答
    {
        while (--waittime) //等待倒计时
        {
            Delay_ms(10);
            if (USART3_RX_STA & 0X8000) //接收到期待的应答结果
            {
                USART3_RX_BUF[USART3_RX_STA & 0X7FFF] = 0; //添加结束符
                ack = (char *)USART3_RX_BUF;
                USART3_RX_STA = 0;
                break; //得到有效数据
            }
        }
    }
    return (uint8_t *)ack;
}

// 将数字转为字符串
//自写的转换代码,更简单的思路
void Num_To_String(uint16_t value)
{
    int k=0,i;            
    int num = (int)value;
    for(;(value/=10)>=1;k++)
    {
    }
    for(i=k;i>=0;i--)
    {
        strValue[i]=num%10+'0';
        num/=10;
    }
    strValue[k+1] = '\0'; //结束符号
}

接下来是esp8266的头文件↓

此处解释上面代码每个模块的作用

#ifndef __ESP8266
#define __ESP8266

#include <stdlib.h>
#include <string.h>
#include "led.h"
#include "Delay.h"

//#include "usart.h"        //当使用串口1在电脑上看数据时所用,此外还有send中的sprintf要解冻
#include "usart3.h"
#include "stm32f10x.h"
#include "sys.h"
extern char strValue[8];        //这个字符数组是Num_To_String后的结果


void esp8266_start_trans(void);        //esp8266连接onenet的代码(相当于初始化)
uint8_t esp8266_quit_trans(void);    //esp8266退出onenet的代码

uint8_t esp8266_send_cmd(u8 *cmd,u8 *ack,u16 waittime);    //这仨为中间代码,是发送和接收代码的基石
uint8_t* esp8266_check_cmd(u8 *str);
uint8_t* esp8266_send_data(u8 *cmd,uint16_t waittime);

uint16_t esp8266_get_data(char* vStr);                    //用esp8266向onenet获得data的最终函数
uint8_t* esp8266_str_data(char* key,char* value);        //用esp8266向onenet发送data的最终函数

void Num_To_String(uint16_t value);        //将得到的数字化为字符串。
#endif

小课堂:讲解一下esp8266的上传流程

首先要直到,esp8266的波特率是115200

然后就是下列顺序啦(忽视博主的丑陋字体吧qaq)

最后一个改一下(意思是temp,humi是名字,数字是数据)

大概就是这些了,最后呢吧esp8266接入stm32的PB10和PB11,然后vcc,gnd,就能够传输数据啦

主代码,教你使用

#include "sys.h"
#include "Delay.h"
//#include "usart.h"
#include "usart3.h"
#include "esp8266.h"
#include "timer.h"
#include "OLED.h"

int main(void)
{
    u8 tempValue = 66;
    u8 humidity = 0;
    u8 t = 0;
    u8 Keynum=0;
    // 设置中断优先级分组为组2:2位抢占优先级,2位响应优先级

 //   Usart_Init(); //串口初始化波特率为9600,具体可在usart.c中更改
    
    // 初始化ESP8266, 连接onenet, 进入透传模式
    Usart3_Init();            //由于esp8266建议波特率115200,所以此处波特率为115200
    esp8266_start_trans();
    OLED_Init();
    PWM_Init();
    while (1)
    {
        if (t == 10)
        {
            t = 0;
            // 将温度和湿度上传到云平台
            Num_To_String(tempValue);
            esp8266_str_data("temp", strValue);上传数据的函数
            Num_To_String(humidity);
            esp8266_str_data("humi", strValue);
            tempValue++;
            if(tempValue>=100)
            {
                tempValue=0;
            }
        }
        Delay_ms(10);
        t++;
    }
}


好了捏,这就是本博客的所有内容了,最后呢,唠嗑一句,期末刚考完,鼠鼠才大一捏,高数都还能看,但是英语就已经没救捏,英语学习真难绷捏QAQ。为什么英语要折磨鼠鼠呜呜呜~

下一期时间未知,但是本博客的问题会总结到下一个esp8266博客一起讨论,要源码可以私聊捏~

(弘扬免费源码精神,从我做起~)

Guess you like

Origin blog.csdn.net/ChiShangying/article/details/129307014