Connect failure RAK4630 AU915 to Everynet

I cant make it work with OTAA example code in RAK4630, and for some reason the device changes it port after it programmed (it starts with port 4 and after uploading, it is port 6) It happen always but after a couple restart/disconnect, it works again.

Setup: AU915 sub band 2 (Chile)
Running: RAK7200->Everynet Gw->Everynet
Failing: RAK4630->Everynet Gw->Everynet

Using official code: WisBlock/LoRaWAN_OTAA_ABP.ino at master · RAKWireless/WisBlock · GitHub
Testing 2nd official code (is not the same as before): WisBlock/examples/RAK4630/communications/LoRa/LoRaWAN at master · RAKWireless/WisBlock · GitHub
Testing some recommendation from: GitHub - beegee-tokyo/SX126x-Arduino: Arduino library to use Semtech SX126x LoRa chips and modules to communicate

I have tested:

  • Change many parameters code in “lmh_param_t”: nothing
  • Creating many new EUIS and keys (i know are MSB): nothings
  • Adding Radio.IrqProcess() in loop (i dont know why it exist in some example codes and others don’t)
  • Changing ChannelsMask in RegionAU915.cpp inside SX126x-Arduino library.
  • Uncomment line 45 to 47 inside Commissioning.h inside SX126x-Arduino library.


#include <Arduino.h>
#include <LoRaWan-RAK4630.h>
#include <SPI.h>

// RAK4630 supply two LED
#define LED_BUILTIN 35

#ifndef LED_BUILTIN2
#define LED_BUILTIN2 36

bool doOTAA = true;
#define SCHED_MAX_EVENT_DATA_SIZE APP_TIMER_SCHED_EVENT_DATA_SIZE /** Maximum size of scheduler events. /
#define SCHED_QUEUE_SIZE 60 /
* Maximum number of events in the scheduler queue. */
#define LORAWAN_DATERATE DR_0 /LoRaMac datarates definition, from DR_0 to DR_5/
#define LORAWAN_TX_POWER TX_POWER_5 /LoRaMac tx power definition, from TX_POWER_0 to TX_POWER_15/
#define JOINREQ_NBTRIALS 10 /**< Number of trials for the join request. */

DeviceClass_t gCurrentClass = CLASS_A; /* class definition*/
LoRaMacRegion_t g_CurrentRegion = LORAMAC_REGION_AU915; /* Region:EU868*/
lmh_confirm gCurrentConfirm = LMH_CONFIRMED_MSG; /* confirm/unconfirm packet definition*/
uint8_t gAppPort = LORAWAN_APP_PORT; /* data port*/

/**brief Structure containing LoRaWan parameters, needed for lmh_init()

// Foward declaration
static void lorawan_has_joined_handler(void);
static void lorawan_rx_handler(lmh_app_data_t *app_data);
static void lorawan_confirm_class_handler(DeviceClass_t Class);
static void send_lora_frame(void);

/**brief Structure containing LoRaWan callback functions, needed for lmh_init()
static lmh_callback_t lora_callbacks = {BoardGetBatteryLevel, BoardGetUniqueId, BoardGetRandomSeed,
lorawan_rx_handler, lorawan_has_joined_handler, lorawan_confirm_class_handler};

//OTAA keys !!! ALL KEYS ARE MSB !!!
uint8_t nodeDeviceEUI[8] = {0xc7, 0x0a, 0x53, 0x8d, 0x48, 0xae, 0xb7, 0x1a};
uint8_t nodeAppEUI[8] = {0x65, 0x26, 0x5a, 0x15, 0xab, 0x2c, 0x18, 0xa6};
uint8_t nodeAppKey[16] = {0x44, 0xaf, 0x3b, 0xc3, 0xd3, 0x25, 0x6a, 0xec, 0xfd, 0x7c, 0x35, 0x78, 0xff, 0x8a, 0x4d, 0xbe};

// Private defination
#define LORAWAN_APP_DATA_BUFF_SIZE 64 /** buffer size of the data to be transmitted. /
#define LORAWAN_APP_INTERVAL 20000 /
* Defines for user timer, the application data transmission interval. 20s, value in [ms]. */
static uint8_t m_lora_app_data_buffer[LORAWAN_APP_DATA_BUFF_SIZE]; //< Lora user application data buffer.
static lmh_app_data_t m_lora_app_data = {m_lora_app_data_buffer, 0, 0, 0, 0}; //< Lora user application data structure.

TimerEvent_t appTimer;
static uint32_t timers_init(void);
static uint32_t count = 0;
static uint32_t count_fail = 0;

void setup()
digitalWrite(LED_BUILTIN, LOW);

// Initialize LoRa chip.

