Arduino UNO + Dragino LoRa shield crashes

Hi. I have an Arduino UNO with a Dragino LoRa shield. If I compile it on IDE Pro, it doesn’t work, gets caught in an “EV_START” loop for why, I dont know. If I compile it in Web App Version - 6.2.1 It works, then crashes.
Here is the code -

/*******************************************************************************
  
   Hello, Ryan node v5.0

   Arduino UNO + Dragino LoRa Node

   Frequency: AU915 sub-band 1+2 (915.2 to 918.2 uplink)
   Over the Air Authentication (OTAA)
   
   The following data is required -

   1) Application EUI (APPEUI)  (This is little endian format, so it is in reverse order that the server
      provides.)

      70B3D57ED0031E90 becomes { 0x90, 0x1e, 0x03, 0xd0, 0x7e, 0xd5, 0xb3, 0x70 };

   2) Device EUI (DEVEUI)  (This is little endian format, so it is in reverse order that the server
      provides.)

      00033BBCFF12A631 becomes { 0x31, 0xa6, 0x12, 0xff, 0xbc, 0x3b, 0x03, 0x00 }
      
   3) Application Key (APPKEY) (This is little endian format)

      802D15E27A184D76F1238F3F7D2CF712 becomes { 0x80, 0x2d, 0x15, 0xe2, 0x7a, 0x18, 0x4d, 0x76, 0xf1, 0x23, 0x8f, 0x3f, 0x7d, 0x2c, 0xf7, 0x12 };

*******************************************************************************/

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>

static const u1_t PROGMEM APPEUI[8] = { 0x90, 0x1E, 0x03, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };       
static const u1_t PROGMEM DEVEUI[8] = { 0x31, 0xA6, 0x12, 0xFF, 0xBC, 0x3B, 0x03, 0x00 };
static const u1_t PROGMEM APPKEY[16] = { 0x80, 0x2D, 0x15, 0xE2, 0x7A, 0x18, 0x4D, 0x76, 0xF1, 0x23, 0x8F, 0x3F, 0x7D, 0x2C, 0xF7, 0x12 };

static uint8_t mydata[] = "Hello, Ryan!";
static osjob_t sendjob;
const unsigned TX_INTERVAL = 10;                         // Schedule TX every this-many seconds
const lmic_pinmap lmic_pins = { .nss = 10, .rxtx = LMIC_UNUSED_PIN, .rst = 9, .dio = {2, 6, 7}, };  // Pin mapping for Dragino Lora shield


void setup()
{
  Serial.begin(9600);
  Serial.println(F("Starting"));
  Serial.println(F("Loading AU915/AU921 Configuration..."));

  os_init();                                            // LMIC init
  LMIC_reset();                                         // Reset the MAC state. Session and pending data transfers will be discarded.
  LMIC_setDrTxpow(DR_SF7, 14);

  // The frequency plan is hard-coded to AU915 as used by TTN.  But the band (or selected 16 channels) is configured here!

  for (int channel = 16; channel < 72; ++channel)       // this means channels 0-15 are up in this Node
  {
    LMIC_disableChannel(channel);
  }

  LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
  do_send(&sendjob);                                    // Start job (sending automatically starts OTAA too)
}


void loop()
{
  os_runloop_once();
}


void onEvent (ev_t ev)
{
  Serial.print(os_getTime());
  Serial.print(": ");
  switch (ev)
  {
    case EV_SCAN_TIMEOUT:
      Serial.println(F("EV_SCAN_TIMEOUT"));
      break;
    case EV_BEACON_FOUND:
      Serial.println(F("EV_BEACON_FOUND"));
      break;
    case EV_BEACON_MISSED:
      Serial.println(F("EV_BEACON_MISSED"));
      break;
    case EV_BEACON_TRACKED:
      Serial.println(F("EV_BEACON_TRACKED"));
      break;
    case EV_JOINING:
      Serial.println(F("EV_JOINING"));
      break;
    case EV_JOINED:
      Serial.println(F("EV_JOINED"));
      {
        u4_t netid = 0;
        devaddr_t devaddr = 0;
        u1_t nwkKey[16];
        u1_t artKey[16];
        LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
        Serial.print("netid: ");
        Serial.println(netid, DEC);
        Serial.print("devaddr: ");
        Serial.println(devaddr, HEX);
        Serial.print("artKey: ");
        for (int i = 0; i < sizeof(artKey); ++i)
        {
          Serial.print(artKey[i], HEX);
        }
        Serial.println("");
        Serial.print("nwkKey: ");
        for (int i = 0; i < sizeof(nwkKey); ++i)
        {
          Serial.print(nwkKey[i], HEX);
        }
        Serial.println("");
      }
      Serial.println(F("Successful OTAA Join..."));
      LMIC_setLinkCheckMode(0);                                     // Disable link check validation
      break;
    /*
      || This event is defined but not used in the code. No
      || point in wasting codespace on it.
      ||
      || case EV_RFU1:
      ||     Serial.println(F("EV_RFU1"));
      ||     break;
    */
    case EV_JOIN_FAILED:
      Serial.println(F("EV_JOIN_FAILED"));
      break;
    case EV_REJOIN_FAILED:
      Serial.println(F("EV_REJOIN_FAILED"));
      break;
      break;
    case EV_TXCOMPLETE:
      Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
      if (LMIC.txrxFlags & TXRX_ACK)
        Serial.println(F("Received ack"));
      if (LMIC.dataLen)
      {
        Serial.print(F("Received "));
        Serial.print(LMIC.dataLen);
        Serial.println(F(" bytes of payload"));
      }
      os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send);     // Schedule next transmission
      break;
    case EV_LOST_TSYNC:
      Serial.println(F("EV_LOST_TSYNC"));
      break;
    case EV_RESET:
      Serial.println(F("EV_RESET"));
      break;
    case EV_RXCOMPLETE:
      Serial.println(F("EV_RXCOMPLETE"));                                                  // data received in ping slot
      break;
    case EV_LINK_DEAD:
      Serial.println(F("EV_LINK_DEAD"));
      break;
    case EV_LINK_ALIVE:
      Serial.println(F("EV_LINK_ALIVE"));
      break;
    /*
      || This event is defined but not used in the code. No
      || point in wasting codespace on it.
      ||
      || case EV_SCAN_FOUND:
      ||    Serial.println(F("EV_SCAN_FOUND"));
      ||    break;
    */
    case EV_TXSTART:
      Serial.println(F("EV_TXSTART"));
      break;
    default:
      Serial.print(F("Unknown event: "));
      Serial.println((unsigned) ev);
      break;
  }
}


