2017-10-16 121 views
0

我是新手,请大家多多包涵我:)Radiohead的库通信

我下面电台司令这个客户端服务器的例子在库中找到, http://www.airspayce.com/mikem/arduino/RadioHead/ 我用Dragino劳拉与盾的Arduino UNO和Arduino的兆。我有几个问题,如果有人能帮助我:

1)我没有看到服务器或客户机地址,这样如何服务器和客户端发送的邮件? 2)我们可以看到代码 “而(串行)!”,就是把它发送和USB串行接收数据,而不是通过无线电信号

服务器

// rf95_server.pde 
// -*- mode: C++ -*- 
// Example sketch showing how to create a simple messageing server 
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or 
// reliability, so you should only use RH_RF95  if you do not need the higher 
// level messaging abilities. 
// It is designed to work with the other example rf95_client 
// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with 
// the RFM95W, Adafruit Feather M0 with RFM95 

#include <SPI.h> 
#include <RH_RF95.h> 

// Singleton instance of the radio driver 
RH_RF95 rf95; 
//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W 
//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 

// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro) 
//#define Serial SerialUSB 

int led = 9; 

void setup() 
{ 
 // Rocket Scream Mini Ultra Pro with the RFM95W only: 
 // Ensure serial flash is not interfering with radio communication on SPI bus 
//  pinMode(4, OUTPUT); 
//  digitalWrite(4, HIGH); 

 pinMode(led, OUTPUT);     
 Serial.begin(9600); 
 while (!Serial) ; // Wait for serial port to be available 
 if (!rf95.init()) 
   Serial.println("init failed");   
 // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on 

 // The default transmitter power is 13dBm, using PA_BOOST. 
 // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
 // you can set transmitter powers from 5 to 23 dBm: 
//  driver.setTxPower(23, false); 
 // If you are using Modtronix inAir4 or inAir9,or any other module which uses the 
 // transmitter RFO pins and not the PA_BOOST pins 
 // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. 
 // Failure to do that will result in extremely low transmit powers. 
//  driver.setTxPower(14, true); 
} 

void loop() 
{ 
 if (rf95.available()) 
 { 
   // Should be a message for us now   
   uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; 
   uint8_t len = sizeof(buf); 
   if (rf95.recv(buf, &len)) 
   { 
     digitalWrite(led, HIGH); 
//      RH_RF95::printBuffer("request: ", buf, len); 
     Serial.print("got request: "); 
     Serial.println((char*)buf); 
//      Serial.print("RSSI: "); 
//      Serial.println(rf95.lastRssi(), DEC); 
      
     // Send a reply 
     uint8_t data[] = "And hello back to you"; 
     rf95.send(data, sizeof(data)); 
     rf95.waitPacketSent(); 
     Serial.println("Sent a reply"); 
      digitalWrite(led, LOW); 
   } 
   else 
   { 
     Serial.println("recv failed"); 
   } 
 } 
} 

客户

// rf95_client.pde 
// -*- mode: C++ -*- 
// Example sketch showing how to create a simple messageing client 
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or 
// reliability, so you should only use RH_RF95 if you do not need the higher 
// level messaging abilities. 
// It is designed to work with the other example rf95_server 
// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with 
// the RFM95W, Adafruit Feather M0 with RFM95 

#include <SPI.h> 
#include <RH_RF95.h> 

// Singleton instance of the radio driver 
RH_RF95 rf95; 
//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W 
//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 

// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro) 
//#define Serial SerialUSB 

void setup() 
{ 
 // Rocket Scream Mini Ultra Pro with the RFM95W only: 
 // Ensure serial flash is not interfering with radio communication on SPI bus 
//  pinMode(4, OUTPUT); 
//  digitalWrite(4, HIGH); 

 Serial.begin(9600); 
 while (!Serial) ; // Wait for serial port to be available 
 if (!rf95.init()) 
   Serial.println("init failed"); 
 // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on 

 // The default transmitter power is 13dBm, using PA_BOOST. 
 // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
 // you can set transmitter powers from 5 to 23 dBm: 
//  driver.setTxPower(23, false); 
 // If you are using Modtronix inAir4 or inAir9,or any other module which uses the 
 // transmitter RFO pins and not the PA_BOOST pins 
 // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. 
 // Failure to do that will result in extremely low transmit powers. 
//  driver.setTxPower(14, true); 
} 

void loop() 
{ 
 Serial.println("Sending to rf95_server"); 
 // Send a message to rf95_server 
 uint8_t data[] = "Hello World!"; 
 rf95.send(data, sizeof(data)); 
  
 rf95.waitPacketSent(); 
 // Now wait for a reply 
 uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; 
 uint8_t len = sizeof(buf); 

 if (rf95.waitAvailableTimeout(3000)) 
 { 
   // Should be a reply message for us now   
   if (rf95.recv(buf, &len)) 
  { 
     Serial.print("got reply: "); 
     Serial.println((char*)buf); 
//      Serial.print("RSSI: "); 
//      Serial.println(rf95.lastRssi(), DEC);     
   } 
   else 
   { 
     Serial.println("recv failed"); 
   } 
 } 
 else 
 { 
   Serial.println("No reply, is rf95_server running?"); 
 } 
 delay(400); 
} 
+0

不能回答你所有的问题,但它的外观的代码使用的是默认频率和通信详细配置:'434.0MHz,13dBm的,BW = 125千赫,CR = 4/5,SF = 128chips/symbol'在一个简单的主/从只有通信方案,你不*需要*地址本身,或多或少只是轮流设备“会说话” –

+0

另外,如果'(!rf95.init( ))'while while(!Serial)'后面的''表明'rf95.init()'挂钩到Arduino的Serial中。我的猜测是USB串行端口被无线电电子设备切断和接管,或者无线电电子设备反映串行端口的输入/输出。 (即,它们可以是平行) –

+0

这也意味着你的'Serial.println'电话喷出垃圾在电台,可能扰乱你的通信协议。 –

回答

1

1)我没有看到服务器或客户机地址,这样如何服务器和客户端发送的邮件?

  1. 劳拉是一个无线协议的任何接收机能够解码(只要它们具有升特芯片或等同物)。就像接收调频收音机一样 - 你需要的只是一个天线和意愿。 :)

    LoraWAN与劳拉传输作为其 物理层的网络规范。 LoraWAN指定终端到终端的 加密的数据包,设备寻址,重放攻击保护, 拥塞管理,信道跳频,应用程序配置, 等

2)我们可以看到代码“设施而(串行!);”,是将其发送,并通过USB串行接收数据,而不是通过无线无线电信号

  • 的无线电头库不具有串行相互作用或重定向它以任何方式。

    while (!Serial);是一个标准的Arduino成语。该Serial类实现的方法operator bool()这样(bool)Serial评估为true时候才可以使用。因此,while (!Serial);是一个紧密的循环,等待串行端口准备就绪。