Author Topic: Can't receive (or transmit) using MEGA LoRa [solved]  (Read 6864 times)

itzikhaim

  • NewMember
  • *
  • Posts: 3
Can't receive (or transmit) using MEGA LoRa [solved]
« on: July 24, 2016, 11:33:16 AM »
Hello.

I would like to ask you if anyone can help regarding a problem I have when trying to use the MOTEINO MEGA LoRa.

I have ordered the 433MHz Transceiver and soldered (properly) the quarter-wavelength mono-pole wire antenna.
Also, downloaded and configure the Arduino 1.0.6 to work with the 'Mighty 1284p 16MHz using Optiboot' as the target board - I have succeeded with uploading and programming the sketch files.

Lastly, the (latest) libraries of the SPIFlash and the RFM69 were downloaded and used - but still when uploading for two boards the example codes ('Gateway' and 'Node') - I can't see the communication link being established.
currently I don't know even if the Transceiver gets out for transmitting (don't a Spectrum Analyzer) - the changes and modifications I did to the 'include' files summed up to the following:
line 36 ar RFM69.h:

Code: [Select]
#define RF69_SPI_CS             4 // SS is the SPI slave select pin, for instance D10 on ATmega328
Also:
lines 51-54 (Defining the Interrupt pin for the ATMEL 1284p chip):

Code: [Select]
#else 
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          2 
#endif
both at Gateway.ino and Node.ino made sure that this line is enabled:
#define FREQUENCY     RF69_433MHZ

Please your help.
Thank you!
I.C.
« Last Edit: August 10, 2016, 03:40:54 PM by Felix »

luisr320

  • Sr. Member
  • ****
  • Posts: 255
  • Country: pt
Re: Can't receive (or transmit) using MEGA LoRa
« Reply #1 on: July 24, 2016, 03:20:30 PM »
Hi.
I've been using regular Moteinos for quite a while and I thought that using the Lora version would be easy but it isn't.
First thing that needs to be understood is that Lora technology is a planet from a different galaxy when compared to the regular RFM69. And when you look into the available documentation or comments regarding its usage, you can't find anything easily, as I could for the RFM69 Moteinos.

Another thing that is difficult to understand are the names of the radios used for the Lora versions of the Moteinos. A 433Mhz Lora radio is a RFM96LORA. But you need to use the #include <RH_RF95.h> on your sketch. Not RF96.
The libraries to use are here: http://lowpowerlab.com/RadioHead_LowPowerLab.zip.
Download it and install it inside your arduino libraries folder.
Then go to the examples folder of that library and open a RF95_client.ino on one Moteino and a RF95_server.ino on the other.

Or just load these couple of sketches into each, after downloading and installing the library I mention above:

Code: [Select]
// Load this on what you will consider to be the "Client" node

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

#define FREQUENCY  434

#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
  #define FLASH_SS      23 // and FLASH SS on D23
#else
  #define LED           9 // Moteinos have LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif

// Singleton instance of the radio driver
RH_RF95 rf95;

void setup()
{
  Serial.begin(115200);
  if (!rf95.init())
    Serial.println("init failed");
  else { Serial.print("init OK - "); Serial.print(FREQUENCY); Serial.print("mhz"); }
 
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
  rf95.setFrequency(FREQUENCY);
}

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?");
  }
  Blink(LED,3);
  delay(200);
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}


Code: [Select]

//Load this on what you consider to be the "Server" node

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

#define FREQUENCY  434

// Singleton instance of the radio driver
#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
  #define FLASH_SS      23 // and FLASH SS on D23
#else
  #define LED           9 // Moteinos have LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif

RH_RF95 rf95;

void setup()
{
  pinMode(LED, OUTPUT);
  Serial.begin(115200);
  if (!rf95.init())
    Serial.println("init failed");
  else { Serial.print("init OK - "); Serial.print(FREQUENCY); Serial.print("mhz"); }
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
  rf95.setFrequency(FREQUENCY);
}

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");
    }
  }
}

If you want I can also post a basic Datagram version of these sketches.

Happy Moteining :)
« Last Edit: July 24, 2016, 06:06:01 PM by luisr320 »

itzikhaim

  • NewMember
  • *
  • Posts: 3
Re: Can't receive (or transmit) using MEGA LoRa
« Reply #2 on: July 26, 2016, 10:28:58 AM »
Dear luisr320 - yes, it worked (almost) just fine!

Using your recommended libraries of RadioHead and the two examples provided at RH_RF95  (the RF95_client and the RF95_server),
I was able to use the transceivers correctly.

Just something annoying to share with you: when uploading the downloaded the provided clent/server examples - it didn't send and receive yet.

