Decimals, strings, and LoRa

are you powering the LoRa module? from 5V or 3.3V? I used 3.3V

I also used 3.3v for lora, I already using now my bench power supply to power my esp32

what ESP32 module are you using?

nodemcu esp32-s this one to be specific

Thank you so much @horace , it is indeed a power supply issue, and also the code you have sent earlier, I combined it with the code I am currently using and I can now receive.

My question now is how to add the 4th and the 5th node or how to add "n" number of nodes. What will I modify or will add to the receiver side to do so? I am targeting of having as much as 10 and so on.

each transmitter must have a unique NodeID

#define nodeID 1  //  <<< set up required node ID

struct __attribute__((packed)) Struct1 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node  <<<<<<<<<<<<
  int16_t seq;       // sequence number
  float distance;
  float voltage;
};
Struct1 struct1 = { 1, nodeID, 0, 1, 4.5 };  

and the receiver has a list of NodeID to poll, e.g. 3 in this case

byte nodeIDs[] = { 1, 2, 3 };   // list of nodeIDs to poll
1 Like

Ohhhh noted! Thank you so much for this one, I'll get back to you if I encountered any other problems

in the current code I am using here

// Lora transmit structure 1 Node, Arduino Mega

#include <SPI.h>
#include <LoRa.h>             //https://github.com/sandeepmistry/arduino-LoRa
#include <TinyGPS++.h>        // https://github.com/mikalhart/TinyGPSPlus
#include <Adafruit_GFX.h>     //https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h> //https://github.com/adafruit/Adafruit_SSD1306

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

#define nodeID 1      //  <<< set up required node ID

// The TinyGPS++ object
TinyGPSPlus gps;

struct __attribute__((packed)) Struct1 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node
  int16_t seq;       // sequence number
  double latitude;
  double longitude;
  uint32_t _date;
  uint32_t _time;
  uint32_t _satellites;
};

Struct1 struct1 = { 1, nodeID, 0, 0, 0, 0, 0, 0};

void setup() {
  Serial.begin(115200);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32

  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
  
  Serial1.begin(115200);
  while (!Serial)  ;
  Serial.println("LoRa Sender ");
  LoRa.setPins(53, 49, 48); // 10 for UNO, 53 for Mega
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  LoRa.onTxDone(onTxDone);    // setup callbacks
  LoRa.onReceive(onReceive);
  LoRa_rxMode();
}


void loop() {
  sendMessage();       // send a message
  delay(5000);
  while (Serial1.available() > 0){
    gps.encode(Serial1.read());
    if (gps.location.isUpdated()){
      struct1.latitude    = gps.location.lat();      // setup test values
      struct1.longitude   = gps.location.lng();
      struct1._date       = gps.date.value();
      struct1._time       = gps.time.value();
      struct1._satellites = gps.satellites.value();
    }
  }
}

// receive packet - check it is a poll 
void onReceive(int packetSize) {
  if(packetSize != 1) return;   // if not a poll packet return
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  // Display static text
  display.println("Poll Packet Received");
  display.display();
  
  Serial.print("Lora receive RSSI ");
  Serial.print(LoRa.packetRssi());
  Serial.print(" packet size ");
  Serial.print(packetSize);
  byte nodeIDreceived = LoRa.read();    // read first byte 
  Serial.print(" nodeID polled ");
  Serial.print(nodeIDreceived);
  if (nodeID == nodeIDreceived) {       // poll for this structID
    Serial.println(" sending packet!");
    sendMessage();                      // send a message
  } else Serial.println();
}

// set transmit mode
void LoRa_txMode() {
  LoRa.idle();             // set standby mode
  LoRa.disableInvertIQ();  // normal mode
}

// set receive mode
void LoRa_rxMode() {
  LoRa.disableInvertIQ();  // normal mode
  LoRa.receive();          // set receive mode
}

// send a message packet
void sendMessage() {
  LoRa_txMode();              // set transmit mode
  struct1.seq++;              // increment packet sequence number
  LoRa_txMode();                                  // set tx mode
  LoRa.beginPacket();                             // start packet
  LoRa.write((byte *)&struct1, sizeof(struct1));  // transmit packet
  // display packet contents
  //for (unsigned int i = 0; i < sizeof(struct);i++) {
  // Serial.print(' ');
  // Serial.print(((byte *) &struct1)[i]);
  //}
  LoRa.endPacket(true);     // finish packet and send it

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  // Display static text
  display.println("Sequence: " + String(struct1.seq));
  display.display();
  
}

