Hello,
I built an application that connects between a gateway and a node. Both stations contains ESP32 and LoRa SX1276. I used Ping-Pong example as a base and added to the gateway deep sleep from another example. All the LoRa mechanisms are handled by the LoRa library. I used both Heltec’s and Sandeep Mistry’s libraries – they both worked well.
The algorithms are simple:
- The receive is initiated by an interrupt, and so is the completion of the transmission.
- The gateway creates a string, transmits it, waits for the reception of the reply, and presents it.
- The node loop simply retransmit the received command.
I measure the following parameters:
- Error rate – the count of defected messages that returned to the gateway. Result – 0 out of more than 30,000 cycles. Conclusion - the algorithm is stable.
- Gateway: Delay from the wake-up from the deep sleep to the start of next deep sleep. This period is over 3500 milliseconds.
- Gateway: Delay between the end of endPacket method to the end of the string receive. This period equals to the previous parameter, meaning the string handling is less than 1 millisecond.
- Node: cycle time from the receiver interrupt until the end of transmission interrupt. Result over 1730 milliseconds.
My conclusion is that every transmission or reception need ~870 milliseconds to complete. This performance is unacceptable . How can I improve it?
Regards
Yona
Gateway:
> /*********************************************************/
> void setup()
> {
> if(!LoRaBegin(917E6))
> {
> Serial.println(“LoRa init failed. Check your connections.”);
> while (true);
> TxFlag = false;
> }
> //--------------------------------------------
> Serial.begin(9600); // initialize serial
> while (!Serial);
> pinMode(LED, OUTPUT);
> startRun = millis();
> currentMillis = millis();
> messageReceived = false;
> Serial.println(“LoRa init succeeded - Simple gateway”);
> }
> /*********************************************************/
> void loop()
> {
> overallCycleTime = millis();
> esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
> if(wakeup_reason != 4)
> {
> Serial.println(“Wakeup was not caused by timer:” + String(wakeup_reason) +
> " RxFalg/TxFlag=" + String(messageReceived) + “/” + String(TxFlag) +
> “. Returning to sleep mode”);
> esp_sleep_enable_timer_wakeup(interLoopsInterval * USEC_PER_SECOND);
> esp_deep_sleep_start();
> }
>
> // Serial.println("\n"); // TP loop start
>
> // Create command -----------------------------------------
> messagesCounter++;
> masterCommand = “014” + String(messagesCounter)+ “FCSch”;
>
> // Transmit -----------------------------------------------
> LoRa_sendMessage(masterCommand);
> Serial.println(“Loop 7: Sent message=|” + masterCommand + “|”);
> digitalWrite(LED, !digitalRead(LED));
>
> // Wait for the transmit time, node side processing and receive processing
> currentMillis = millis();
> while ( ((millis() - currentMillis) < (interLoopsInterval * MSEC_PER_SECOND))&&!messageReceived)
> ; // Wait for the reply
>
> if(messageReceived) {
> messageReceived = false;
> if(receivedRetransmission == masterCommand)
> Serial.println(“Retransmission successful; Loop time=” + String(millis() - currentMillis));
> else
> Serial.println(“Retransmission corrupted (” + String(++errorsCounter) +
> “) - received : |” + receivedRetransmission + “|”);
> }
> else
> Serial.println(“Retransmission failed”);
> Serial.println(“With " + String(errorsCounter) + " accumulated errors out of " + String(messagesCounter) + " loops”);
>
> // Gotodeep sleep ----------------------------------------
> Serial.println(“Loop time=” + String(millis() - overallCycleTime));
> Serial.println(“Set sleep time of " + String(interLoopsInterval) + " Seconds\n”);
> esp_sleep_enable_timer_wakeup(interLoopsInterval * USEC_PER_SECOND);
> esp_deep_sleep_start();
> }
Node
/*********************************************************/
void setup()
{
Serial.begin(9600); // initialize serial
delay(1000);
LoRa.setPins(csPin, resetPin, irqPin);
if (!LoRa.begin(frequency))
{
Serial.println(“LoRa init failed. Check your connections.”);
while (true); // if failed, do nothing
}
LoRa.setTxPower(6);
LoRa.setSpreadingFactor(11);
LoRa.setSignalBandwidth(41700);
LoRa.setCodingRate4(5);
LoRa.setSyncWord(0x43);
LoRa.setPreambleLength(8);
LoRa.enableCrc();Serial.println(“LoRa init succeeded - Node”);
startRun = millis();
messageReceived = false;LoRa.onReceive(onReceive);
LoRa.onTxDone(onTxDone);
LoRa.receive();
}
/*********************************************************/
void loop()
{
if(messageReceived)
{
messageReceived = false;
Serial.println(masterCommand + “| - Retransmit\n”);
LoRa_sendMessage(masterCommand); // send a message
}
}
/*********************************************************/
void LoRa_sendMessage(String message)
{
LoRa.idle(); // set tx mode
LoRa.beginPacket(); // start packet
LoRa.print(message); // add payload
LoRa.endPacket(true); // finish packet and send it
}
/*********************************************************/
void onTxDone()
{
// Serial.println(“TxDone”);
Serial.println("; Loop time=" + String(millis() - timeCounter));
LoRa.receive();
}
/*********************************************************/
void onReceive(int packetSize)
{
// Serial.println(“onReceive”);
timeCounter = millis();
masterCommand = “”;
while (LoRa.available())
masterCommand += (char)LoRa.read();
messageReceived = true;
}