极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12686|回复: 1

关于nrf24l01+dht11无线传输温度数据的问题

[复制链接]
发表于 2016-2-21 13:26:15 | 显示全部楼层 |阅读模式
下面是例程里的发送代码,封装了一个Sends函数,Sends("hello"); 发送字符串是可以的,假如要发送数值呢?该怎么修改?

发送代码
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
void setup(){
Serial.begin(9600);
Mirf.spi = &MirfHardwareSpi;
Mirf.init();

Mirf.setRADDR((byte *)"clie1"); // 标记本地名,用于接收
Mirf.payload = 5; //对话的长度,用于约定双方对话的缓冲窗口大小,这个代表5个字节
Mirf.channel = 3; // 信道,测试了一下,不同的信道也能接收但即时性很差,不知是不是存在自动寻道匹配机制

Mirf.config();
}
void loop(){
unsigned long time = millis();

Mirf.setTADDR((byte *)"serv1"); // 标记对方的地址
Sends("hello"); //发送了一个5字节的hello
delay(1000);
}

void Sends(char *str)
{
int lens;
lens=strlen(str);

char msg[lens];
int i;
for (i=0;i<lens;i++)
{
msg[i]= int(str[i]);
}
Mirf.send((byte *)&msg);

while(Mirf.isSending()){}

}
回复

使用道具 举报

 楼主| 发表于 2016-2-22 09:46:41 | 显示全部楼层
............
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 17:45 , Processed in 0.056661 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表