#include <string.h>
//单片机头文件
#include "sys.h"
//网络协议层
#include "onenet.h"
//网络设备
#include "esp8266.h"
//硬件驱动
#include "delay.h"
#include "usart.h"
#include "led.h"
//硬件初始化
void Hardware_Init(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
delay_init(); //延时函数初始化
Usart1_Init(115200); //串口1初始化为115200
Usart2_Init(115200); //串口2,驱动ESP8266用
LED_Init(); //LED初始化
}
void Net_Init()
{
ESP8266_Init(); //初始化ESP8266
while(OneNet_DevLink()) //接入OneNET
delay_ms(500);
LED = LED_ON; //入网成功
}
int main(void)
{
unsigned char *dataPtr = NULL;
unsigned short timeCount = 300; //发送间隔变量
Hardware_Init(); //初始化外围硬件
Net_Init(); //网络初始化
while(1)
{
delay_ms(10);
timeCount ++;
if(timeCount >= 300) //发送间隔
{
OneNet_SendData(); //发送数据
timeCount = 0;
ESP8266_Clear();
}
dataPtr = ESP8266_GetIPD(0);
if(dataPtr != NULL)
{
OneNet_RevPro(dataPtr);
}
}
}
全部代码下载:
STM32接入OneNET.7z
(194.71 KB, 下载次数: 35)
|