Auto add devices to RAK plateform failed

hi
i’m working with rak3172 and gateway rak7289 and i want to make an automate system in which, in order to connect the rak3172 to the gateway, i will not need to enter manually the DevEUI I like this


so i tried to configure here a way to make it automatic by enabling “Auto Add LoRa Device.”

and in the code of rak3172 i configured it like this

#include <Wire.h>
// Set your credentials
#define OTAA_BAND (RAK_REGION_EU868)
#define OTAA_DEVEUI {0xAC, 0x1F, 0x09, 0xFF, 0xFE, 0x17, 0x87, 0xDB}
#define OTAA_APPEUI {0x0c, 0xad, 0xbb, 0x68, 0x06, 0xeb, 0xf6, 0x5e} // LSB format
#define OTAA_APPKEY {0x06, 0xA6, 0x98, 0x28, 0xAC, 0x7C, 0x00, 0x60, 0xCF, 0xD3, 0x1A, 0xF8, 0xCE, 0xFE, 0x77, 0x0B}
// RAK-specific pin definitions (for RAK13007 Relay)
#define RELAY_PIN WB_IO4  // Relay control pin (previously used in your code)
#define blue_led WB_IO2
#define DOWNLINK_PORT 2      // Must match ThingsBoard fPort

void joinCallback(int32_t status) {
    Serial.printf("Join status: %d\r\n", status);
}

void recvCallback(SERVICE_LORA_RECEIVE_T *data) {
    if (data->BufferSize > 0 && data->Port == DOWNLINK_PORT) {
        // Process relay command (first byte only)
        uint8_t command = data->Buffer[0];
        
        if (command == 0x01) {       // ON (AQ==)
            digitalWrite(blue_led, HIGH);    // Relay ON
            Serial.println("Relay: ON");
        } 
        else if (command == 0x00) {  // OFF (AA==)
            digitalWrite(blue_led, LOW);   // Relay OFF
            Serial.println("Relay: OFF");
        }
    }
}

void sendDataToGateway(const uint8_t *data, uint8_t size) {
    uint8_t port = 1;  // Application port
    bool confirm = false;//true;  // Confirmed message
    uint8_t retry = 3;  // Retry attempts

    if (api.lorawan.send(size, (uint8_t *)data, port, confirm, retry)) {
        Serial.println("Data sent successfully!");

    } else {
        Serial.println("Failed to send data.");
    }
}

void setup() {
    // Initialize Serial (with RAK_AT_MODE for RAK3172)
    Serial.begin(115200, RAK_AT_MODE);
    delay(2000);  // Stabilization delay

    // Startup message (minimal)
    Serial.println("RAK3172 Relay Controller");
    Serial.println("-----------------------");

    pinMode(RELAY_PIN, OUTPUT);
    digitalWrite(RELAY_PIN, HIGH);   // Relay OFF
    pinMode(blue_led, OUTPUT);
    digitalWrite(blue_led, LOW);


    // Set up LoRaWAN OTAA
    uint8_t node_device_eui[8] = OTAA_DEVEUI;
    uint8_t node_app_eui[8] = OTAA_APPEUI;
    uint8_t node_app_key[16] = OTAA_APPKEY;

    if (!api.lorawan.band.set(OTAA_BAND)) {
        Serial.println("Failed to set band.");
        return;
    }
    if (!api.lorawan.deviceClass.set(RAK_LORA_CLASS_C)) { // Continuous receive mode
        Serial.println("Failed to set device class.");
        return;
    }
    if (!api.lorawan.njm.set(RAK_LORA_OTAA)) { // Set OTAA mode
        Serial.println("Failed to set network join mode.");
        return;
    }

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.registerRecvCallback(recvCallback);
    api.lorawan.registerJoinCallback(joinCallback);

    // Attempt OTAA join with retry logic
    for (int attempt = 0; attempt < 5; attempt++) {
        if (api.lorawan.join()) {
            Serial.println("LoRaWAN join successful!");
            break;
        }
        Serial.printf("Retrying join... Attempt %d/5\n", attempt + 1);
        delay(10000);
    }

    if (api.lorawan.njs.get() == 0) {
        Serial.println("Failed to join network after 5 attempts.");
        return;
    }

    Serial.println("RAK3172 is ready to send data and receive downlinks.");
}

void loop() {
    uint8_t testData[] = {0x01};//{0x01, 0x02, 0x03}; // Test uplink data
    sendDataToGateway(testData, sizeof(testData));

    delay(10000);  // Send data every 10 seconds
}

but the device didn’t autoadd. i even tried “#define OTAA_APPEUI {0x5e, 0xf6, 0xeb, 0x06, 0x68, 0xbb, 0xad, 0x0c}”
because i doubt in Application EUI is Little Endian in Firmware
so how to fix this problem

Have a look at this example if there are any differences LoRaWan_OTAA

Make sure you have automatic join disabled with AT+JOIN=0:0

If the RAK3172 is automatically starting the join process, it does not accept changes in DevEUI, AppEUI, … while the join process is ongoing.

hi
i tested the program in the example from the git

