Cannot register LoRa to TTN | H7 Portenta Vision Shield

Hi, I got myself an H7 Portenta with LoRa Vision Shield. I am closely following the official tutorial
on AU915 regional band. However, when I run the program after entering appropriate band=BAND_AU915, appEui and AppKey I get the following error:

LoraError: Failed to set autoband

Can someone please guide me to get started? Is there a different tutorial by OpenMV that I can follow to better understand how to fix the issue? Is there any official documentation at least?

Regards,
Prithul

@iabdalkader - Can you help on this?

I don’t know much about Lora, I just ported/implemented the driver to support the custom Arduino Lora firmware. Perhaps try to update/install the Lora firmware from the Arduino IDE ?

One thing to test is to see if what you want to do works with Arduino driver/sketch/firmware, if so then it’s likely our driver that’s broken.

Thanks for the response, Ibrahim! I’ll try using Arduino sketch and get back to you.

I intend to use my H7 Portenta Vision Shield for a deep learning project with LoRa. If LoRa does not work on OpenMV, I will have to make a solid decision and move everything to Arduino, which is of course painful given I have things ready to work in Python. Your support is critical for me, thanks for being involved.

Regards,
PC

Hi,

I tried this using Arduino IDE and it worked. I wouldn’t say it’s perfect because sometimes it does not relay data to TTN, but that’s a connection issue I suppose. OpenMV way of doing this still isn’t working.

Regards,
PC

Can you post the Arduino sketch and the Python script ? Just the function that’s not working.

Hi Ibrahim,

The Arduino script is basically the example file ‘LoraSendAndReceive.ino’ with my device’s creds and AU915 band. Here you go:

/*
  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 = "0000000000000000";
String appKey = "D9032D90CD8EC3F889CF329AE180C28C";

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(AU915)) {
    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) {
    Serial.println("Something went wrong; are you indoor? Move near a window and retry");
    while (1) {}
  }

  // Set poll interval to 60 secs.
  modem.minPollInterval(60);
  // 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();
}

Similarly for the Python script, I am running the example program as follows. Getting the error in Lora() itself:

from lora import *

lora = Lora(band=BAND_AU915, poll_ms=60000, debug=False)

print("Firmware:", lora.get_fw_version())
print("Device EUI:", lora.get_device_eui())
print("Data Rate:", lora.get_datarate())
print("Join Status:", lora.get_join_status())

appEui = "0000000000000000" # Add your App EUI here
appKey = "D9032D90CD8EC3F889CF329AE180C28C" # Add your App Key here

try:
    lora.join_OTAA(appEui, appKey, timeout=20000)
    # Or ABP:
    #lora.join_ABP(devAddr, nwkSKey, appSKey, timeout=5000)
# You can catch individual errors like timeout, rx etc...
except LoraErrorTimeout as e:
    print("Something went wrong; are you indoor? Move near a window and retry")
    print("ErrorTimeout:", e)
except LoraErrorParam as e:
    print("ErrorParam:", e)

print("Connected.")
lora.set_port(3)

try:
    if lora.send_data("HeLoRA world!", True):
        print("Message confirmed.")
    else:
        print("Message wasn't confirmed")

except LoraErrorTimeout as e:
    print("ErrorTimeout:", e)

# Read downlink messages
while (True):
    if (lora.available()):
        data = lora.receive_data()
        if data:
            print("Port: " + data["port"])
            print("Data: " + data["data"])
    lora.poll()
    sleep_ms(1000)

Regards,
PC

Can you post the output you get when running the Python script ?

I don’t get any errors when I run your script, other than the timeout of course.

I’m getting a different error now surprisingly. However, here you go! Looking up how to resolve this simultaneously.

Regards,
PC

You’re getting a timeout error and then it continues to try to send data and then fails as it’s not connected. The example isn’t great, it should raise the exception again after printing the error, to stop the code from going any further.

I edited the code to understand the process better, this is what I get now

When I use Arduino and it connects sometimes, it connects quite instantly; I suppose a timeout of 20s is sufficient to connect. Do you know how I can/should further deduce the problem?

I first suspected that the issue is with the gateway, but I used this off-the-shelf device to confirm connection, and it connects without any issue.

EDIT/UPDATE:

I could, for the first time, connect to the TTN server via OpenMV. Happy about that but what bugs me is that it’s so random. I did not even touch the device or the gateway, reran the code for some 10 times and it connected this one time.

<I’m going to run it again now, let’s see what happens>

<Yep, did not connect. So random>

PC

I don’t think it’s the library, uart or any of that, the firmware does reply and it says the command timed out.

What if you try with a shorter timeout like 1-3 seconds and then try to join 10 times in a loop ? Something like:

for i in range(0, 10):
    try:
        lora.join_OTAA(appEui, appKey, timeout=3000)
        break
    except LoraErrorTimeout as e:
        if i + 1 == 10: raise(e)
        print("re-trying to join...")
        time.sleep_ms(1000)
1 Like

Hi Ibrahim, I tried this yesterday with various timeouts and found that it sometimes connects when it attempts to connect multiple times. Guess it’s got something to do with the connection, which puzzles me 'cause I have a personal gateway that’s within line-of-sight. Tried this outdoors also.

PC

Note that the default timeout in the Arduino firmware is 60 seconds:

#define DEFAULT_JOIN_TIMEOUT 60000L

Not that you should use that, I think shorter timeout + multiple attempts is better.

1 Like

Would like to add that I experimented with another antenna, particularly this one, to realise it’s much better for LoRa than what comes with the H7 Portenta. At least one of the official tutorials mentions that the UFL Antenna of the H7 should be fine, but I suppose it’s not the best option to go ahead with.

Hope this helps someone in the future!

Regards,
PC

I think the antenna that comes with Portenta, Giga, Nicla etc… is intended for WiFi, and Lora is sub-gigahertz. The tutorial you’ve referenced, recommends this one Dipole Pentaband Waterproof Antenna — Arduino Official Store in the required hardware section.
Anyway, I’m glad it works.

I just tested the LoRa-E5 based breakout to realise how quickly and smoothly it connects to TTN in the first try itself. To further test if the issue is the antenna, I used Portenta’s antenna here to experience the same. I have ordered a dipole antenna as per official suggestions to do one last test.

Although Portenta Vision Shield’s LoRa connects eventually after n tries, I am hesitant to use this in my field project due to reliability issues.

PC

Hi all, I could finally get this working by switching the frequency plan to AS923 (from AU915) on the Portenta and Gateway (on gateway’s hard settings and its registration on TTN). This is a very Australia-specific problem.

I’ve tested several antennas for this and can confirm that the antenna that comes with the Portenta is good enough.

One disadvantage in my situation here is that I cannot leverage on gateways installed by others since most of them are on AU915, but that’s okay.

PC