// transmit finished - print the data 
void onTxDone() {
  Serial.print(" StructureID ");
  Serial.print(struct1.StructureID);
  Serial.print(" Node ");
  Serial.print(nodeID);
  Serial.print(" TxDone seq number ");
  Serial.print(" seq number ");
  Serial.print(struct1.seq);
  Serial.print(" latitude = ");
  Serial.print(struct1.latitude);
  Serial.print(" longitude = ");
  Serial.print(struct1.longitude);
  Serial.print(" date = ");
  Serial.print(struct1._date);
  Serial.print(" time = ");
  Serial.print(struct1._time);
  Serial.print(" no. of satellites = ");
  Serial.println(struct1._satellites);
  LoRa_rxMode();        // set receive mode
}

this part of code seem like doing noting at all

void onReceive(int packetSize) {
  if(packetSize != 1) return;   // if not a poll packet return
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  // Display static text
  display.println("Poll Packet Received");
  display.display();
  
  Serial.print("Lora receive RSSI ");
  Serial.print(LoRa.packetRssi());
  Serial.print(" packet size ");
  Serial.print(packetSize);
  byte nodeIDreceived = LoRa.read();    // read first byte 
  Serial.print(" nodeID polled ");
  Serial.print(nodeIDreceived);
  if (nodeID == nodeIDreceived) {       // poll for this structID
    Serial.println(" sending packet!");
    sendMessage();                      // send a message
  } else Serial.println();
}

because my serial print on transmitter side prints nothing

and my oled only prints the part sendMessage()

Hi again, I thought earlier that polling works fine with me but its not. That's why the display inside on void onReceive() funtion doesn't display anything. I forgot to uncomment the sendMessage(); line inside the loop. this is the codes I am currently using

// Lora transmit structure 1 Node, Arduino Mega

#include <SPI.h>
#include <LoRa.h>             //https://github.com/sandeepmistry/arduino-LoRa
#include <TinyGPS++.h>        // https://github.com/mikalhart/TinyGPSPlus
#include <Adafruit_GFX.h>     //https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h> //https://github.com/adafruit/Adafruit_SSD1306

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

#define nodeID 1      //  <<< set up required node ID

// The TinyGPS++ object
TinyGPSPlus gps;

struct __attribute__((packed)) Struct1 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node
  int16_t seq;       // sequence number
  double latitude;
  double longitude;
  uint32_t _date;
  uint32_t _time;
  uint32_t _satellites;
};

Struct1 struct1 = { 1, nodeID, 0, 0, 0, 0, 0, 0};

void setup() {
  Serial.begin(115200);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32

  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
  
  Serial1.begin(115200);
  while (!Serial)  ;
  Serial.println("LoRa Sender ");
  LoRa.setPins(53, 49, 48); // 10 for UNO, 53 for Mega
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  LoRa.onTxDone(onTxDone);    // setup callbacks
  LoRa.onReceive(onReceive);
  LoRa_rxMode();
}


void loop() {
  // sendMessage();       // send a message
  // delay(5000);
  while (Serial1.available() > 0){
    gps.encode(Serial1.read());
    if (gps.location.isUpdated()){
      struct1.latitude    = gps.location.lat();      // setup test values
      struct1.longitude   = gps.location.lng();
      struct1._date       = gps.date.value();
      struct1._time       = gps.time.value();
      struct1._satellites = gps.satellites.value();
    }
  }
}

// receive packet - check it is a poll 
void onReceive(int packetSize) {
  if(packetSize != 1) return;   // if not a poll packet return
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  // Display static text
  display.println("Poll Packet Received");
  display.display();
  
  Serial.print("Lora receive RSSI ");
  Serial.print(LoRa.packetRssi());
  Serial.print(" packet size ");
  Serial.print(packetSize);
  byte nodeIDreceived = LoRa.read();    // read first byte 
  Serial.print(" nodeID polled ");
  Serial.print(nodeIDreceived);
  if (nodeID == nodeIDreceived) {       // poll for this structID
    Serial.println(" sending packet!");
    sendMessage();                      // send a message
  } else 
  Serial.print(LoRa.packetRssi());
  Serial.println();
}

