LoRa shield sending but not receiving

Can anyone help me with this please.

Using 2 Mega 2560 with Durinotech LoRa shields.

The TX will send to the RX and the RX receives and sends back a confirmation of receipt.

But the TX does not receive the confirmation back.

The TX package size is always ZERO.

I am sure it is something I am just not seeing because a similar sketch worked just fine a few week ago.

Now even the sketch that once worked has the same problem, Packet Size ZERO.

Have tried out the TX and RX " EXAMPLES" and they seem to work fine,

//...................................................................  TX SENDER   ......................................

#include <SPI.h>
#include <LoRa.h>
//.................................................................    RTC   DS 3231   ............
#include <Wire.h>
#include <ds3231.h>
struct ts t;
//................................................................   LORA ADDRESSES   .............
byte localAddress = 0xAA;
byte destinationAddress = 0xBB;

unsigned int lastSendTime = 0;
long int staTRec  = 0;
long int staT = 0;
void setup() {
  Serial.begin(9600);


  //..............................................................  RTC START   ............
  Wire.begin();
  DS3231_init;
  //..............................................................   SET TIME   ...........
  //t.hour = 14; t.min = 10; t.sec = 5; t.mday = 12; t.mon = 11; t.year = 2021;
  //DS3231_set(t);

  //.............................................................   STARTING LORA   ....................
  Serial.println("Start LoRa duplex  TX  Sender");
  if (!LoRa.begin(915E6)) {
    Serial.println("LoRa init failed. Check your connections.");
    while (true) {}
  }
}
//..............................................................   VOID SENDING DATA   ...........................
void senddatA()
{
  if (millis() - lastSendTime > 5000) {
    String sensorData = String(staT);

    sendMessage(sensorData);
    Serial.println("  SENT            " + sensorData);
    // Serial.print(" from 0x" + String(localAddress, HEX));
    // Serial.println(" to 0x" + String(destinationAddress, HEX));
    lastSendTime = millis();

  }
}
//.............................................................   VOID SEND MESSAGE   .............................
void sendMessage(String outgoing) {
  digitalWrite(12, HIGH);
  LoRa.beginPacket();
  LoRa.write(destinationAddress);
  LoRa.write(localAddress);
  LoRa.write(outgoing.length());
  LoRa.print(outgoing);
  LoRa.endPacket();
  delay(500);
  digitalWrite(12, LOW);

}
//...........................................................   RECEIVING MESSAGE   ..............
void receiveMessage(int packetSize) {

  if (packetSize == 0) return;
  int recipient = LoRa.read();
  byte sender = LoRa.read();
  byte incomingLength = LoRa.read();
  String incoming = "";
  while (LoRa.available()) {
    incoming += (char)LoRa.read();



  }
  if (incomingLength != incoming.length()) {
    //Serial.println("Error: Message length does not match length");
    return;
  }
  if (recipient != localAddress) {
    //Serial.println("Error: Recipient address does not match local address");
    return;
  }

  staTRec = incoming.toInt();
  Serial.print("  Received  back  "); Serial.println(staTRec);

  // station();


}
//.......................................................................................   LOOP   ................................................
void loop() {
  staT = 260;
  senddatA();
  // Serial.print ("  START STATION  ");Serial.println(staT);

  receiveMessage(LoRa.parsePacket());     //    RECEIVE MESSAGE
  delay(1000);



}
type o// ................................................RX  RECEIVER  ..............

#include <SPI.h>
#include <LoRa.h>

