RAK4631 Auto join fails, manual join works

I am running into an issue where if I set auto-join to true through AT commands (AT+JOIN=1:1:8:0), my device fails to join the network and I get a +EVT:JOIN_FAILED_TX_TIMEOUT error repeatedly.

However, if I instead turn off auto join (AT+JOIN=1:0:8:0), restart the device, and then manually call the AT+JOIN command, I will able to join my gateway. Similarly, if I instead use the API to join in my code (api.lorawan.join();), this will also generally succeed in joining the network.

My initial thought is that auto join attempts to connect to the network too quickly (perhaps before things are able to be properly setup?), as I will always get an +EVT:JOIN_FAILED_TX_TIMEOUT before any of my setup debugging statements are printed.

The code I am using is a very lightly modified RUI3-Sensor-Node example.

And insight would be appreciated!

Welcome to the forum @csomori

What RUI3 version are you using?

Try AT+JOIN=1:1:8:30 or any value different to 0 for the last parameter (time between retries).

Hello!

RUI version is RUI_4.0.1_RAK4631. Also on US915.

I tried both AT+JOIN=1:1:8:30 and 1:1:30:0 (I also thought parameter 3 was the retry period?)

Another interesting behavior is that it seems to attempt reconnecting more frequently than I specify. Here is an output of the console when I call the AT+JOIN=? command

image

If it really was a 30s re-attempt period I should not have this many errors (unless these errors occur at times when its not just trying to join the network). If I count the number of error messages in a minute I get 10, which implies its trying to reconnect every ~6s.

Also, after about 5 minutes of watching the console I got this error: Restricted_Wait_3251723_ms

And finally, during this process of receiving the +EVT:JOIN_FAILED_RX_TIMEOUT errors, I am unable to make any changes to the AT+JOIN parameters, I can only call AT+JOIN=? to view them, but attempting to change them gives me an AT_ERROR.

Correct, I am wrong with the parameters, the third one is the time between retries and the last one is the number or re-attempts. 0 should mean it tries only 1 time, and then gives up.

I will have a look into the example code as well (long time since I wrote it).

Just to confirm, you are using this code RUI3-Sensor-Node as a base?

Can you try to change the join callback function

void joinCallback(int32_t status)
{
	// MYLOG("JOIN-CB", "Join result %d", status);
	if (status != 0)
	{
		if (!(ret = api.lorawan.join()))
		{
			MYLOG("JOIN-CB", "LoRaWan OTAA - join fail! \r\n");
			if (found_sensors[OLED_ID].found_sensor)
			{
				rak1921_add_line((char *)"Join NW failed");
			}
		}
	}
	else
	{
		bool result_set_dr = api.lorawan.dr.set(g_data_rate);
		MYLOG("JOIN-CB", "Set the data rate  %s", result_set_dr ? "Success" : "Fail");
		MYLOG("JOIN-CB", "LoRaWan OTAA - joined! \r\n");
		digitalWrite(LED_BLUE, LOW);

		if (found_sensors[OLED_ID].found_sensor)
		{
			rak1921_add_line((char *)"Joined NW");
		}
	}
}

and remove the join retry line from the code.
The code was first released and tested with one of the first RUI3 versions. I am thinking that there could be a change in the behaviour of RUI3.
Can you try

void joinCallback(int32_t status)
{
	// MYLOG("JOIN-CB", "Join result %d", status);
	if (status != 0)
	{
		MYLOG("JOIN-CB", "LoRaWan OTAA - join fail! \r\n");
		if (found_sensors[OLED_ID].found_sensor)
		{
			rak1921_add_line((char *)"Join NW failed");
		}
	}
	else
	{
		bool result_set_dr = api.lorawan.dr.set(g_data_rate);
		MYLOG("JOIN-CB", "Set the data rate  %s", result_set_dr ? "Success" : "Fail");
		MYLOG("JOIN-CB", "LoRaWan OTAA - joined! \r\n");
		digitalWrite(LED_BLUE, LOW);

		if (found_sensors[OLED_ID].found_sensor)
		{
			rak1921_add_line((char *)"Joined NW");
		}
	}
}

Correct, using the RUI3-Sensor-Node code.

I modified the joinCallback method to remove the api call and that did not work. However, I am now receiving error messages at approximately the correct retry period specified with AT+JOIN so I think that has resolved at least part of the issue.

I took a look through your repo and decided to try the RUI3-LowPower-Example code. I figured perhaps your most up to date code may work better. But with the unmodified code I was having the same issue.

One thing I noticed is that when I attempt to join the network by the auto-join method, the data rate is set to 0 in the debugging output, even though I explicitly set it to 3. However, when I turn off auto-join and instead use the API to join the network, the data rate is correctly set to 3 as seen in the debugging log.

I am seated about 3m away from the gateway and so even walked down the hallway through a wall to see if this impacted results (I had read being too close to the gateway can cause issues), however this also did not help.

And finally something else I noticed is that when I successfully join the network using the API method, it always takes two tries, where the first attempt fails with the +EVT:JOIN_FAILED_RX_TIMEOUT error.

If you are that close to the gateway and using the max TX power, you might get have connection problems because the signal is too strong and the gateway antenna is over saturated.

You can try to reduce the TX power or move the gateway farther away.

For the datarate, LoRaWAN regions require a specific datarate when joining, e.g. in AS923 it has to be DR2 and you can select DR0 or DR1 only after successful joining.
For US915 the DR for the join is DR0, so the join packet will be always sent with DR0. After successful joining the DR can be set by API call or should go to the one setup with AT+DR AT command.

So after trying a number of different things with reducing TX power, walking to the other side of the building, and not having success, I’m thinking of 2 possible reasons.

  1. Timing: The Auto-join method tries to connect too quickly on start up. This wouldn’t explain why additional attempts fail though. However maybe it’s trying to join before other important commands have run?

  2. Needing to attempt connection twice: Like I mentioned, I am always able to manually connect to the gateway (either through the API or AT+JOIN) but consistently the first attempt fails. Meaning, I always need to make 2 manual join calls for it to work. It doesn’t seem to matter if I make these 2 calls in quick succession, or wait 30s between them, the 2nd call always works. I believe the fact that the first call fails may be connected to why the auto-join method fails.

What is your final goal?

  1. Do you want to setup automatic join with AT command and your code just checks whether it connected or failed?
  2. Do you want to control the join from your code instead of using the automatic join?

In case 1), remove the join calls from your code, it might (will) interfere with the automatic join tries of RUI3.
In case 2), set AT+JOIN=0:0 and take control of the join from within your code.

Mixing up automatic join and starting join from code at the same time is not a good idea.

For the first join fail and second always succeeds, first decide about above and then retry. I have many devices, not only RUI3, but as well with open source Arduino firmware, that need most of the time two join requests and only sometimes succeed on the first one.

So I know I can just use the API method to get the connection working, and likely I will just do that now after all this testing. However, based on previous forum posts I saw, it seems like using the AT commands are more ‘desirable’, and so auto-joining with the AT commands seems like the better option. Moreover I have a minor concern that the inability to connect using the auto-join method may indicate to some other problems that could come up in the future.

If you have experience with requiring multiple manual/API join calls to get things connected, that at least eases my concerns with that. However the auto-join failure still remains a mystery.

Thanks for all your help and suggestions!

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