当前位置:网站首页>CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统
CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统
2022-08-03 17:02:00 【InfoQ】
1、前言
2、设计需求
硬件选型:

3、硬件选型
3.1 CC2530+WIFI模块

3.2 DHT11温湿度模块

3.3 蜂鸣器

4、物联网云端配置与应用
4.1 华为云IoTDA介绍

4.2 产品创建












4.3 设备创建



{
"device_id": "62e732be3a884835598654f7_dev1",
"secret": "12345678"
}4.4 MQTT三元组信息生成


ClientId 62e732be3a884835598654f7_dev1_0_0_2022080102
Username 62e732be3a884835598654f7_dev1
Password 13483ebeadd786ea107527a3c92c5463a8f3c71377cd33276143ffe2fb85c1dc4.5 MQTT主题订阅与发布格式
//订阅主题: 平台下发消息给设备
$oc/devices/62e732be3a884835598654f7_dev1/sys/messages/down
//设备上报数据
$oc/devices/62e732be3a884835598654f7_dev1/sys/properties/report
//上报的属性消息 (一次可以上报多个属性,在json里增加就行了)
{"services": [{"service_id": "server_id","properties":{"温度":23.4}},{"service_id": "server_id","properties":{"湿度":80.5}}]}4.6 设备模拟登录测试


4.7 应用侧开发接口介绍

5、CC2530程序设计
5.1 IAR环境搭建

5.2 硬件原理图

5.3 IAR程序工程图

