LoRa does not transmitting the required data

Hello Guys , I need a little help with this.

I am working on a LoRa based project for transmitting data between two LoRa devices. I am using serial communication to receive data from sensors and transmit them to the receiver. when I am using Rx - Tx port from sensors to transmitter it shows me data correctly. But it does not transmit data to the LoRa receiver. But when I am using Rx - Rx port from sensors to LoRa transmitter, it transmitting data to the loRa receiver. but does not show the correct the correct data. Here I will post the arduino Tx code and Rx code. If someone can help with it, really appreciated.

//-------------------------------------
// TX: Reads Serial port and generates a message to transmit
//
// A Message Passing System
// Format is NODEID, msgSeq, ttl, messageType, Data I5, I5, I5, I5, I5
// NODEID is this transceiver number
// msgSeq is sequence number, used to determine if this message has already been seen
// ttl is time to live, decremented by each node and not forwarded if zero
// messageType (0=reset,1=data)
// message is digital data
//-------------------------------------

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

int NODEID = 1; // Node number 0 to 100 for transmitter
int SLOTTIME = 0; //waiting time 0 for transmitter.
int msgSeq = 0; //highest message sequence number encountered since last Reset. Reset sets it to zero
int TTL = 5; //default time to live
RH_RF95 rf95; //Singleton instance of radio driver
int led = 13; //Define LED pin used to demonstrate activity
char messageChars[20]; //Initial variable to store received data
int messageNum; //Number extracted from message to transmit
int address, slottime; //Parameters written to eeprom previously

void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("TxV3");
while (!Serial)
Serial.println("Waiting for serial port"); //Wait for serial port to be ready.

// EEPROM.write(0, 1);
// EEPROM.write(1, 0);
address = EEPROM.read(0);
slottime = EEPROM.read(1);
Serial.print("address "); Serial.println(address); Serial.print("slot ");Serial.println(slottime);
if (address > 0) NODEID = address;
if (slottime > 0) SLOTTIME = slottime;

while (!rf95.init())
{
Serial.println("Initialisation of LoRa receiver failed");
delay(1000);
}
// Initialise Transmitter
rf95.setFrequency(915.0); //Use 915 MHz
rf95.setTxPower(23, false); //Set to highest allowable power 23 dBm
rf95.setModemConfig(RH_RF95::Bw500Cr45Sf128); //500 kHz band SF of 7 (128 chips / symbol)

// Send a 'Reset' out to all nodes to reset counters
char str[80];
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
sprintf(str, "%5d %5d %5d %5d %5d", NODEID, 0, TTL, 0, 0);
for (int i = 0; i < 80; i++)
buf[i] = str[i];
Serial.println((char*)str); //Display reset message on console
digitalWrite(led, HIGH); //LED to show activity
rf95.send(buf, sizeof(buf)); //Send the message
rf95.waitPacketSent(); //Wait until sent before continuing
digitalWrite(led, LOW); //LED off to show end of activity
}

void loop()
{
// Get data from Serial if there's some there. Can maybe attach an interrupt to this rather than looping.
while (Serial.available() == 0)
delay(100); //wait 100 ms then see if a message has arrived

// Available is zero until there's a message to read
Serial.readBytes(messageChars,20); //Read the serial data and store in var
sscanf(messageChars, "%5d", &messageNum); //Format of message is a single digit in a 5 wide field

// Format message to send to receiver
char str[80];
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];

// Increment sequence number
msgSeq = (msgSeq + 1);
int msgType = 1; //Data message
sprintf(str, "%5d %5d %5d %5d %5d", NODEID, msgSeq, TTL, msgType, messageNum);
for (int i = 0; i < 80; i++)
buf[i] = str[i];

// Transmit message
Serial.println((char*)str); //Display message on console (DEBUG)
digitalWrite(led, HIGH); //LED to show activity
rf95.send(buf, sizeof(buf)); //Send the message
rf95.waitPacketSent(); //Wait until sent before continuing
digitalWrite(led, LOW); //LED off to show end of activity
}