// set transmit mode
void LoRa_txMode() {
  LoRa.idle();             // set standby mode
  LoRa.disableInvertIQ();  // normal mode
}

// set receive mode
void LoRa_rxMode() {
  LoRa.disableInvertIQ();  // normal mode
  LoRa.receive();          // set receive mode
}

// send a message packet
void sendMessage() {
  LoRa_txMode();              // set transmit mode
  struct1.seq++;              // increment packet sequence number
  LoRa_txMode();                                  // set tx mode
  LoRa.beginPacket();                             // start packet
  LoRa.write((byte *)&struct1, sizeof(struct1));  // transmit packet
  // display packet contents
  //for (unsigned int i = 0; i < sizeof(struct);i++) {
  // Serial.print(' ');
  // Serial.print(((byte *) &struct1)[i]);
  //}
  LoRa.endPacket(true);     // finish packet and send it

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  // Display static text
  display.println("Sequence: " + String(struct1.seq));
  display.display();
  
}

// transmit finished - print the data 
void onTxDone() {
  Serial.print(" StructureID ");
  Serial.print(struct1.StructureID);
  Serial.print(" Node ");
  Serial.print(nodeID);
  Serial.print(" TxDone seq number ");
  Serial.print(" seq number ");
  Serial.print(struct1.seq);
  Serial.print(" latitude = ");
  Serial.print(struct1.latitude);
  Serial.print(" longitude = ");
  Serial.print(struct1.longitude);
  Serial.print(" date = ");
  Serial.print(struct1._date);
  Serial.print(" time = ");
  Serial.print(struct1._time);
  Serial.print(" no. of satellites = ");
  Serial.println(struct1._satellites);
  LoRa_rxMode();        // set receive mode
}
// Lora receiver using ESP32 with RA-02 443MHz LoRa module- polled version

// connections
// RA-02 SS   to ESP32 GPIO5
// RA-02 RST  to ESP32 GPIO16
// RA-02 DIO0 to ESP32 GPIO17
// RA-02 MOSI to ESP32 GPIO23
// RA-02 MIS0 to ESP32 GPIO19
// RA-02 SCK  to ESP32 GPIO18
// setpins() is therefore
// setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN);
// LoRa.setPins(5, 16, 17);  // for ESP32


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

// three different structures may be received
struct __attribute__((packed)) Struct1 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node
  int16_t seq;       // sequence number
  double latitude;
  double longitude;
  uint32_t _date;
  uint32_t _time;
  uint32_t _satellites;
} struct1;

struct __attribute__((packed)) Struct2 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node
  int16_t seq;       // sequence number
  double latitude;
  double longitude;
  uint32_t _date;
  uint32_t _time;
  uint32_t _satellites;
} struct2;

struct __attribute__((packed)) Struct3 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node
  int16_t seq;       // sequence number
  double latitude;
  double longitude;
  uint32_t _date;
  uint32_t _time;
  uint32_t _satellites;
} struct3;

struct __attribute__((packed)) Struct4 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node
  int16_t seq;       // sequence number
  double latitude;
  double longitude;
  uint32_t _date;
  uint32_t _time;
  uint32_t _satellites;
} struct4;

struct __attribute__((packed)) Struct5 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node
  int16_t seq;       // sequence number
  double latitude;
  double longitude;
  uint32_t _date;
  uint32_t _time;
  uint32_t _satellites;
} struct5;


// used for polling
byte nodeIDs[] = { 1, 2, 3, 4, 5 };   // list of nodeIDs to poll
byte polledOK[] = { 2, 2, 2, 2, 2 };  // indicate polling sucess/failure
int nodeIndex = 0;              // index into above arrays

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(1);
  Serial.println("LoRa Receiver ESP32 with RA-02 443MHz LoRa module");
  // void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN);

  // LoRa.setPins(10, 9, 2);  // 10 for UNO and Nano, 53 for Mega
  // LoRa.setPins(15,16,4);  // for ESP8266
  //LoRa.setPins(8,4,7);   // for Lora 32u4
  LoRa.setPins(5, 16, 17);  // for ESP32
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1) delay(10);
  }
  Serial.println("Lora Receiver started");
  LoRa.onTxDone(onTxDone);    // setup callbacks
  LoRa.onReceive(onReceive);  // set receive callback
  LoRa_rxMode();              // set receive mode
}