byte localAddress = 0xBB;
byte destinationAddress = 0xAA;
long int reC = 0;
unsigned int lastSendTime = 0;
long int staT = 0;
void setup() {
   Serial.begin(9600);
//................................................................   STARTING LORA   ....................................
        Serial.println("Start LoRa duplex RX Receiver");
        if (!LoRa.begin(915E6)) {
        Serial.println("LoRa init failed. Check your connections.");
        while (true) {}
      }
}
//..............................................................   VOID SENDING DATA   ...........................
void senddatA()
{
  if (millis() - lastSendTime > 2000) {
    String sensorData = String(reC);

    sendMessage(sensorData);
    Serial.println("  SENT            " + sensorData);
    // Serial.print(" from 0x" + String(localAddress, HEX));
    // Serial.println(" to 0x" + String(destinationAddress, HEX));
    lastSendTime = millis();

  }
}

 void sendMessage(String outgoing) {

       
       
        LoRa.beginPacket();
        LoRa.write(destinationAddress);
        LoRa.write(localAddress);
        LoRa.write(outgoing.length());
        LoRa.print(outgoing);
        LoRa.endPacket();
        Serial.print("                           sending back   " ); Serial.println(outgoing);

        digitalWrite(7, HIGH); delay(500); digitalWrite(7, LOW);
       
    
      }
        //...................................................................   RECEIVING DATA   ............................................
        void receiveMessage(int packetSize) {
        if (packetSize == 0) return;
        int recipient = LoRa.read();
        byte sender = LoRa.read();
        byte incomingLength = LoRa.read();

        String incoming = "";

        while (LoRa.available()) {
        incoming += (char)LoRa.read();
      }

        reC = incoming.toInt();
         senddatA();
Serial.print("      REC  Is  ");Serial.println(reC);
        
       

      }

void loop() {
   receiveMessage(LoRa.parsePacket());     //    RECEIVE MESSAGE

}

r paste code here

Hello Hello Any replies appreciated even if its just to call me a B....Y idiot??????

Hi,
Can you please post a schematic of your projects.
If both 2560 circuits are the same, have you tried swapping the function?
That is send from what would have been the receiving end in the first case.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Thanks TOM.

I have no thing connected to the LoRa to try to connect.

I am using Duinotech shields with Mega 2560 boards.

I have some 868MH and 915MH shields but ensure that I do not mix them up.

Tx transmits to RX and RX receives just fine.

Change the TX and RX boards around and the one way transmissions work just fine BUT

when I try to get either to reply back to other the RX says its sending but the TX receives
"0" packets.

The Lora Shields are Brand New from Jaycar and I have tried several Mega 2560 boards.

The strange thing is that this code was running perfectly for over 7 months I recently decided
to change the LED's on the Sender and try out a " Nextion " board to display the " status".

type or paste code//..................................................................   RX  RECEIVER  ..........................................
#include <SPI.h>
#include <LoRa.h>

byte localAddress = 0xBB;
byte destinationAddress = 0xAA;
//.................................................................    ENERGY MONITOR    ......................................

#include "EmonLib.h"             // Include Emon Library
#define CURRENT_CAL 250
EnergyMonitor emon1;             // Create an instance

//.................................................................   VARIABLES   ............................................
long lastSendTime = 0;
int interval = 2000;