void do_send(osjob_t* j) {
  // Check if there is not a current TX/RX job running
  if (LMIC.opmode & OP_TXRXPEND)
  {
    //Serial.println(F("OP_TXRXPEND, not sending"));
    Serial.print("OP_TXRXPEND, not sending; at freq: ");
    Serial.println(LMIC.freq);
  } 
  else 
  {
    // Prepare upstream data transmission at the next possible time.
    LMIC_setTxData2(1, mydata, sizeof(mydata) - 1, 0);
    Serial.print(F("Packet queued for freq: "));
    Serial.println(LMIC.freq);
  }
  // Next TX is scheduled after TX_COMPLETE event.
}


void os_getArtEui (u1_t* buf)
{
  memcpy_P(buf, APPEUI, 8);
}


void os_getDevKey (u1_t* buf)
{
  memcpy_P(buf, APPKEY, 16);
}


void os_getDevEui (u1_t* buf)
{
  memcpy_P(buf, DEVEUI, 8);
}

here is the monitor output -

StStarting
Loading AU915/AU921 Confarting
Loading AU915/AU921 Configuration…
Packet queued for iguration…
Packet queued for freq: 0
610: EV_JOINING
1971: freq: 0
610: EV_JOINING
1971: EV_TXSTART
EV_TXSTART
427049: EV_JOINED
netid: 1
dev427049: EV_JOINED
netid: 1
devaddr: 2165C96
artKey: 396A6374Aaddr: 2165C96
artKey: 396A6374A40EE8467967EBEEFDF6F8
nwkKey: 640EE8467967EBEEFDF6F8
nwkKey: 68DC7E47D2481D53F26052BCA389B3BF
8DC7E47D2481D53F26052BCA389B3BF
Successful OTAA Join…
433282
Successful OTAA Join…
433282: EV_TXSTART
: EV_TXSTART
608151: EV_TXCOMPLETE (includes 608151: EV_TXCOMPLETE (includes waiting for RX windows)
waiting for RX windows)
1233621: EV_TXSTART
Packet queu1233621: EV_TXSTART
Packet queued for freq: 915200000
ed for freq: 915200000
1417825: EV_TXCOMPLETE (includes1417825: EV_TXCOMPLETE (includes waiting for RX windows)
waiting for RX windows)
FAILURE
/tmp/176228509/custom/FAILURE
/tmp/176228509/custom/MCCI LoRaWAN LMIC library/src/lmMCCI LoRaWAN LMIC library/src/lmic/lmic_us_like.c:168
ic/lmic_us_like.c:168

Can you please suggest to me what I’m doing wrong. Many thanks. Regards

there is something fishy in the console trace you show:

 netid: 1

devaddr: 2165C96
artKey: 396A6374Aaddr: 2165C96
artKey: 396A6374A40EE8467967EBEEFDF6F8
nwkKey: 640EE8467967EBEEFDF6F8
nwkKey: 68DC7E47D2481D53F26052BCA389B3BF
(and why is there a new line here?)
8DC7E47D2481D53F26052BCA389B3BF
Successful OTAA Join…



...

in the code the only place where you print artKey and nwkKey, it’s always after printing netid and devaddr and here you have something that does not match the code at all

      Serial.println(F("EV_JOINED"));
      {
        u4_t netid = 0;
        devaddr_t devaddr = 0;
        u1_t nwkKey[16];
        u1_t artKey[16];
        LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
        Serial.print("netid: ");
        Serial.println(netid, DEC);
        Serial.print("devaddr: ");
        Serial.println(devaddr, HEX);
        Serial.print("artKey: ");
        for (int i = 0; i < sizeof(artKey); ++i)
        {
          Serial.print(artKey[i], HEX);
        }
        Serial.println("");
        Serial.print("nwkKey: ");
        for (int i = 0; i < sizeof(nwkKey); ++i)
        {
          Serial.print(nwkKey[i], HEX);
        }
        Serial.println("");
      }
      Serial.println(F("Successful OTAA Join..."));

this might indicate a buffer overflow somewhere

Its possible the compiler warning about low memory is not helping;

'Low memory available, stability problems may occur'

const unsigned TX_INTERVAL = 10;                         // Schedule TX every this-many seconds

Be aware that at a 10 second interval you can exceed your daily TTN air time allowance in 3.5 minutes.

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