/***
 *  This example shows LoRaWan protocol joining the network in OTAA mode, class A, region EU868.
 *  Device will send uplink every 20 seconds.
***/

#define OTAA_PERIOD   (20000)
/*************************************

   LoRaWAN band setting:
     RAK_REGION_EU433
     RAK_REGION_CN470
     RAK_REGION_RU864
     RAK_REGION_IN865
     RAK_REGION_EU868
     RAK_REGION_US915
     RAK_REGION_AU915
     RAK_REGION_KR920
     RAK_REGION_AS923

 *************************************/
#define OTAA_BAND     (RAK_REGION_EU868)
#define OTAA_DEVEUI   {0xAC, 0x1F, 0x09, 0xFF, 0xFE, 0x17, 0x88, 0x38}
#define OTAA_APPEUI   {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
#define OTAA_APPKEY   {0x06, 0xA6, 0x98, 0x28, 0xAC, 0x7C, 0x00, 0x60, 0xCF, 0xD3, 0x1A, 0xF8, 0xCE, 0xFE, 0x77, 0x0B}

/** Packet buffer for sending */
uint8_t collected_data[64] = { 0 };

void recvCallback(SERVICE_LORA_RECEIVE_T * data)
{
    if (data->BufferSize > 0) {
        Serial.println("Something received!");
        for (int i = 0; i < data->BufferSize; i++) {
            Serial.printf("%x", data->Buffer[i]);
        }
        Serial.print("\r\n");
    }
}

void joinCallback(int32_t status)
{
    Serial.printf("Join status: %d\r\n", status);
}

/*************************************
 * enum type for LoRa Event
    RAK_LORAMAC_STATUS_OK = 0,
    RAK_LORAMAC_STATUS_ERROR,
    RAK_LORAMAC_STATUS_TX_TIMEOUT,
    RAK_LORAMAC_STATUS_RX1_TIMEOUT,
    RAK_LORAMAC_STATUS_RX2_TIMEOUT,
    RAK_LORAMAC_STATUS_RX1_ERROR,
    RAK_LORAMAC_STATUS_RX2_ERROR,
    RAK_LORAMAC_STATUS_JOIN_FAIL,
    RAK_LORAMAC_STATUS_DOWNLINK_REPEATED,
    RAK_LORAMAC_STATUS_TX_DR_PAYLOAD_SIZE_ERROR,
    RAK_LORAMAC_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS,
    RAK_LORAMAC_STATUS_ADDRESS_FAIL,
    RAK_LORAMAC_STATUS_MIC_FAIL,
    RAK_LORAMAC_STATUS_MULTICAST_FAIL,
    RAK_LORAMAC_STATUS_BEACON_LOCKED,
    RAK_LORAMAC_STATUS_BEACON_LOST,
    RAK_LORAMAC_STATUS_BEACON_NOT_FOUND,
 *************************************/

void sendCallback(int32_t status)
{
    if (status == RAK_LORAMAC_STATUS_OK) {
        Serial.println("Successfully sent");
    } else {
        Serial.println("Sending failed");
    }
}