unsigned int reC  = 0;
int statioN  = 0;
int onofF    = 0;
int incom = reC;
int aaa = 0;  //  Temp Variable
int loopCount = 0;  //   Energy Monitor Loop
float currentDraw = 0;
int AConoff = 0;  //      AC  either ON = 1 or OFF = 0
void setup() {
  Serial.begin(9600);
  //.................................................................    ENERGY MONITOR    ......................................

  emon1.current(0, CURRENT_CAL);       // Current: input pin, calibration.

  //................................................................   LED SETUP  ............................................
  pinMode(6, OUTPUT);  //.................TX LED
  digitalWrite(6, HIGH);
  delay(500);
  digitalWrite(6, LOW);

  pinMode(7, OUTPUT);//.................RX LED
  digitalWrite(7, HIGH);
  delay(500);
  digitalWrite(7, LOW);
  for (aaa = 3; aaa < 6; aaa++) {
    pinMode(aaa, OUTPUT); digitalWrite(aaa, LOW); delay(500); digitalWrite(aaa, HIGH);
  }
  //.................................................................   RELAY PIN SETUP   ..................................
  pinMode(23, OUTPUT); digitalWrite (23, HIGH); //   RELAY 1
  pinMode(24, OUTPUT); digitalWrite (24, HIGH); //   RELAY 2
  pinMode(25, OUTPUT);  digitalWrite (25, HIGH); //   RELAY 3
  //................................................................   STARTING LORA   ....................................
  Serial.println("Start LoRa duplex RX Receiver");
  if (!LoRa.begin(915E6)) {
    Serial.println("LoRa init failed. Check your connections.");
    while (true) {}
  }
}
//.................................................................    ENERGY MONITOR    ......................................
void currenT() {
  
    emon1.calcVI(20, 2000);        // Calculate all. No.of half wavelengths (crossings), time-out
    float currentDraw            = emon1.Irms;             //extract Irms into Variable

    Serial.print("                                       Current Read: ");
    Serial.println(currentDraw);

    if (currentDraw > 12){
      AConoff = 0;                 //..... ON  ....
     Serial.println("  Power is ON  AConoff is 0 ");
     

    }
    else {
      AConoff = 1;               //..... OFF  ....
        Serial.println("  Power is OFF  AConoff is 1 ");
    }


    int temp1 = ((statioN*10)+(AConoff));
//Serial.print("statioN  ");Serial.print(statioN);Serial.print("  * 100  ");Serial.print(" + ");Serial.print("  AConoff  ");Serial.print(AConoff);Serial.print(" = ");



Serial.print(" Send back to TX   ");Serial.println(temp1);

delay(2000);
    String send1 = String(temp1);
  //  Serial.print("  AC  On Off is "); Serial.println(send1);
    sendMessage(send1);                 //   SEND BACK TO TX
Serial.print("   ****SENT MESSAGE BACK TO TX***");Serial.println(temp1);



    delay(500);
 
}
//...................................................................   OUTGOING DATA   .....................................
void sendMessage(String outgoing) {

  if (reC > 200) {

    //Serial.print("Current: ");
    //Serial.println(currentDraw);
    LoRa.beginPacket();
    LoRa.write(destinationAddress);
    LoRa.write(localAddress);
    LoRa.write(outgoing.length());
    LoRa.print(outgoing);
    LoRa.endPacket();
    //Serial.print("                           sending back   " ); Serial.println(outgoing);

    
  }
}
//...................................................................   INCOMING DATA   ............................................
void receiveMessage(int packetSize) {
  //Serial.print(" packet Size is  ");Serial.println(packetSize);
  if (packetSize == 0) return;
  int recipient = LoRa.read();
  byte sender = LoRa.read();
  byte incomingLength = LoRa.read();

  String incoming = "";

  while (LoRa.available()) {
   
    incoming += (char)LoRa.read();
  }

  reC = incoming.toInt();
  //Serial.print("   REC  "); Serial.println(reC);
 
  station();

}

//....................................................................   STATIONS   .............................................
void station() {
 if  ((reC > 229) && (reC <252))//  CHANGE TO  >229 & < 252 when using RX as Tank Fill and Fruit trees (230 to 250)
 
 {
  
    Serial.println(reC);
    statioN = ((reC / 10));
    onofF   = (reC - ((reC / 10) * 10));

   // Serial.print("   Station Received is   "); Serial.println(statioN);
    //Serial.print("   Station onoff is       "); Serial.println(onofF);

    if (onofF == 0) {
      digitalWrite((statioN), LOW);// Turn ON Relay
      //Serial.print (statioN); Serial.print (" Relay is ON");
    }

    if (onofF == 1) {
      digitalWrite((statioN), HIGH);// Turn OFF Relay
     // Serial.print (statioN); Serial.println (" Relay is OFF");
     
    }
     currenT();
 }
}
//....................................................................   VOID LOOP   .............................................
void loop() {

  receiveMessage(LoRa.parsePacket());     //    RECEIVE MESSAGE



type or paste code here

 


    
   

  

} here

//................................................................. TX SENDER ..........................................

#include <SPI.h>
#include <LoRa.h>
//................................................................. RTC DS 3231 ............
#include <Wire.h>
#include <ds3231.h>
struct ts t;

//................................................................ LORA ADDRESSES .............
byte localAddress = 0xAA;
byte destinationAddress = 0xBB;
long lastSendTime = 0;
long lastSendTime1 = 0;
unsigned int interval = 10000;
unsigned int interval1 = 0;

