LoRaMacIsBusy()


I’m using RAK3172, can you explain why LoRaMacIsBusy ? Thank u

LoRaMAC busy is thrown when you do an API call but there is

  • an TX/RX cycle still ongoing
  • the device is trying to join the network and you send another command, e.g. setting the DevEUI or trying to send a packet

There might be a view more cases, but these are the usual ones.

1 Like

When I debug more, I see it LORAMAC_TX_RUNNING, how can I fix it

What do you mean with “Fix it”?
If TX is active, the device is either (1) trying to join the network or it is (2) in a TX/RX cycle.

(1) can be started automatically, if you set autojoin with AT+JOIN=1:1 before. This is saved in flash, so on every reboot the device will try to join, independent of any API call. You can get the result of the join attempt with the API Join callback function

(2) Wait for the TX/RX cycle to be finished. Best is to use the API TX callback function.

/**
 * @brief Callback after join request cycle
 *
 * @param status Join result
 */
void joinCallback(int32_t status)
{
	if (status != 0)
	{
		MYLOG("JOIN-CB", "LoRaWan OTAA - join fail! \r\n");
		// To be checked if this makes sense
		// api.lorawan.join();
	}
	else
	{
		MYLOG("JOIN-CB", "LoRaWan OTAA - joined! \r\n");
		digitalWrite(LED_BLUE, LOW);
	}
}

/**
 * @brief LoRaWAN callback after TX is finished
 *
 * @param status TX status
 */
void sendCallback(int32_t status)
{
	MYLOG("TX-CB", "TX status %d", status);
	digitalWrite(LED_BLUE, LOW);
	tx_active = false;
}

/**
 * @brief LoRaWAN callback after packet was received
 *
 * @param data pointer to structure with the received data
 */
void receiveCallback(SERVICE_LORA_RECEIVE_T *data)
{
	MYLOG("RX-CB", "RX, port %d, DR %d, RSSI %d, SNR %d", data->Port, data->RxDatarate, data->Rssi, data->Snr);
	for (int i = 0; i < data->BufferSize; i++)
	{
		Serial.printf("%02X", data->Buffer[i]);
	}
	Serial.print("\r\n");
	tx_active = false;
}


void setup()
{
	// Setup the callbacks for joined and send finished
	api.lorawan.registerRecvCallback(receiveCallback);
	api.lorawan.registerSendCallback(sendCallback);
	api.lorawan.registerJoinCallback(joinCallback);
	// ..... do other setup stuff
}
1 Like