volatile int nodeIDdataReceived = 0, txDone = 0;  // from callbacks

void loop() {
  static long timer = millis();
  if (millis() - timer > 5000) {
    timer = millis();
    // polling nodes
    if (--polledOK[nodeIndex] == 0) {  // did last receive response?
      Serial.print("Node failed to respond to polling ID = ");
      Serial.println(nodeIDs[nodeIndex]);
      polledOK[nodeIndex] = 1;
    }
    Serial.print("polling ID = ");  // poll next node
    Serial.print(nodeIDs[nodeIndex]);
    //Serial.println(nodeIndex);
    LoRa_txMode();                   // set to transmit
    LoRa.beginPacket();              // start packet
    LoRa.write(nodeIDs[nodeIndex]);  // transmit packet
    LoRa.endPacket(true);            // finish packet and send it
    //delay(2);
    if (++nodeIndex >= sizeof(nodeIDs)) nodeIndex = 0;
  }
  //LoRa_rxMode();  // set receive mode
  if (txDone) {                       // transmit done?
    txDone = 0;
    Serial.println("  transmitted");
  }
  //delay(5000);  // polling delay
  dataReceived(nodeIDdataReceived);   // check data received?
}

// transmit finished - set indicator for loop() to print the data
void onTxDone() {
  LoRa_rxMode();  // set receive mode
  txDone = 1;
}

// set receive mode
void LoRa_rxMode() {
  LoRa.disableInvertIQ();  // normal mode
  LoRa.receive();          // set receive mode
}

// set transmit mode
void LoRa_txMode() {
  LoRa.idle();             // set standby mode
  LoRa.disableInvertIQ();  // normal mode
}

// check sequence number is correct 
void checkSeqNumber(int NodeID, int seq) {
  static int seqNumbers[] = { 0, 0, 0, 0 }, seqErrors = 0;
  if (NodeID >= sizeof(seqNumbers) / sizeof(int)) return;
  if (seq != seqNumbers[NodeID]) {  // check for sequence error!
    Serial.print("  seq number error expected ");
    Serial.print(seqNumbers[NodeID]);
    Serial.print(" received ");
    Serial.print(seq);
    Serial.print("  seq  errors ");
    Serial.println(++seqErrors);
    seqNumbers[NodeID] = seq;
  }
  seqNumbers[NodeID]++;      // next sequence nunber expected
  polledOK[NodeID - 1] = 2;  // indicate polling sucess
}


// receive packet - set indicator for loop()
void onReceive(int packetSize) {
  nodeIDdataReceived=packetSize;
}