// Initialize Serial for debug output
Serial.println(“Welcome to RAK4630 LoRaWan!!!”);
Serial.println(“Type: OTAA”);

#if defined(REGION_AS923)
Serial.println(“Region: AS923”);
#elif defined(REGION_AU915)
Serial.println(“Region: AU915”);
#elif defined(REGION_CN470)
Serial.println(“Region: CN470”);
#elif defined(REGION_CN779)
Serial.println(“Region: CN779”);
#elif defined(REGION_EU433)
Serial.println(“Region: EU433”);
#elif defined(REGION_IN865)
Serial.println(“Region: IN865”);
#elif defined(REGION_EU868)
Serial.println(“Region: EU868”);
#elif defined(REGION_KR920)
Serial.println(“Region: KR920”);
#elif defined(REGION_US915)
Serial.println(“Region: US915”);
#elif defined(REGION_US915_HYBRID)
Serial.println(“Region: US915_HYBRID”);
Serial.println(“Please define a region in the compiler options.”);

//creat a user timer to send data to server period
uint32_t err_code;
err_code = timers_init();
if (err_code != 0)
Serial.printf(“timers_init failed - %d\n”, err_code);

// Setup the EUIs and Keys

// Initialize LoRaWan
err_code = lmh_init(&lora_callbacks, lora_param_init,doOTAA);
if (err_code != 0)
Serial.printf(“lmh_init failed - %d\n”, err_code);

// Start Join procedure

void loop()
// Handle Radio events

/**brief LoRa function for handling HasJoined event.
void lorawan_has_joined_handler(void)
Serial.println(“OTAA Mode, Network Joined!”);

lmh_error_status ret = lmh_class_request(gCurrentClass);
if(ret == LMH_SUCCESS)
TimerSetValue(&appTimer, LORAWAN_APP_INTERVAL);

/**brief Function for handling LoRaWan received data from Gateway

  • param[in] app_data Pointer to rx data
    void lorawan_rx_handler(lmh_app_data_t *app_data)
    Serial.printf(“LoRa Packet received on port %d, size:%d, rssi:%d, snr:%d, data:%s\n”,
    app_data->port, app_data->buffsize, app_data->rssi, app_data->snr, app_data->buffer);


void lorawan_confirm_class_handler(DeviceClass_t Class)
Serial.printf(“switch to class %c done\n”, “ABC”[Class]);
// Informs the server that switch has occurred ASAP
m_lora_app_data.buffsize = 0;
m_lora_app_data.port = gAppPort;
lmh_send(&m_lora_app_data, gCurrentConfirm);

void send_lora_frame(void)
if (lmh_join_status_get() != LMH_SET)
//Not joined, try again later

uint32_t i = 0;
memset(m_lora_app_data.buffer, 0, LORAWAN_APP_DATA_BUFF_SIZE);
m_lora_app_data.port = gAppPort;
m_lora_app_data.buffer[i++] = ‘H’;
m_lora_app_data.buffer[i++] = ‘e’;
m_lora_app_data.buffer[i++] = ‘l’;
m_lora_app_data.buffer[i++] = ‘l’;
m_lora_app_data.buffer[i++] = ‘o’;
m_lora_app_data.buffer[i++] = ‘!’;
m_lora_app_data.buffsize = i;

lmh_error_status error = lmh_send(&m_lora_app_data, gCurrentConfirm);
if (error == LMH_SUCCESS)
    Serial.printf("lmh_send ok count %d\n", count);
    Serial.printf("lmh_send fail count %d\n", count_fail);


/**brief Function for handling user timerout event.
void tx_lora_periodic_handler(void)
TimerSetValue(&appTimer, LORAWAN_APP_INTERVAL);
Serial.println(“Sending frame now…”);

/**brief Function for the Timer initialization details Initializes the timer module. This creates and starts application timers. */
uint32_t timers_init(void)
TimerInit(&appTimer, tx_lora_periodic_handler);
return 0;

I will be grateful for any comments, regards.

Hello @Matias.Varas

If you are using AU915 with subband 2 (channels 8 to 15) you have to tell the library to use another subband. By default it is using subband 1 (channels 0 to 7). Short explanation

After lmh_init() and before lmh_join() add lmh_setSubBandChannels(2)

err_code = lmh_init(&lora_callbacks, lora_param_init,doOTAA);
if (err_code != 0)
   Serial.printf(“lmh_init failed - %d\n”, err_code);

// For some regions we might need to define the sub band the gateway is listening to
// This must be called AFTER lmh_init()
if (!lmh_setSubBandChannels(2))
   Serial.println("lmh_setSubBandChannels failed. Wrong sub band requested?");

// Start Join procedure

Success and working! Thanks for your help :slight_smile:

1 Like

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