Hi,
I’m relatively new to working with RAK, LoRa, and gateways, and I’m still in the learning phase. My background involves IoT projects using ESP, STM32, and Arduino, but I have limited experience with LoRa gateways.
Currently, I’m working on a project where I need to connect a RAK3172 module to a RAK7289 gateway to transmit data. I’ve attempted to program the RAK3172 using Arduino IDE and developed a program for it "
// Set your credentials
#define OTAA_BAND (RAK_REGION_EU868)
#define OTAA_DEVEUI {0xAC, 0x1F, 0x09, 0xFF, 0xFE, 0x17, 0x87, 0xDB}
#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}
void joinCallback(int32_t status) {
Serial.printf(“Join status: %d\r\n”, status);
}
void recvCallback(SERVICE_LORA_RECEIVE_T *data) {
if (data->BufferSize > 0) {
Serial.println(“Data Received!”);
for (int i = 0; i < data->BufferSize; i++) {
Serial.printf(“0x%02X “, data->Buffer[i]);
}
Serial.println(”\r\n”);
}
}
// Function to send data to the gateway
void sendDataToGateway(const uint8_t *data, uint8_t size) {
uint8_t port = 1; // Set the port number (1 is commonly used for general messages)
bool confirm = true; // Set to true if you want the data to be confirmed
uint8_t retry = 3; // Number of retries in case of failure
// Use the send method that fits your need (confirm, retry, etc.)
bool success = api.lorawan.send(size, (uint8_t*)data, port, confirm, retry);
if (success) {
Serial.println("Data sent successfully!");
} else {
Serial.println("Failed to send data.");
}
}
// Define your LoRaWAN settings here (frequency, region)
void setup() {
Serial.begin(115200, RAK_AT_MODE);
delay(2000);
Serial.println("RAKwireless LoRaWan Send Mode");
Serial.println("------------------------------------------------------");
// Configure LoRaWAN settings
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();
}
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.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_C)) { // Set to Class C for continuous receive
Serial.printf("LoRaWan OTAA - set device class is incorrect!\r\n");
return;
}
if (!api.lorawan.njm.set(RAK_LORA_OTAA)) { // Set network join mode to OTAA
Serial.printf("LoRaWan OTAA - set network join mode is incorrect!\r\n");
return;
}
if (!api.lorawan.join()) { // Attempt to join the network
Serial.printf("LoRaWan OTAA - join fail!\r\n");
return;
}
while (api.lorawan.njs.get() == 0) {
Serial.print("Waiting for LoRaWAN join...\r\n");
delay(10000);
}
api.lorawan.registerRecvCallback(recvCallback); // Register receive callback
api.lorawan.registerJoinCallback(joinCallback);
Serial.println("RAK3172 is now in send mode!");
}
void loop() {
// Example of sending data to the gateway
uint8_t data = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ’ ', ‘G’, ‘a’, ‘t’, ‘e’, ‘w’, ‘a’, ‘y’, ‘!’};
sendDataToGateway(data, sizeof(data)); // Send data to the gateway
delay(30000); // Wait for 30 seconds before sending again
}
". On the gateway side, I accessed the web interface (http://192.168.230.1) and created an application in the LoRa Network → Application section, linking it with the device EUI.
The issue I’m facing is that when I run the code on the RAK3172, it repeatedly shows the following error and fails to join the network:"Waiting for LoRaWAN join…
Waiting for LoRaWAN join…
+EVT:JOIN_FAILED_TX_TIMEOUT
Waiting for LoRaWAN join…
+EVT:JOIN_FAILED_TX_TIMEOUT "
Could you please guide me on what might be causing this issue and how to resolve it? Any help or suggestions would be greatly appreciated.