I notice that the FREQUENCY definition is 434 and not 433 - when changed both frequencies to 433 it was working splendid.

Thanks,
itzikhaim

luisr320

  • Sr. Member
  • ****
  • Posts: 255
  • Country: pt
Re: Can't receive (or transmit) using MEGA LoRa [solved]
« Reply #3 on: July 26, 2016, 12:29:09 PM »
That's good news.
It's weird that you couldn't use that frequency. I can and all works well.
Happy moteining.
Luis

itzikhaim

  • NewMember
  • *
  • Posts: 3
Re: Can't receive (or transmit) using MEGA LoRa [solved]
« Reply #4 on: July 27, 2016, 07:56:46 AM »
Luis hello.

I have noticed that you mentioned "Datagram .. of these sketches."
Please elaborate on this - what is this?

Thanks,
I.C.

luisr320

  • Sr. Member
  • ****
  • Posts: 255
  • Country: pt
Re: Can't receive (or transmit) using MEGA LoRa [solved]
« Reply #5 on: July 27, 2016, 11:39:05 AM »
The Radiohead library has the ability to add a way for the integrity of the data sent to a receiver to be assured.
Just like the SendwithRetry of the RFM69 library.
Using the sketch that I posted above, if the receiver doesn't get all the data, there is no way for the sender to know, because the size of the data is not accounted for. So if it misses its target there is no way to get another one sent.
Also, when the sender transmits, everyone with a similar radio tuned on that frequency will get it and are able to see the data.
And any data sent by some other radio will be received by the receiver, even though it might not be the intended receiver.
You could, of course, just code an id and a data type on the data struct itself and make the receiver check in the struct if the data is intended for itself.

But using a Reliable Datagram, all that is taken care for.

Looking at the Radiohead site, you can check how to use the RHReliabledatagram (http://www.airspayce.com/mikem/arduino/RadioHead/classRHReliableDatagram.html).

For instance, the data is sent by using a sendtoWait() like this:
sendtoWait ( uint8_t * buf, uint8_t len, uint8_t address)

And the receiver will use a recfromAck() like this:
recvfromAck ( uint8_t * buf, uint8_t * len, uint8_t * from = NULL, uint8_t * to = NULL, uint8_t * id = NULL, uint8_t * flags = NULL)

As you can see, the "address" (the CLIENT_ADDRESS) and the "from" (the SERVER_ADDRESS)  are checked, as well as the data length.

Try these two sketches:
Code: [Select]
// rf95_reliable_datagram_server.pde


#include <RHReliableDatagram.h>  //get it here http://lowpowerlab.com/RadioHead_LowPowerLab.zip
#include <RH_RF95.h>  //get it here http://lowpowerlab.com/RadioHead_LowPowerLab.zip
#include <SPI.h> //get it here: https://www.github.com/lowpowerlab/spiflash

#define SERVER_ADDRESS 1 // address number of the Server
#define CLIENT_ADDRESS 2 // address number of the Client
#define RETRIES 4 // Number of times the sendtoWait() will try to send a message. Default is 3
#define TIMEOUT 2000 // Timeout before sendWait() tries again to send a message

// Match frequency to the hardware version of the radio on your Moteino
#define FREQUENCY   433

// Singleton instance of the radio driver
RH_RF95 driver;

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, SERVER_ADDRESS);

void setup()
{
  // connect to the serial monitor at 115200 baud
  Serial.begin(115200);
  Serial.println("DATAGRAM TEST - SERVER");
  Serial.println("");
 
  //Initialize the radio
  if (!manager.init())
    Serial.println("Init failed!");
  else
  {
    Serial.print("Init OK - ");
    Serial.println(FREQUENCY); Serial.print("mhz");
    driver.setFrequency(FREQUENCY);
  }

  manager.setRetries(RETRIES);
  manager.setTimeout(TIMEOUT);

}

uint8_t data[] = "FROM SERVER: Message received!";
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];

void loop()
{
  if (manager.available())
  {
    uint8_t len = sizeof(buf);
    uint8_t from;
    // Wait for a message addressed to us from the client and send an ACKNOWLEDGE if it is received with the right length
    if (manager.recvfromAck(buf, &len, &from))
    {
      Serial.print("The following message was received from and acknowledged to CLIENT ID: ");
      Serial.print(from);
      Serial.print(" -> ");
      Serial.println((char*)buf);

      //Now send a reply back to the originator client
      if (!manager.sendtoWait(data, sizeof(data), from))
        Serial.println("Transmission of data failed! ACK not received from CLIENT!");
      else
        Serial.println("A reply was sent to and acknowledged by the CLIENT");
        Serial.println("");
    }
    else
    Serial.println("ACK not received from CLIENT");
  }
}