// check if packet received (packetSize > 0)
void dataReceived(int packetSize) {
  if(packetSize==0) return;           // if no data return
  nodeIDdataReceived=0;
  Serial.print("Lora receive RSSI "); // packet received process it
  Serial.print(LoRa.packetRssi());
  Serial.print(" packet size ");
  Serial.print(packetSize);
  byte structureID = LoRa.read();  // read first byte the structure ID
  // switch to correct structure to decode
  switch (structureID) {
    case 1:
      LoRa.readBytes((byte *)&struct1 + 1, packetSize - 1);  // receive struct1 packet
      struct1.StructureID = structureID;
      // display packet
      //for (int i = 0; i < packetSize; i++) {
      // Serial.print(' ');
      // Serial.print(((byte *) &struct1)[i]);
      // }
      Serial.print(" StructureID ");
      Serial.print(struct1.StructureID);
      Serial.print(" from Node ");
      Serial.print(struct1.NodeID);
      Serial.print(" seq number ");
      Serial.print(struct1.seq);
      Serial.print(" latitude_1 = ");
      Serial.print(struct1.latitude);
      Serial.print(" longitude_1 = ");
      Serial.print(struct1.longitude);
      Serial.print(" date_1 = ");
      Serial.print(struct1._date);
      Serial.print(" time_1 = ");
      Serial.print(struct1._time);
      Serial.print(" no. of satellites_1 = ");
      Serial.println(struct1._satellites);
      checkSeqNumber(struct1.NodeID, struct1.seq);
      break;
    case 2:
      LoRa.readBytes((byte *)&struct2 + 1, packetSize - 1);  // receive struct2 packet
      struct2.StructureID = structureID;
      Serial.print(" StructureID ");
      Serial.print(struct2.StructureID);
      Serial.print(" from Node ");
      Serial.print(struct2.NodeID);
      Serial.print(" seq number ");
      Serial.print(struct2.seq);
      Serial.print(" latitude_2 = ");
      Serial.print(struct2.latitude);
      Serial.print(" longitude_2 = ");
      Serial.print(struct2.longitude);
      Serial.print(" date_2 = ");
      Serial.print(struct2._date);
      Serial.print(" time_2 = ");
      Serial.print(struct2._time);
      Serial.print(" no. of satellites_2 = ");
      Serial.println(struct2._satellites);
      checkSeqNumber(struct2.NodeID, struct2.seq);
      break;
    case 3:
      LoRa.readBytes((byte *)&struct3 + 1, packetSize - 1);  // receive struct3 packet
      struct3.StructureID = structureID;
      Serial.print(" StructureID ");
      Serial.print(struct3.StructureID);
      Serial.print(" from Node ");
      Serial.print(struct3.NodeID);
      Serial.print(" seq number ");
      Serial.print(struct3.seq);
      Serial.print(" latitude_3 = ");
      Serial.print(struct3.latitude);
      Serial.print(" longitude_3 = ");
      Serial.print(struct3.longitude);
      Serial.print(" date_3 = ");
      Serial.print(struct3._date);
      Serial.print(" time_3 = ");
      Serial.print(struct1._time);
      Serial.print(" no. of satellites_3 = ");
      Serial.println(struct3._satellites);
      checkSeqNumber(struct3.NodeID, struct3.seq);
      break;
  }
}

this are the output on the ESP32 and nothing in the arduino mega

polling ID = 1  transmitted
polling ID = 2  transmitted
polling ID = 3  transmitted
polling ID = 4  transmitted
polling ID = 5  transmitted
Node failed to respond to polling ID = 1
polling ID = 1  transmitted
Node failed to respond to polling ID = 2
polling ID = 2  transmitted
Node failed to respond to polling ID = 3
polling ID = 3  transmitted
Node failed to respond to polling ID = 4
polling ID = 4  transmitted
Node failed to respond to polling ID = 5
polling ID = 5  transmitted

in the transmitter you are callinga lot of LCD display and Serial functions in the callback routines which should be avoided (try to keep them as short as possible)
try this code - I have moved the information display into loop() with onReceive() and onTxDone() as short as possible

// Lora transmit structure 1 Node, Arduino Mega

#include <SPI.h>
#include <LoRa.h>              //https://github.com/sandeepmistry/arduino-LoRa
#include <TinyGPS++.h>         // https://github.com/mikalhart/TinyGPSPlus
#include <Adafruit_GFX.h>      //https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h>  //https://github.com/adafruit/Adafruit_SSD1306

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

#define nodeID 1  //  <<< set up required node ID

// The TinyGPS++ object
TinyGPSPlus gps;

struct __attribute__((packed)) Struct1 {
  byte StructureID;  // identifies the structure type
  byte NodeID;       // ID of transmitting node
  int16_t seq;       // sequence number
  double latitude;
  double longitude;
  uint32_t _date;
  uint32_t _time;
  uint32_t _satellites;
};

Struct1 struct1 = { 1, nodeID, 0, 0, 0, 0, 0, 0 };

void setup() {
  Serial.begin(115200);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // Address 0x3C for 128x32

  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);

  Serial1.begin(115200);
  while (!Serial)
    ;
  Serial.println("LoRa Sender ");
  LoRa.setPins(53, 49, 48);  // 10 for UNO, 53 for Mega
  //LoRa.setPins(10, 9, 2);  // 10 for UNO and Nano, 53 for Mega

  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1)
      ;
  }
  LoRa.onTxDone(onTxDone);  // setup callbacks
  LoRa.onReceive(onReceive);
  LoRa_rxMode();
}