5.4 DHT11.c代码
#include "uart.h"
/*
函数功能:串口0初始化
*/
void Init_Uart0(void)
{
PERCFG&=~(1<<0); //串口0的引脚映射到位置1,即P0_2和P0_3
P0SEL|=0x3<<2; //将P0_2和P0_3端口设置成外设功能
U0BAUD = 216; //32MHz的系统时钟产生115200BPS的波特率
U0GCR&=~(0x1F<<0);//清空波特率指数
U0GCR|=11<<0; //32MHz的系统时钟产生115200BPS的波特率
U0UCR |= 0x80; //禁止流控,8位数据,清除缓冲器
U0CSR |= 0x3<<6; //选择UART模式,使能接收器
}
/*
函数功能:UART0发送字符串函数
*/
void UR0SendString(u8 *str)
{
while(*str!='\0')
{
U0DBUF = *str; //将要发送的1字节数据写入U0DBUF
while(UTX0IF == 0);//等待数据发送完成
UTX0IF = 0; //清除发送完成标志,准备下一次发送
str++;
}
}
/*
函数功能: 模仿printf风格的格式化打印功能
*/
char USART0_PRINT_BUFF[200]; //格式化数据缓存数据
void USART0_Printf(const char *format,...)
{
char *str=NULL;
/*1. 格式化转换*/
va_list ap; // va_list---->char *
va_start(ap,format); //初始化参数列表
vsprintf(USART0_PRINT_BUFF,
format,
ap); //格式化打印
va_end(ap); //结束参数获取
/*2. 串口打印*/
str=USART0_PRINT_BUFF;//指针赋值
while(*str!='\0')
{
U0DBUF=*str; //发送一个字节的数据
str++; //指针自增,指向下一个数据
while(UTX0IF == 0);//等待数据发送完成
UTX0IF = 0; //清除发送完成标志,准备下一次发送
}
}5.5 ESP8266.c代码
#include "esp8266.h"
uint lenU1 = 0;
uchar tempRXU1;
uchar RecdataU1[MAXCHAR];
//"AT+CIPSEND=0,10\r\n" //长度10
//返回">" 之后就可以正常发送数据了
//发送成功返回 "SEND OK"
//发送数据
void ESP8266_SendData(char *p,int len)
{
int i=0;
char buff[50];
sprintf(buff,"AT+CIPSEND=0,%d\r\n",len);
clearBuffU1();
Uart1_Send_String(buff); //发送指令
DelayMs(1000); //等待
for(i=0;i<len;i++)
{
Uart1_Send_Char(p[i]);
}
//等待发送完成
DelayMs(1000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
}
/****************************************************************************
* 名 称: SetWifi()
* 功 能: 设置LED灯相应的IO口
* 入口参数: 无
* 出口参数: 无
****************************************************************************/
void SetWifi(void)
{
P0DIR |= 0x40; //P0.6定义为输出
IGT = 0; //高电平复位
DelayMs(500);
IGT = 1; //低电平工作
}
/*
设置WIFI为AP模式+TCP服务器
*/
void SetESP8266_AP_TCP_Server()
{
clearBuffU1();
Uart1_Send_String("AT\r\n");
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
Uart1_Send_String("ATE0\r\n");
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
Uart1_Send_String("AT+CWMODE=2\r\n");
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
Uart1_Send_String("AT+RST\r\n");
DelayMs(2000);
DelayMs(2000);
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
Uart1_Send_String("ATE0\r\n");
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
Uart1_Send_String("AT+CWSAP=\"wifi_cc2530\",\"12345678\",1,4\r\n");
DelayMs(2000);
DelayMs(2000);
DelayMs(2000);
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
Uart1_Send_String("AT+CIPMUX=1\r\n");
DelayMs(2000);
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
Uart1_Send_String("AT+CIPSERVER=1,8089\r\n");
DelayMs(2000);
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
clearBuffU1();
Uart1_Send_String("AT+CIFSR\r\n");
DelayMs(2000);
DelayMs(2000);
RecdataU1[lenU1]='\0';
UR0SendString(RecdataU1);
}
unsigned char dataRecv;
unsigned char Flag = 0;
/*===================UR1初始化函数====================*/
void Init_Uart1()
{
PERCFG = 0x00;//位置1 P0.4/P0.5口
P0SEL |= 0x30;//P0.4,P0.5用作串口(外部设备功能)
U1CSR |= 0x80;//设置为UART方式
U1GCR |= 11;//BAUD_E
U1BAUD |= 216;//BAUD_M 波特率设为115200
UTX1IF = 0; //UART1 TX中断标志初始置位0
U1CSR |= 0X40; //允许接收
IEN0 |= 0x88; // 开总中断,UART1接收中断
}
void clearBuffU1(void)
{
int j;
for(j=0;j<MAXCHAR;j++)
{
RecdataU1[j]=0x00;
}
lenU1=0;
}
/*******************************************************************************
串口1发送一个字节函数
*******************************************************************************/
void Uart1_Send_Char(char Data)
{
U1CSR &= ~0x40; //禁止接收
U1DBUF = Data;
while(UTX1IF == 0);
UTX1IF = 0;
U1CSR |= 0x40; //允许接收
}
/*******************************************************************************
串口1发送字符串函数
*******************************************************************************/
void Uart1_Send_String(char *Data)
{
while(*Data!='\0')
{
Uart1_Send_Char(*Data);
Data++;
}
}
/****************************************************************
串口接收一个字符: 一旦有数据从串口传至CC2530, 则进入中断,将接收到的数据赋值给变量temp.
****************************************************************/
#pragma vector = URX1_VECTOR
__interrupt void UART1_ISR(void)
{
if(lenU1<81)
{
tempRXU1 = U1DBUF;
RecdataU1[lenU1]=tempRXU1;
URX1IF = 0; // 清中断标志
lenU1++;
}
}6、总结
边栏推荐
- SwinIR combat: record the training process of SwinIR in detail
- vant自动上传图片/文件
- sphinx error connection to 127.0.0.1:9312 failed (errno=0, msg=)
- The strongest distributed lock tool: Redisson
- CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统
- sphinx coreseek的安装和php下使用
- C专家编程 第3章 分析C语言的声明 3.2 声明是如何形成的
- 使用Stream多年,collect还有这些“骚操作”?
- 【GAMES101】作业6 加速结构
- SwinIR实战:详细记录SwinIR的训练过程
猜你喜欢

国内首发可视化智能调优平台,小龙带你玩转KeenTune UI

组件通信--下拉菜单案例

酷开科技 × StarRocks:统一 OLAP 分析引擎,全面打造数字化的 OTT 模式

【GAMES101】作业6 加速结构

Interviews are no longer hanged!This is the correct way to open the seven schemes of Redis distributed locks

TiKV & TiFlash 加速复杂业务查询丨TiFlash 应用实践

通用型安全监测数据管理系统

C# 构造函数如人之影子
![[Unity Getting Started Plan] Basic Concepts (6) - Sprite Renderer Sprite Renderer](/img/c2/5717cb053bc6c07829a616735cbc71.png)
[Unity Getting Started Plan] Basic Concepts (6) - Sprite Renderer Sprite Renderer

面试突击:什么是粘包和半包?怎么解决?
随机推荐
5. Longest Palindromic Substring
C专家编程 第3章 分析C语言的声明 3.2 声明是如何形成的
sphinx coreseek的安装和php下使用
高薪程序员&面试题精讲系列132之微服务之间如何进行通信?服务熔断是怎么回事?你熟悉Hystrix吗?
数据中台“集存通用治”功能场景说明
LeetCode·899.有序队列·最小表示法
C专家编程 第3章 分析C语言的声明 3.7 typedef struct foo{... foo;}的含义
CC2530_ZigBee+华为云IOT:设计一套属于自己的冷链采集系统
请问下这个hologres维表是被缓存了么?怎么直接Finished了
B站回应HR称核心用户是Loser;微博回应宕机原因;Go 1.19 正式发布|极客头条
MobileVIT实战:使用MobileVIT实现图像分类
405. Convert a Number to Hexadecimal
#夏日挑战赛#【FFH】OpenHarmony设备开发基础(四)启动流程
【Metaverse系列一】元宇宙的奥秘
2年开发经验去面试,吊打面试官,即将面试的程序员这些笔记建议复习
并发高的情况下,试试用ThreadLocalRandom来生成随机数
如何直击固定资产管理的难题?
【无标题】
After using Stream for many years, does collect still have these "saucy operations"?
【There is no tracking information for the current branch. Please specify which branch you want to 】