void setup()
{
    Serial.begin(115200, RAK_AT_MODE);
    delay(2000);
  
    Serial.println("RAKwireless LoRaWan OTAA Example");
    Serial.println("------------------------------------------------------");
  
    if(api.lorawan.nwm.get() != 1)
    {
        Serial.printf("Set Node device work mode %s\r\n",
            api.lorawan.nwm.set() ? "Success" : "Fail");
        api.system.reboot();
    }

    // OTAA Device EUI MSB first
    uint8_t node_device_eui[8] = OTAA_DEVEUI;
    // OTAA Application EUI MSB first
    uint8_t node_app_eui[8] = OTAA_APPEUI;
    // OTAA Application Key MSB first
    uint8_t node_app_key[16] = OTAA_APPKEY;
  
    if (!api.lorawan.appeui.set(node_app_eui, 8)) {
        Serial.printf("LoRaWan OTAA - set application EUI is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.appkey.set(node_app_key, 16)) {
        Serial.printf("LoRaWan OTAA - set application key is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.deui.set(node_device_eui, 8)) {
        Serial.printf("LoRaWan OTAA - set device EUI is incorrect! \r\n");
        return;
    }
  
    if (!api.lorawan.band.set(OTAA_BAND)) {
        Serial.printf("LoRaWan OTAA - set band is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.deviceClass.set(RAK_LORA_CLASS_A)) {
        Serial.printf("LoRaWan OTAA - set device class is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.njm.set(RAK_LORA_OTAA))	// Set the network join mode to OTAA
    {
        Serial.printf("LoRaWan OTAA - set network join mode is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.join())	// Join to Gateway
    {
        Serial.printf("LoRaWan OTAA - join fail! \r\n");
        return;
    }
  
    /** Wait for Join success */
    while (api.lorawan.njs.get() == 0) {
        Serial.print("Wait for LoRaWAN join...");
        api.lorawan.join();
        delay(10000);
    }
  
    if (!api.lorawan.adr.set(true)) {
        Serial.printf("LoRaWan OTAA - set adaptive data rate is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.rety.set(1)) {
        Serial.printf("LoRaWan OTAA - set retry times is incorrect! \r\n");
        return;
    }
    if (!api.lorawan.cfm.set(1)) {
        Serial.printf("LoRaWan OTAA - set confirm mode is incorrect! \r\n");
        return;
    }
  
    /** Check LoRaWan Status*/
    Serial.printf("Duty cycle is %s\r\n", api.lorawan.dcs.get()? "ON" : "OFF");	// Check Duty Cycle status
    Serial.printf("Packet is %s\r\n", api.lorawan.cfm.get()? "CONFIRMED" : "UNCONFIRMED");	// Check Confirm status
    uint8_t assigned_dev_addr[4] = { 0 };
    api.lorawan.daddr.get(assigned_dev_addr, 4);
    Serial.printf("Device Address is %02X%02X%02X%02X\r\n", assigned_dev_addr[0], assigned_dev_addr[1], assigned_dev_addr[2], assigned_dev_addr[3]);	// Check Device Address
    Serial.printf("Uplink period is %ums\r\n", OTAA_PERIOD);
    Serial.println("");
    api.lorawan.registerRecvCallback(recvCallback);
    api.lorawan.registerJoinCallback(joinCallback);
    api.lorawan.registerSendCallback(sendCallback);
}

void uplink_routine()
{
    /** Payload of Uplink */
    uint8_t data_len = 0;
    collected_data[data_len++] = (uint8_t) 't';
    collected_data[data_len++] = (uint8_t) 'e';
    collected_data[data_len++] = (uint8_t) 's';
    collected_data[data_len++] = (uint8_t) 't';
  
    Serial.println("Data Packet:");
    for (int i = 0; i < data_len; i++) {
        Serial.printf("0x%02X ", collected_data[i]);
    }
    Serial.println("");
  
    /** Send the data package */
    if (api.lorawan.send(data_len, (uint8_t *) & collected_data, 2, true, 1)) {
        Serial.println("Sending is requested");
    } else {
        Serial.println("Sending failed");
    }
}

void loop()
{
    static uint64_t last = 0;
    static uint64_t elapsed;
  
    if ((elapsed = millis() - last) > OTAA_PERIOD) {
        uplink_routine();
  
        last = millis();
    }
    //Serial.printf("Try sleep %ums..", OTAA_PERIOD);
    api.system.sleep.all(OTAA_PERIOD);
    //Serial.println("Wakeup..");
}

that you provided with the right configuration of devEUI and i kept waiting and it showing thi in serial monitor “RAKwireless LoRaWan OTAA Example
------------------------------+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…+EVT:JOIN_FAILED_RX_TIMEOUT
Wait for LoRaWAN join…Restricted_Wait_3358748_ms
Wait for LoRaWAN join…Restricted_Wait_3348744_ms” it couldn’t even connect , when i added the device manually it start sending"
RAKwireless LoRaWan OTAA Example
Wait for LoRaWAN join…+EVT:JOINED
Duty cycle is ON
Packet is CONFIRMED
Device Address is 029BDB94
Uplink period is 20000ms

Current Work Mode: LoRaWAN.".

so my question is simple in order to make a new device send to the gateway rak7289 save automatically without me entering the devEUI like this shall modify
- Code of rak3172
-parameter in the gateway rak7289
- both

any help will be appreciated

What exactly do you mean with “a new device send to the gateway rak7289 save automatically”

If you want a device to register itself on the LoRaWAN server, that is imho impossible.
You have to setup the device in the LoRaWAN server manually or through the LNS’s API.

A device cannot register itself on the LNS through LoRaWAN.

so what i mean is if a client buys a Gateway 7289 with a RAK3172 and a humidity sensor, then later adds a temperature sensor, must the gateway be manually reconfigured each time? Ideally, new sensors should auto-connect without vendor intervention—similar to WisNode or other plug-and-play systems.

For example, if I create a product with a RAK3172 + RAK12025 soil sensor, how can I ensure it auto-pairs with the gateway? Is there a built-in method, or is custom setup required?

Would appreciate any insights—thanks!

There is no “auto-pairs” in LoRaWAN.

If you setup an end node, independent whether it is built with a RAK3172 or the SensorHub or an end node of another supplier, you must register the device in the LoRaWAN server with its DevEUI, AppEUI (JoinEUI) and AppKey. Only then the device can connect to the LoRaWAN server (join the network).

If you add additional sensors to an end node that is already registered, that doesn’t change the registration.
Only the payload that the device will send is changing. But the LoRaWAN server doesn’t care about changes in the payload.

so mr @beegee
what is this option

This works only if you setup the AppEUI and AppKey of the end nodes in the LoRaWAN server manually.
Then the server will accept any device with the same AppEUI and AppKey and register the device with its DevEUI as a new device.

This option is available in the internal LoRaWAN server of WisGate Edge gateways, but not available in TTN, Chirpstack, Actility, …

I will not be using any of “TTN, Chirpstack, Actility, …” What I’m doing is sending through MQTT from RAK7289 to ThingsBoard, and it’s functional.

and it worked


i don’t know when i tested previously it didn’t work maybe i didn’t enter the AppEUI correctly

anyway thanks for the support

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