//-------------------------------------
// RX: Reads LoRa messages prints out Serial
//
// A Message Passing System
// Format is NODEID, msgSeq, ttl, messageType, Data (Each integer, field of 5 wide I5, I5, I5, I5, I5)
// NODEID is this transceiver number
// msgSeq is sequence number, used to determine if this message has already been seen
// ttl is time to live, decremented by each node and not forwarded if zero
// messageType (0=reset,1=data)
// message is digital data
//-------------------------------------

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

int NODEID = 201; // Node number 200+ for receiver
int SLOTTIME = 0; //Slot time for receiver
int maxSeq = 0; //highest message sequence number encountered since last Reset. Reset sets it to zero
int TTL = 5; //default time to live
RH_RF95 rf95; //Singleton instance of radio driver
int led = 13; //Define LED pin used to demonstrate activity
char messageChars[20]; //Initial variable to store received data
int address, slottime; //Parameters written to eeprom previously

void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("RxV3");
while (!Serial)
Serial.println("Waiting for serial port"); //Wait for serial port to be ready.
// EEPROM.write(0, 201); //Receiver address is 200+
// EEPROM.write(1, 0);
address = EEPROM.read(0);
slottime = EEPROM.read(1)*1000;
if (address > 0) NODEID = address;
if (slottime > 0) SLOTTIME = slottime;

Serial.print("address ");
Serial.println(address);
Serial.print("slottime ");
Serial.println(slottime);

while (!rf95.init())
{
Serial.println("Initialisation of LoRa receiver failed");
delay(1000);
}
// Initialise Transmitter
rf95.setFrequency(915.0); //Use 915 MHz
rf95.setTxPower(23, false); //Set to highest allowable power 23 dBm
rf95.setModemConfig(RH_RF95::Bw500Cr45Sf128); //500 kHz band SF of 7 (128 chips / symbol)

//Send a 'Reset' out to all nodes to reset counters (should factor code. Some duplication)
char str[80];
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
sprintf(str, "%5d %5d %5d %5d", NODEID, 0, TTL, 0);
for (int i=0; i < 80; i++)
buf[i] = str[i];
Serial.println((char*)str); //Display reset message on console
digitalWrite(led, HIGH); //LED to show activity
rf95.send(buf, sizeof(buf)); //Send the message
rf95.waitPacketSent(); //Wait until sent before continuing
digitalWrite(led, LOW); //LED off to show end of activity
}

void loop()
{
// Get data from LoRa transceiver if available
while (rf95.available() == 0); // Do nothing until something available

uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len)) //Message available
{
Serial.print("Received message : "); //DEBUG
Serial.println((char*)buf); //DEBUG
digitalWrite(led, HIGH);
}
else
Serial.println("recv failed");

char str[80]; // Unpack message
for (int i=0; i < 80; i++)
str[i] = buf[i];

// Now extract subfields 

int sourceNode, msgSeq, ttlReceived, msgType, msgNum; //source, sequence, ttl, type, numeric data;
Serial.println(str); //DEBUG
sscanf(str, " %5d %5d %5d %5d %5d", &sourceNode, &msgSeq, &ttlReceived, &msgType, &msgNum);
if (msgType == 0) { // A reset message. Set sequence number to zero
msgSeq = 0;
maxSeq = 0;
}
if ((msgSeq > maxSeq) && (ttlReceived > 0) && (msgType ==1)) //New data message. Send it out Serial.
Serial.println(msgNum);

maxSeq = msgSeq; // Update message sequence numbers
digitalWrite(led, LOW);
}

Hi, @kithmini
To add code please click this link;

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

Does the basic client and server examples provided for that library work with your hardware ?

Where did you get the code you posted from ?

Please edit your post to place the code within code tags ("</>" editor button.

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