//................................................................ VARIABLES
int count = 0; unsigned int staT = 220; // OUTGOING
int countRec = 0; int staTRec = 0; // INCOMING
int statioN = 0; // STATION NUMBER 22 to 33
int onofF = 0; // 0 = ON ... 1 = OFF
int daY = 0; int houR = 0; int miN = 0; int seC = 0;
int MINUTE = 0;
int SECOND = 0;
int adjtime = 59;// Delete after test Set to current minute for sequental station test
int NexNo = 0;
long int pco = 0;
long int fonT = 0;
long int reC = 0;

//________________________________________________________________________________________________________________
//_______________________________________________________________________________________ VOID SETUP __________
void setup() {
Serial.begin(9600);
//.............................................................. RTC START ............
Serial2.begin(9600); // Use Pins 16 & 17 for Serial2
Wire.begin();
DS3231_init;
//.............................................................. SET TIME ...........
//t.hour = 16; t.min = 7; t.sec = 10; t.mday = 6; t.mon = 11; t.year = 2021;
//DS3231_set(t);
//.............................................................. LED SETUP .......................

//............................................................. STARTING LORA ....................
Serial.println("Start LoRa duplex TX Sender");
if (!LoRa.begin(915E6)) {
Serial.println("LoRa init failed. Check your connections.");
while (true) {}
}
//............................................................... LED SETUP ......................
pinMode(22, OUTPUT); digitalWrite(22, HIGH); delay(1000); digitalWrite(22, LOW);
}