volatile int nodeIDreceived = 0, txDone = 0;  // from callbacks

void loop() {
  // sendMessage();       // send a message
  // delay(5000);
  while (Serial1.available() > 0) {
    gps.encode(Serial1.read());
    if (gps.location.isUpdated()) {
      struct1.latitude = gps.location.lat();  // setup test values
      struct1.longitude = gps.location.lng();
      struct1._date = gps.date.value();
      struct1._time = gps.time.value();
      struct1._satellites = gps.satellites.value();
    }
  }

  // receive packet - check it is a poll
  if (nodeIDreceived) {  // if node poll received process it
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0, 0);
    // Display static text
    display.println("Poll Packet Received");
    display.display();
    Serial.print("Lora receive RSSI ");
    Serial.print(LoRa.packetRssi());
    Serial.print(" nodeID polled ");
    Serial.print(nodeIDreceived);
    if (nodeID == nodeIDreceived) {  // poll for this structID
      Serial.println(" sending packet!");
      sendMessage();  // send a message
    } else
      Serial.print(LoRa.packetRssi());
    Serial.println();
    nodeIDreceived = 0;
  }
  // transmit finished - print the data
  if (txDone) {  // if transmit complete display message
    txDone = 0;
    Serial.print(" StructureID ");
    Serial.print(struct1.StructureID);
    Serial.print(" Node ");
    Serial.print(nodeID);
    Serial.print(" TxDone seq number ");
    Serial.print(" seq number ");
    Serial.print(struct1.seq);
    Serial.print(" latitude = ");
    Serial.print(struct1.latitude);
    Serial.print(" longitude = ");
    Serial.print(struct1.longitude);
    Serial.print(" date = ");
    Serial.print(struct1._date);
    Serial.print(" time = ");
    Serial.print(struct1._time);
    Serial.print(" no. of satellites = ");
    Serial.println(struct1._satellites);
    LoRa_rxMode();  // set receive mode
  }
}

// receive packet - if a poll set nodeIDreceived for loop()
void onReceive(int packetSize) {
  if (packetSize == 1)             // if not a poll packet return
    nodeIDreceived = LoRa.read();  // read first byte
}

// set transmit mode
void LoRa_txMode() {
  LoRa.idle();             // set standby mode
  LoRa.disableInvertIQ();  // normal mode
}

// set receive mode
void LoRa_rxMode() {
  LoRa.disableInvertIQ();  // normal mode
  LoRa.receive();          // set receive mode
}

// send a message packet
void sendMessage() {
  LoRa_txMode();                                  // set transmit mode
  struct1.seq++;                                  // increment packet sequence number
  LoRa_txMode();                                  // set tx mode
  LoRa.beginPacket();                             // start packet
  LoRa.write((byte *)&struct1, sizeof(struct1));  // transmit packet
  // display packet contents
  //for (unsigned int i = 0; i < sizeof(struct);i++) {
  // Serial.print(' ');
  // Serial.print(((byte *) &struct1)[i]);
  //}
  LoRa.endPacket(true);  // finish packet and send it

  // display.clearDisplay();
  // display.setTextSize(2);
  // display.setTextColor(WHITE);
  // display.setCursor(0, 0);
  // Display static text
  // display.println("Sequence: " + String(struct1.seq));
  // display.display();
}

// transmit finished - setop loop() to print the data
void onTxDone() {
  LoRa_rxMode();  // set receive mode
  txDone = 1;
}

the transmitter serial monitor output

LoRa Sender 
Lora receive RSSI -123 nodeID polled 2-123
Lora receive RSSI -122 nodeID polled 3-122
Lora receive RSSI -123 nodeID polled 1 sending packet!

 StructureID 1 Node 1 TxDone seq number  seq number 1 latitude = 0.00 longitude = 0.00 date = 0 time = 0 no. of satellites = 0
Lora receive RSSI -118 nodeID polled 2-118
Lora receive RSSI -123 nodeID polled 3-123
Lora receive RSSI -122 nodeID polled 1 sending packet!

 StructureID 1 Node 1 TxDone seq number  seq number 2 latitude = 0.00 longitude = 0.00 date = 0 time = 0 no. of satellites = 0

1 Like

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