MKRWAN1310 connection reliability

I can't seem to solve why my MKRWAN1310 will only sometimes connect to The Things Network.

Sometimes, it will connect first try, other times will take many attempts.

For example, using this code:

/*
  Lora Send And Receive
  This sketch demonstrates how to send and receive data with the MKR WAN 1300/1310 LoRa module.
  This example code is in the public domain.
*/

#include <MKRWAN.h>

LoRaModem modem;

// Uncomment if using the Murata chip as a module
// LoRaModem modem(Serial1);

#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
String appEui = SECRET_APP_EUI;
String appKey = SECRET_APP_KEY;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial);
  // change this to your regional band (eg. US915, AS923, ...)
  if (!modem.begin(US915)) {
    Serial.println("Failed to start module");
    while (1) {}
  };
  Serial.print("Your module version is: ");
  Serial.println(modem.version());
  Serial.print("Your device EUI is: ");
  Serial.println(modem.deviceEUI());

  int connected = modem.joinOTAA(appEui, appKey);
  if (!connected) {
    while (!connected){
    Serial.println("gonna try again");
    delay(5);
    int connected = modem.joinOTAA(appEui, appKey);
  }
  }

  // Set poll interval to 60 secs.
  modem.minPollInterval(5);
  // NOTE: independent of this setting, the modem will
  // not allow sending more than one message every 2 minutes,
  // this is enforced by firmware and can not be changed.
}

void loop() {
  Serial.println();
  Serial.println("Enter a message to send to network");
  Serial.println("(make sure that end-of-line 'NL' is enabled)");

  while (!Serial.available());
  String msg = Serial.readStringUntil('\n');

  Serial.println();
  Serial.print("Sending: " + msg + " - ");
  for (unsigned int i = 0; i < msg.length(); i++) {
    Serial.print(msg[i] >> 4, HEX);
    Serial.print(msg[i] & 0xF, HEX);
    Serial.print(" ");
  }
  Serial.println();

  int err;
  modem.beginPacket();
  modem.print(msg);
  err = modem.endPacket(true);
  if (err > 0) {
    Serial.println("Message sent correctly!");
  } else {
    Serial.println("Error sending message :(");
    Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength");
    Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)");
  }
  delay(1000);
  if (!modem.available()) {
    Serial.println("No downlink message received at this time.");
    return;
  }
  char rcv[64];
  int i = 0;
  while (modem.available()) {
    rcv[i++] = (char)modem.read();
  }
  Serial.print("Received: ");
  for (unsigned int j = 0; j < i; j++) {
    Serial.print(rcv[j] >> 4, HEX);
    Serial.print(rcv[j] & 0xF, HEX);
    Serial.print(" ");
  }
  Serial.println();
}

On Serial Output I will get:

12:49:04.280 -> Your module version is: ARD-078 1.2.3
12:49:04.372 -> Your device EUI is: xxxxxxxxxxxxxxxxxx
12:50:05.466 -> gonna try again
12:51:00.439 -> gonna try again
12:52:01.501 -> gonna try again
12:53:02.551 -> gonna try again
12:54:03.627 -> gonna try again

and on things network console I will see:
image

So it looks like it is not a signal strength issue, as the join request is coming through.

Then if I change nothing, except unplug the USB power to MKRWAN1310 and plug back in, it will work... so I will see this instead:

12:54:33.511 -> Your module version is: ARD-078 1.2.3
12:54:33.605 -> Your device EUI is: xxxxxxxxxxxxxxxxxx
13:01:17.227 -> Enter a message to send to network
13:01:17.227 -> (make sure that end-of-line 'NL' is enabled)
13:01:30.457 -> 
13:01:30.457 -> Sending: worked - 77 6F 72 6B 65 64 
13:01:30.457 -> Message sent correctly!
13:01:31.569 -> No downlink message received at this time.
13:01:31.569 -> 
13:01:31.569 -> Enter a message to send to network
13:01:31.569 -> (make sure that end-of-line 'NL' is enabled)

Any ideas on what I can optimize here?

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