# LoRa FANET with RH\_RF95.h and RFM95W

**URL:** <https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577>\
**Category:** Libraries\
**Created:** [April 9, 2020, 3:52pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577 "2020-04-09T15:52:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![not103](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@not103](https://community.particle.io/u/not103)\
**Post date:** [April 9, 2020, 3:52pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/1 "2020-04-09T15:52:39Z")

</div>

Hello, I am making some experiment to work with FANET+ network. I would like to publish wind data from a Photon connected anemometer to the FANET network (is a LoRa application for paragliding devices).

I have two devices working on this network (they are talking togheter) and I would like to add a custom Photon with RFM95W transceiver.

This is the FANET specification:

_868.2Mhz_  
_Syncword 0xF1_  
_250kHz Bandwidth_  
_Spreading Factor 7_  
_ExplicitHeader: Coding Rate CR 5-8/8 (depending on #neighbors), CRC for Payload_

This my code, it compile, it runs (no error on RF95 init) but I can’t see any raw data.

```auto
// This #include statement was automatically added by the Particle IDE.
#include <RH_RF95.h>
     
#include <SPI.h>
 
#define RFM95_RST 1  
#define RFM95_CS 6
#define RFM95_INT 2   

#define SERIAL_DEBUG

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

#define LED 7
SYSTEM_THREAD(ENABLED);
 
void setup()
{
  delay(5000);    
    
  pinMode(LED, OUTPUT);
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
 
  Serial.begin(115200);
  while (!Serial) {
    delay(1);
  }
  delay(100);
 
  Serial.println("Feather LoRa RX Test!");
 
  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);
 
  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");
 
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
 
  rf95.setSignalBandwidth(250E3);
  rf95.setSpreadingFactor(7);
  rf95.setCodingRate4(8);
  rf95.setPreambleLength(12);
  rf95.setPayloadCRC(1);
  // 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:
  rf95.setTxPower(23, false);
}
 
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("Received: ", buf, len);
      Serial.print("Got: ");
      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("Receive failed");
    }
  }
}

```

Where I am wrong? How can I deal with it?

---

<div class="post-metadata">

**Author:** ![bpr](https://avatars.discourse-cdn.com/v4/letter/b/8797f3/32.png) [@bpr](https://community.particle.io/u/bpr)\
**Post date:** [April 9, 2020, 6:23pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/2 "2020-04-09T18:23:58Z")

</div>

@not103 ,  
Did you  
-define RF95\_FREQ somewhere’s?  
-double check wiring?

---

<div class="post-metadata">

**Author:** ![not103](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@not103](https://community.particle.io/u/not103)\
**Post date:** [April 9, 2020, 6:51pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/3 "2020-04-09T18:51:32Z")

</div>

FREQ was defined, after paste the code I probbly accidentally delete it with an unnecessary comment.

Just after #define LED 7 there is

#define RF95\_FREQ 868.2

Wiring seems ok. Same RFM95W board connected to an ESP8266 works, it connect with the above LoRa implementation.

---

<div class="post-metadata">

**Author:** ![not103](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@not103](https://community.particle.io/u/not103)\
**Post date:** [April 9, 2020, 7:39pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/4 "2020-04-09T19:39:18Z")

</div>

This is a printout of RFM95W registry:

_1: 81_  
_6: D9_  
_7: 0_  
_8: 0_  
_9: 88_  
_A: 9_  
_B: 2B_  
_C: 20_  
_D: 0_  
_E: 0_  
_F: 0_  
_10: 0_  
_11: 0_  
_12: 0_  
_13: 0_  
_14: 0_  
_15: 0_  
_16: 0_  
_17: 0_  
_18: 10_  
_19: 0_  
_1A: 0_  
_1B: 0_  
_1C: 0_  
_1D: 88_  
_1E: 74_  
_1F: 64_  
_20: 0_  
_21: 8_  
_22: 1_  
_23: FF_  
_24: 0_  
_25: 0_  
_26: 4_  
_27: 0_  
_39: F1_  
_42: 12_

---

<div class="post-metadata">

**Author:** ![bpr](https://avatars.discourse-cdn.com/v4/letter/b/8797f3/32.png) [@bpr](https://community.particle.io/u/bpr)\
**Post date:** [April 9, 2020, 7:43pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/5 "2020-04-09T19:43:29Z")

</div>

@not103  
hmmm, can't see any other problems...  
However, I have been using

> sendtoWait

(RHReliableDiagram) successfully rather than your use of

> ```
> rf95.send(data, sizeof(data));
> rf95.waitPacketSent();
> 
> ```

You might look at my gists at [bprobbins’s gists · GitHub](https://gist.github.com/bprobbins)

---

<div class="post-metadata">

**Author:** ![not103](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@not103](https://community.particle.io/u/not103)\
**Post date:** [April 9, 2020, 8:06pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/6 "2020-04-09T20:06:15Z")

</div>

Well I would like to start trying to receive a message (the two devices sends broadcast message) but I can’t get anything.

---

<div class="post-metadata">

**Author:** ![bpr](https://avatars.discourse-cdn.com/v4/letter/b/8797f3/32.png) [@bpr](https://community.particle.io/u/bpr)\
**Post date:** [April 9, 2020, 8:29pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/7 "2020-04-09T20:29:17Z")

</div>

I'd start by trying the default modem settings:

> rf95.setModemConfig(RH\_RF95::Bw125Cr45Sf128 );

on two devices, then if that works try out your earlier setting one by one.  
I actually never could successfully get anything but the default settings to work

---

<div class="post-metadata">

**Author:** ![not103](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@not103](https://community.particle.io/u/not103)\
**Post date:** [April 9, 2020, 8:34pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/8 "2020-04-09T20:34:41Z")

</div>

The devices I have aren’t customizable, they only works with configuration with these specs:

_868.2Mhz_  
_Syncword 0xF1_  
_250kHz Bandwidth_  
_Spreading Factor 7_  
_ExplicitHeader: Coding Rate CR 5-8/8 (depending on #neighbors), CRC for Payload_

---

<div class="post-metadata">

**Author:** ![bpr](https://avatars.discourse-cdn.com/v4/letter/b/8797f3/32.png) [@bpr](https://community.particle.io/u/bpr)\
**Post date:** [April 9, 2020, 9:32pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/9 "2020-04-09T21:32:15Z")

</div>

> [@not103](#):
>
> RH\_RF95

I think the recommended library to use is RF9X-RK. Did you try that?

---

<div class="post-metadata">

**Author:** ![bpr](https://avatars.discourse-cdn.com/v4/letter/b/8797f3/32.png) [@bpr](https://community.particle.io/u/bpr)\
**Post date:** [April 9, 2020, 11:18pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/10 "2020-04-09T23:18:19Z")

</div>

@not103  
Not sure what specific thing did it, but with a few changes, it works for me:  
First, added the RF9X-RK library as above.  
Second, I apparently wired the feather radio differently, so changed those defines - see code below:  
Third, eliminated the initial delay - caused panic in my photons for some reason, and it’s unnecessary.  
Fourth, set up a random seed to provide a random delay in loop so that the two devices don’t get in a race issue or sync lock.  
Fifth, put a startup message at the end of setup in one device.  
I also reduced txpower since I had my two photons side by side  
Photon1:

```auto
// This #include statement was automatically added by the Particle IDE.
#include <RF9X-RK.h>

// This #include statement was automatically added by the Particle IDE.
#include <RH_RF95.h>
     
#include <SPI.h>
/* 
#define RFM95_RST 1  
#define RFM95_CS 6
#define RFM95_INT 2  
*/ 
#define RFM95_CS A2 
#define RFM95_RST 4 
#define RFM95_INT D2 

#define SERIAL_DEBUG

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

#define LED 7
SYSTEM_THREAD(ENABLED);
 
 #define RF95_FREQ 915.0
 
void setup()
{
 // delay(5000);    
    
  pinMode(LED, OUTPUT);
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
 
  Serial.begin(115200);
  while (!Serial) {
    delay(1);
  }
  delay(100);
 
  Serial.println("Feather LoRa RX Test!");
 
  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);
 
  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");
 
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
 
  rf95.setSignalBandwidth(250E3);
  rf95.setSpreadingFactor(7);
  rf95.setCodingRate4(8);
  rf95.setPreambleLength(12);
  rf95.setPayloadCRC(1);
  // 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:
  rf95.setTxPower(6, false);
  
    randomSeed(analogRead(0));  

    uint8_t data2[] = "Start Message";
    rf95.send(data2, sizeof(data2));
    rf95.waitPacketSent();
}
 
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("Received: ", buf, len);
      Serial.print("Got: ");
      Serial.println((char*)buf);
       Serial.print("RSSI: ");
      Serial.println(rf95.lastRssi(), DEC);

 delay(random(1000, 2000));
 
      // 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("Receive failed");
    }
  }
}

```

And Photon 2:

```auto
// This #include statement was automatically added by the Particle IDE.
#include <RF9X-RK.h>

// This #include statement was automatically added by the Particle IDE.
#include <RH_RF95.h>
     
#include <SPI.h>
/* 
#define RFM95_RST 1  
#define RFM95_CS 6
#define RFM95_INT 2  
*/
#define RFM95_CS A2 
#define RFM95_RST 4 
#define RFM95_INT D2 

#define SERIAL_DEBUG

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

#define LED 7
SYSTEM_THREAD(ENABLED);
 
 #define RF95_FREQ 915.0
 
void setup()
{
 //delay(5000);    
    
  pinMode(LED, OUTPUT);
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
 
  Serial.begin(115200);
  while (!Serial) {
    delay(1);
  }
  delay(100);
 
  Serial.println("Feather LoRa RX Test!");
 
 
  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);
 
  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");
 
 
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);

 
  rf95.setSignalBandwidth(250E3);
 
  rf95.setSpreadingFactor(7);
  rf95.setCodingRate4(8);
  rf95.setPreambleLength(12);
  rf95.setPayloadCRC(1);
  /**/
  // 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
  
  rf95.setTxPower(6, false);

}
 
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("Received: ", buf, len);
      Serial.print("Got: ");
      Serial.println((char*)buf);
       Serial.print("RSSI: ");
      Serial.println(rf95.lastRssi(), DEC);
 
 delay(random(1000, 2000));
 
      // 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("Receive failed");
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [June 8, 2020, 11:18pm UTC](https://community.particle.io/t/lora-fanet-with-rh-rf95-h-and-rfm95w/55577/11 "2020-06-08T23:18:23Z")

</div>

Closed on June 8, 2020, 11:18pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