Code: [Select]
// rf95_reliable_datagram_client.pde


#include <RHReliableDatagram.h>  //get it here http://lowpowerlab.com/RadioHead_LowPowerLab.zip
#include <RH_RF95.h>  //get it here http://lowpowerlab.com/RadioHead_LowPowerLab.zip
#include <SPI.h> //get it here: https://www.github.com/lowpowerlab/spiflash

#define SERVER_ADDRESS 1 // address number of the Server
#define CLIENT_ADDRESS 2 // address number of the Client
#define RETRIES 4 // Number of times the sendtoWait() will try to send a message. Default is 3
#define TIMEOUT 2000 // Timeout before sendWait() tries again to send a message

// Match frequency to the hardware version of the radio on your Moteino
#define FREQUENCY   433

// Singleton instance of the radio driver
RH_RF95 driver;

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, CLIENT_ADDRESS);

void setup()
{
   // connect to the serial monitor at 115200 baud
  Serial.begin(115200);
  Serial.println("DATAGRAM TEST - CLIENT");
  Serial.println("");
 
  //Initialize the radio
  if (!manager.init())
    Serial.println("Init failed!");
  else
  {
    Serial.print("Init OK - ");
    Serial.println(FREQUENCY); Serial.print("mhz");
    driver.setFrequency(FREQUENCY);
  }

  manager.setRetries(RETRIES);
  manager.setTimeout(TIMEOUT);

}

uint8_t data[] = "Hello there!";
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];

void loop()
{
  Serial.println("Sending a message to the SERVER... ");
   
  // Send a message to manager_server
  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
  {
    uint8_t len = sizeof(buf);
    uint8_t from;   
    // Now wait for a reply from the server
    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
    {
      Serial.print("Got reply from server ID ");
      Serial.print(from);
      Serial.print(": ");
      Serial.println((char*)buf);
      Serial.println("");
    }
    else
    {
      Serial.println("No reply, is SERVER running?");
    }
  }
  else
    Serial.println("Transmission of data failed!");
  delay(500);
}
« Last Edit: July 28, 2016, 06:55:17 AM by luisr320 »

ReanimationXP

  • NewMember
  • *
  • Posts: 13
Re: Can't receive (or transmit) using MEGA LoRa [solved]
« Reply #6 on: January 17, 2018, 09:07:33 AM »
Ok, I'm a bit upset now after finding this thread. Why is a user somehow posting links to forks of RadioHead's library hiding on the LowPowerLab site that aren't linked to anywhere in documentation?  I've been chasing ghosts for the past day only to find out perfectly good examples are hiding on the site somewhere rather than being properly pull requested into RadioHead or served up properly in the LowPowerLab github somewhere.. what gives??

ReanimationXP

  • NewMember
  • *
  • Posts: 13
Re: Can't receive (or transmit) using MEGA LoRa [solved]
« Reply #7 on: January 17, 2018, 09:13:19 AM »
That said, thank you luisr320. You were the one and only reason I was able to get the 4 Moteinos I bought to do anything.  I'm having abysmal results with range, however. Looking into how to bump the gain now.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Can't receive (or transmit) using MEGA LoRa [solved]
« Reply #8 on: January 17, 2018, 10:18:58 AM »
@ReanimationXP:
Have you seen this page?

It has library links for using LoRa transceiver Moteinos, along with other tips and details.
Make sure you have a proper antenna connected to your Moteino ANT pin. Using your radios without one can permanently damage the transceivers!

ReanimationXP

  • NewMember
  • *
  • Posts: 13
Re: Can't receive (or transmit) using MEGA LoRa [solved]
« Reply #9 on: January 17, 2018, 11:09:39 AM »
Hi Felix, Yes I've read the whole page several times. This part in particular needs to be updated:

Quote
If you use IDE 1.0.6 or older and having trouble compiling the latest RadioHead, you may try this archived version.

This is the one and only place where the link to your fork of the library appears.  I disregarded it completely since I'm using 1.8.6 and had no issues on compilation - only a failure to init the radio. Why doesn't this exist in your GitHub or as a PR to RadioHead?  What changes were made to RadioHead exactly such that I can replicate them on a current version and submit a proper PR?

ReanimationXP

  • NewMember
  • *
  • Posts: 13
Re: Can't receive (or transmit) using MEGA LoRa [solved]
« Reply #10 on: January 22, 2018, 11:50:50 AM »
Update: Felix has added the necessary information to the page.