极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10521|回复: 1

enc28j60 和 nrf24l01+ 同时使用如何实现?

[复制链接]
发表于 2013-4-13 14:43:27 | 显示全部楼层 |阅读模式
参考了前辈们的文章:
http://www.geek-workshop.com/for ... thread&tid=2520
http://www.geek-workshop.com/for ... thread&tid=1228
想做个室外温度采集,采集端用的是一块arduino mini,温度感应模块采集温度数据然后用nrf24l01传送给接收端,接收端是arduino uno,nrf24l01接到数据后由enc28j60网络模块上传到yeelink,自己试着整合了一下代码,但是通不过编译,跪求大神指点啊!!! (编译环境1.01)

#include "SPI.h"
#include "Mirf.h"
#include "nRF24L01.h"
#include "MirfHardwareSpiDriver.h"
#include <EtherCard.h>
#define OUT
#define REQUEST_RATE 10000 // milliseconds
#define SENSOR1 4
#define SENSOR2 5
#define SENSOR3 6
#define LANcsPin 8
#define RFcsPin 10
int data;
int aaa;
int aaaa;
// ethernet interface mac address
static byte mymac[] = {
  0x74,0x69,0x69,0x2D,0x30,0x31 };

// remote website name
char website[] PROGMEM = "api.yeelink.net";
char urlBuf[] PROGMEM = "/v1.0/device/2464/sensor/3315/datapoints";
char apiKey[] PROGMEM = "U-ApiKey: -------------------------------------------";

byte Ethernet::buffer[700];
static long timer;

// called when the client request is complete
static void my_result_cb (byte status, word off, word len) {
  Serial.print("<<< reply ");
  Serial.print(millis() - timer);
  Serial.println(" ms");
  Serial.println((const char*) Ethernet::buffer+off);
}

void setup () {
  SPI.begin();
  pinMode(LANcsPin,OUTPUT);
  pinMode(RFcsPin,OUTPUT);
  Serial.begin(9600);
  Serial.println("[getDHCPandDNS]");
  digitalWrite(RFcsPin,HIGH);
  digitalWrite(LANcsPin,LOW);
  randomSeed(analogRead(0));
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");

  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("My IP: ", ether.myip);
  // ether.printIp("Netmask: ", ether.mymask);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);

  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
  ether.printIp("Server: ", ether.hisip);

  timer = - REQUEST_RATE; // start timing out right away
  digitalWrite(LANcsPin,HIGH);
  digitalWrite(RFcsPin,LOW);
  Mirf.spi = &MirfHardwareSpi;   //加载24L01  SPI
  Mirf.init();
  Mirf.setRADDR((byte *)"serv1");//接收到"接收地址"
  Mirf.payload = sizeof(int);   //接收类型(整数)
  Mirf.config();
}
void loop () {
  if(Mirf.dataReady()){
     Mirf.getData((byte *)&data); //接收数据
     aaa = data;
     Mirf.rxFifoEmpty();
  }
  delay(10);
  digitalWrite(RFcsPin,HIGH);
  digitalWrite(LANcsPin,LOW);
   ether.packetLoop(ether.packetReceive());
  if ((millis() > timer + REQUEST_RATE) && !aaa == aaaa) {
    aaaa = aaa;
    timer = millis();
    Serial.println(">>> REQ");
    static char buf[20];
    get_send_string(buf);
    if (!ether.dnsLookup(website))
      Serial.println("DNS failed");
    ether.printIp("Server: ", ether.hisip);
    ether.httpPost (urlBuf, website, apiKey, buf, my_result_cb);
  }
}
void get_send_string(OUT char *p){
  if (!aaaa == 1111){
  uint16_t whole = 50;
  sprintf(p,"{\"value\":%d}",whole);}
else{
   uint16_t whole = 0;
  sprintf(p,"{\"value\":%d}",whole);}
   
}
回复

使用道具 举报

发表于 2013-4-28 20:36:54 | 显示全部楼层
我不是大神。。。不过你没说你编译没过时错误代码是什么啊
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-5 07:19 , Processed in 0.034286 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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