Hello all,
I’m using the Heltec LoRa32 V2 module for few applications that requires one to many communications. The gateway always initiates the communication while the addressed node is expected to respond with a message. Currently I’m still trying unsuccessfully to establish stable data interchange between the gateway and a single node.
My development environment is Arduino IDE 1.8.16 running Windows 10, and the latest revision of Heltec’s library (Nov 11, 2021).
I started from the LoRaMultipleCommunicationInterrupt example . To maintain mobility of the code I extracted the LoRa driver to a mid-level library that includes the set-up, transmit and receive sections. This library is common to both sketches.
The problem is that there is that the receiver of the node does receive the transmissions of the gateway, although I minimized the loops to minimum. I can’t determine whether the transmitter doesn’t transmit or the receiver doesn’t receive. I tried to replace the HW modules, and checked the code without success.
Since the setup is identical to both sides, I guess that the possible problem is either in the transmit or receive methods.
I’d appreciate your help in checking these as well as mentioning any other possible reason.
Best regards
OC
Common communication code
#include “LoRa.h”
/*********************************************************/
/*********************************************************/
/*********************************************************/
/*********************************************************/
void onReceive(int packetSize)
{
Serial.println("in receive 1 ");
RxMessage = “”;
while (LoRa.available())
RxMessage += (char)LoRa.read();
messageReceived = true;
Serial.println("in receive 2 " + RxMessage);}
/*********************************************************/
void LoRa_sendMessage(String message)
{
LoRa.idle();
LoRa.beginPacket(); // start packet
LoRa.print(message); // add payload
LoRa.endPacket(false); // finish packet and send it; delay till transmission end
LoRa.receive(); // Set work mode
}
/*********************************************************/
bool LoRaHLbegin()
{
LoRa.setPins(LoRa_CS, LoRa_RST, LoRa_IRQ);
if (!LoRa.begin(stationData.frequency, true)) //stationData.TxPowerLevel > 14))
return false;LoRa.setTxPower(stationData.TxPowerLevel, RF_PACONFIG_PASELECT_PABOOST);
LoRa.setSyncWord(0x43);
LoRa.setPreambleLength(8);
LoRa.enableCrc();LoRa.setSpreadingFactor(11);
LoRa.setSignalBandwidth(35000);
LoRa.setCodingRate4(5);messageReceived = false;
LoRa.onReceive(onReceive); // Set interrupt handlers
LoRa.receive(); // Set work mode
return true;
}
Gateway code
#include “Declarations.h”
#include “LoRaHL.h”#define interLoopsInterval 5.5
/*********************************************************/
void setup()
{
Serial.begin(9600); // initialize serial
while (!Serial);
if(!LoRaHLbegin())
{
Serial.println("\nLoRa gateway init failed. Check SPI declarations.");
while (true);
}
//--------------------------------------------
messageReceived = false;
Serial.println("\nLoRa init succeeded - gateway");
}
/*********************************************************/
void loop()
{
TxMessage = “123456”;
LoRa_sendMessage(TxMessage);
Serial.println(“Loop 7: Sent message=|” + TxMessage + “|”);
digitalWrite(LED, !digitalRead(LED));// Wait for the transmit time, node side processing and receive processing
uint32_t currentMillis = millis();
while (((millis() - currentMillis) < (interLoopsInterval * MSEC_PER_SECOND)) && !messageReceived)
; // Wait for the replyif(messageReceived)
{
messageReceived = false;
Serial.print(“Retransmission successful”);
}
else
Serial.print(“Retransmission failed”);
Serial.println("; Loop time=" + String(millis()- currentMillis) + “\n”);
}
Node code
#include “Declarations.h”
#include “LoRaHL.h”/*********************************************************/
void setup()
{
Serial.begin(9600); // initialize serial
while(!Serial);
if (!LoRaHLbegin())
{
Serial.println(“LoRa init failed. Check LoRa connections.”);
while (true); // if failed, do nothing
}
Serial.println("\nLoRa init succeeded - Node");
}
/*********************************************************/
void loop()
{
if(messageReceived)
{
messageReceived = false;
LoRa_sendMessage(RxMessage); // send a message
Serial.println("Retransmit: " + RxMessage);
}
}