//........................................................................... VOID NEXTION END ROUTINE ..............
void NexEnd() {
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);

}
void neXtimE() {

Serial2.print(F("t0.txt="")); // make sure t number is correct
Serial2.print(F("Time "));
Serial2.print(houR);
Serial2.print(F(":"));
Serial2.print(miN);
Serial2.print(F("""));
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);
}

//.............................................................. CHANGE NEXTION ATTRIBUTES .........................
void neXAttrib()
{

//Serial.print(" NexNo ");Serial.print( NexNo );Serial.print(" fonT ");Serial.print( fonT );Serial.print(" pc0 ");Serial.println(pco);
Serial2.write('n');
Serial2.print(NexNo);

Serial2.print(F(".pco="));
Serial2.print(pco);
NexEnd();
Serial2.write('n');
Serial2.print(NexNo);

Serial2.print(F(".font="));
Serial2.print(fonT);
NexEnd();
}
//.............................................................. VOID TIME PRINT OUT ...........

//.............................................................. VOID SENDING DATA ...........................
void senddatA()
{
if (millis() - lastSendTime > 2000) {
String sensorData = String(staT);

sendMessage(sensorData);
Serial.print("  SENT            " + sensorData); Serial.print("               at  "); Serial.print(houR); Serial.print(":"); Serial.print(miN); Serial.print(":"); Serial.println(seC);
// Serial.print(" from 0x" + String(localAddress, HEX));
// Serial.println(" to 0x" + String(destinationAddress, HEX));
lastSendTime = millis();

}
}
//............................................................. VOID SEND MESSAGE .............................
void sendMessage(String outgoing) {

LoRa.beginPacket();
LoRa.write(destinationAddress);
LoRa.write(localAddress);
LoRa.write(outgoing.length());
LoRa.print(outgoing);
LoRa.endPacket();
delay(500);

}
//............................................................. VOID RECEIVING MESSAGE .........................
void receiveMessage(int packetSize) {
if (packetSize == 0) return;
int recipient = LoRa.read();
byte sender = LoRa.read();
byte incomingLength = LoRa.read();
String incoming = "";
while (LoRa.available()) {
incoming += (char)LoRa.read();
delay(500);
reC = incoming.toInt();

}
if (incomingLength != incoming.length()) {
//Serial.println("Error: Message length does not match length");
return;
}
if (recipient != localAddress) {
//Serial.println("Error: Recipient address does not match local address");
return;
}

Serial.print(" reC is "); Serial.println(reC);

NexNo = reC / 100;

// Serial.print (" NEXNO STAT is "); Serial.println(NexNo);
onofF =(reC-(NexNo*100));
//Serial.print (" Station is ( 0 is ON 1 is OFF) "); Serial.println(onofF);
if(onofF==0){
//Serial.print(NexNo);Serial.println(" CHANGE TO GREEN");
pco = 2016;
neXAttrib();
}

station();
}
//............................................................. VOID STATION ..............................
void station() {

/* //............................................................ Station 22
if (miN == (adjtime + 0)) {
staT = 220;
senddatA();
NexNo = (staT / 10);
fonT = 1; // Large Font
if (onofF==0){
pco = 2016;
}
else{
pco = 63504; // RED
}
neXAttrib();
}
if (miN == (adjtime + 1)) {
staT = 221;
senddatA();
NexNo = (staT / 10);
fonT = 3; // Small Font
pco = 65535; // WHITE
neXAttrib();
}

//............................................................ Station 23
if (miN == (adjtime + 2)) {
staT = 230;
senddatA();
NexNo = (staT / 10);
fonT = 1; // Large Font
if (onofF==0){
pco=2016;
}
else{
pco = 63504; // RED until ONOFF CHANGES TO "0"
}

neXAttrib();

}
if (miN == (adjtime + 3)) {
staT = 231;
senddatA();
NexNo = (staT / 10);
fonT = 3; // Small Font
pco = 65535; // WHITE
neXAttrib();

}

//............................................................ Station 24
if (miN == (adjtime + 4)) {

staT = 240;
senddatA();
NexNo = (staT / 10);
fonT = 1; //   Large Font
if (onofF == 0) {
  pco = 2016;
}
else {
  pco = 63504;  //  RED  until ONOFF CHANGES TO "0"
}

neXAttrib();

}
if (miN == (adjtime + 5)) {
staT = 241;
senddatA();
NexNo = (staT / 10);
fonT = 3; // Small Font
pco = 65535; // WHITE
neXAttrib();
}

//............................................................ Station 25
if (miN == (adjtime + 6)) {
staT = 250;
senddatA();
NexNo = (staT / 10);
fonT = 1; // Large Font
if (onofF == 0) {
pco = 2016 ;
}
else {
pco = 63504; // RED until ONOFF CHANGES TO "0"
}

neXAttrib();

}
if (miN == (adjtime + 7)) {
staT = 251;
senddatA();
NexNo = (staT / 10);
fonT = 3; // Small Font
pco = 65535; // WHITE
neXAttrib();
}
*/

//............................................................   Station 26  ..  Fr. ENTRY GARDEND
if (miN == (adjtime + 0)) {
staT = 260;
senddatA();
NexNo = (staT / 10);
fonT = 1; //   Large Font
pco = 63504;  //  RED
neXAttrib();

}
if (miN == (adjtime + 1)) {
staT = 261;
senddatA();
NexNo = (staT / 10);
fonT = 3; //   Small Font
pco = 65535;  //  WHITE
neXAttrib();
}
//............................................................   Station 27   .. N.W.GARDENS
if (miN == (adjtime + 2)) {
staT = 270;
senddatA();
NexNo = (staT / 10);
fonT = 1; //   Large Font
pco = 63504;  //  RED
neXAttrib();
}
if (miN == (adjtime + 3)) {
staT = 271;
senddatA();
NexNo = (staT / 10);
fonT = 3; //   Small Font
pco = 65535;  //  WHITE
neXAttrib();
}
//............................................................   Station 28  ..  N.E.GARDENS
if (miN == (adjtime + 4)) {
staT = 280;
senddatA();
NexNo = (staT / 10);
fonT = 1; //   Large Font
pco = 63504;  //  RED
neXAttrib();

}
if (miN == (adjtime + 5)) {
staT = 281;
senddatA();
NexNo = (staT / 10);
fonT = 3; //   Small Font
pco = 65535;  //  WHITE
neXAttrib();
}
//............................................................   Station 29  .. GARDENS ( EAST  & FISH POND)
if (miN == (adjtime + 6))
{
staT = 290;
senddatA();
NexNo = (staT / 10);
fonT = 1; //   Large Font
pco = 63504;  //  RED
neXAttrib();

}
if (miN == (adjtime + 7))
{
staT = 291;
senddatA();
NexNo = (staT / 10);
fonT = 3; //   Small Font
pco = 65535;  //  WHITE
neXAttrib();
}
//............................................................   Station 30  ..  EAST LAWNS
if (miN == (adjtime + 8))
{
staT = 300;
senddatA();
NexNo = (staT / 10);
fonT = 1; //   Large Font
pco = 63504;  //  RED
neXAttrib();

}
if (miN == (adjtime + 9))
{
staT = 301;
senddatA();
NexNo = (staT / 10);
fonT = 3; //   Small Font
pco = 65535;  //  WHITE
neXAttrib();
}
//............................................................   Station 31  ..  EAST FISH POND
if (miN == (adjtime + 10))
{
staT = 310;
senddatA();
NexNo = (staT / 10);
fonT = 1; //   Large Font
pco = 63504;  //  RED
neXAttrib();

}
if (miN == (adjtime + 11))
{
staT = 311;
senddatA();
NexNo = (staT / 10);
fonT = 3; //   Small Font
pco = 65535;  //  WHITE
neXAttrib();
}

//............................................................   Station 32  ..  WEST HOUSE GARDEN BEDS
if (miN == (adjtime + 10))
{
staT = 320;
senddatA();
NexNo = (staT / 10);
fonT = 1; //   Large Font
pco = 63504;  //  RED
neXAttrib();

}
if (miN == (adjtime + 11))
{
staT = 321;
senddatA();
NexNo = (staT / 10);
fonT = 3; //   Small Font
pco = 65535;  //  WHITE
neXAttrib();
}

}

//_________________________________________________________________________________________________________________
//_________________________________________________________________________ VOID LOOP ___________
void loop() {

// station(); // TEST ONLY

staT = 230; // TEST ONLY
senddatA(); // TEST ONLY

//............................................................ GET TIME .................
DS3231_get(&t);
daY = (t.mday); houR = (t.hour); miN = (t.min); seC = (t.sec);

//............................................................ RECEIVING DATA .....................

receiveMessage(LoRa.parsePacket());
neXtimE();
}

Hi,

A circuit diagram and a picture(s) of your project may help.

Do Duinotech supply some example code to test their product?
Have you some basic code to test your project?
Does your code work when configured back before the NEXTION screen.

Tom... :smiley: :+1: :coffee: :australia:
PS. Can you please go back and in post #4, place your code in code tags.

There is a 'LoRaDuplex' example in that library, does that work fine as well ?

Tom Thanks. The code worked fine before I started messing with "Nextion" however the code above is a copy of the original code that worked just fine before "Nextion". It was saved to an
external USB stick and Should????? work when loaded back into Arduino. But it don't.
I have tried to use the examples on the Lora library and both TX and RX work fine one way.
I have tried the " LoRa Duplex " and it transmits OK but then gives me an error

"error:message length does not match length"
I am also having trouble identifying the Lora shield pins.
On the Duinotech documents it seems a little confusing to a "noob" like me.

Instead of pins CSN, CE, SCK, MOSI and MISO
they indicate pinout as
Chip reset = D9, DIO0 = D2, DIO5 = D8, DIO2 = D7 and DIO1 = D6

SRNET Thanks

I have tried the " LoRa Duplex " and it transmits OK but then gives me an error

"error:message length does not match length"

Sound maybe like you have poor reception.

When TX and RX are say 5M appart what RSSI and SNR do you get on RX ?

On the tX rx examples it show s between 45 and 65 RSSi.

For my testing both units ate in the same room

I have even tried turning off my mobile , Bluetooth and wireless router but that made
no difference.

I live in a country enviroment so would not think I have any external inteference,

In the Lora Duplex example I had to delete this code to get get a connection

"" // override the default CS, reset, and IRQ pins (optional)
//LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin""

I have also tried moving the TX and RX further away from each other up to a max of about 6 metres.
Have also tried the duplex example on a "UNO" and I dont even get an "Error message" back. just the Serial print of the "Send.

Can you give me any info on the Lora shield pinout in CS SCK MMISO and MOSI format so that i can check for pin conflict in the "EXAMPLE CODE"

Nope, dont have one.

Ask the supplier of the shield, if you dont have the connection details.

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