Mic mismatch during initialization

Hi,

I use a RAK3172 with an ESP32. The ESP is initializing the RAK3172 and check the connection with the module by setting all keys for LoRaWAN OTAA to zero.

D (7031) RAK3172: Transmit command: AT
D (7051) RAK3172:     Status: OK
D (7051) RAK3172:     Error: 0
D (7051) RAK3172: Response from 'AT': OK
D (7051) RAK3172: Transmit command: AT+JOIN=0:0:10:8
D (7091) RAK3172:     Status: OK
D (7091) RAK3172:     Error: 0
D (7091) RAK3172: Transmit command: AT+NWM=1
D (7131) RAK3172:     Status: OK
D (7131) RAK3172:     Error: 0
D (7131) RAK3172: Transmit command: AT+CLASS=A
D (7171) RAK3172:     Status: OK
D (7171) RAK3172:     Error: 0
D (7171) RAK3172: Transmit command: AT+BAND=4
D (7221) RAK3172:     Status: OK
D (7221) RAK3172:     Error: 0
D (7221) RAK3172: Transmit command: AT+BAND=?
D (7251) RAK3172:     Value: 4
D (7251) RAK3172:     Status: OK
D (7251) RAK3172:     Error: 0
D (7251) RAK3172: Set Tx power index: 0
D (7251) RAK3172: Transmit command: AT+TXP=0
D (7281) RAK3172:     Status: OK
D (7281) RAK3172:     Error: 0
D (7281) RAK3172: Transmit command: AT+ADR=1
D (7321) RAK3172:     Status: OK
D (7321) RAK3172:     Error: 0
D (7321) RAK3172: Use OTAA mode
D (7321) RAK3172: Transmit command: AT+NJM=1
D (7361) RAK3172:     Status: OK
D (7361) RAK3172:     Error: 0

If the check is successful the ESP32 will get all neccessary keys from TTI and initialize the RAK3172 with these keys:

D (7361) RAK3172: DEVEUI: 50...49 - Size: 16
D (7361) RAK3172: APPEUI: 00...00 - Size: 16
D (7361) RAK3172: APPKEY: 53...77 - Size: 32
D (7371) RAK3172: Transmit command: AT+DEVEUI=50...49
D (7411) RAK3172:     Status: OK
D (7411) RAK3172:     Error: 0
D (7411) RAK3172: Transmit command: AT+APPEUI=00...00
D (7471) RAK3172:     Status: OK
D (7471) RAK3172:     Error: 0
D (7471) RAK3172: Transmit command: AT+APPKEY=53...77
D (7541) RAK3172:     Status: OK
D (7541) RAK3172:     Error: 0

The RAK3172 tries to join the network, but TTI is throwing a mic mismatch error. When I unplug the device and switch it on again the join process will succeed (with the same keys).

From the TTN documentation I know that the error comes from a possible error in the app key, but I don´t have any idea why the key only works after a power on reset of the ESP32 and the module.

Hi @kampi ,

Is this scenario repeatable even you register it as a new device with a different set of otaa EUI/KEY? Can you confirm if you use LoRaWAN V1.0.3 in TTN V3?

The MIC during the joining process contains 5 parameters (assuming we are LoRaWAN v1.0.3) - AppKey, MHDR, AppEUI, DevEUI and DevNonce. Any one in these five can be the culprit.

Hi @carlrowan,

yes, I can reproduce the error and I have tried it several times. I use a different AppKey every time when I reset the device (because we generate a random key).

I followed the guide from your documentation and setup the device in the following way (not with LoRaWAN V1.0.3)

V1.0.2 or V1.0.3 should work fine. I just need to know what you use. But I will still update the guide to use V1.0.3.

Can you send me the AT command sequence you use in the module? I’ll try to reproduce it.

Does it happen to more than one RAK3172? Have you tried a different network server? I’ll appreciate any info you can provide :handshake:

Hi,

the application runs in two stages:

  1. In the first stage the device is prepared for an update. During this step the device will check the connectivity with the RAK3172 module by initializing the module:
memset(devEUI, 0x00, sizeof(devEUI));
memset(appEUI, 0x00, sizeof(appEUI));
memset(appKey, 0x00, sizeof(appKey));
 if(RAK3172_Init(&Serial1, LORA_RX, LORA_TX, 16, devEUI, appEUI, appKey, LORAWAN_CLASS_A, true, BAND_EU868) == ESP_OK)
 {
        Serial.println("    RAK3172 detected");
        RAK3172_SoftReset();
        RAK3172_Deinit();
        return true;
 }

The function will transmit the following commands:

esp_err_t RAK3172_Init(HardwareSerial* p_Interface, int8_t Rx, int8_t Tx, uint8_t TxPwr, uint8_t* p_DEVEUI, uint8_t* p_APPEUI, uint8_t* p_APPKEY, char Class, bool UseOTAA, RAK3172_Band_t Band, uint32_t Timeout)
{
    // Send ATZ, receive the boot screen and check if the boot screen is valid
    esp_err_t Error = RAK3172_SoftReset(Timeout);
    if(Error)
    {
        return Error;
    }

    // Test for echo mode and disable the echo mode
    RAK3172_SendCommand("AT", NULL, &Response);
    ESP_LOGD(TAG, "Response from 'AT': %s", Response.c_str());
    if(Response.indexOf("OK") == -1)
    {
        _Interface->readStringUntil('\n');
        ESP_LOGD(TAG, "Echo mode enabled. Disabling echo mode...");
        _Interface->print("ATE\r\n");
        _Interface->readStringUntil('\n');
        _Interface->readStringUntil('\n');
        Response = _Interface->readStringUntil('\n');
        ESP_LOGD(TAG, "Response from 'AT': %s", Response.c_str());
        if(Response.indexOf("OK") == -1)
        {
            return ESP_FAIL;
        }
    }

    if(RAK3172_SendCommand("AT+JOIN=0:0:10:8", NULL, NULL))
    {
        return ESP_FAIL;
    }
    if(RAK3172_SendCommand("AT+NWM=1", NULL, NULL) || RAK3172_SendCommand("AT+CLASS=" + String(Class), NULL, NULL) || RAK3172_SendCommand("AT+BAND=" + String((uint8_t)Band), NULL, NULL) || RAK3172_SetTxPwr(TxPwr) || RAK3172_SendCommand("AT+ADR=1", NULL, NULL))
    {
        return ESP_FAIL;
    }

    if(UseOTAA)
    {
        ESP_LOGD(TAG, "Use OTAA mode");
        if(RAK3172_SendCommand("AT+NJM=" + String(UseOTAA), NULL, NULL) || RAK3172_SetKeys(p_DEVEUI, p_APPEUI, p_APPKEY))
        {
            return ESP_FAIL;

        }
        return ESP_OK;
    }
    ESP_LOGE(TAG, "ABP is not supported in this version!");
    return ESP_ERR_INVALID_ARG;
}
  1. This check gets passed successfully. After that check the device receives the keys for the LoRaWAN setup and write that values to the Flash memory
DevEUI: 0x50...0x49 
AppEUI: 0x0...0x0 
AppKey: 0x76...0x46
  1. Now the device performs a reboot, calls RAK3172_Init again and use the keys from the Flash memory this time:
D (7361) RAK3172: DEVEUI: 50...49 - Size: 16
D (7361) RAK3172: APPEUI: 00...00 - Size: 16
D (7361) RAK3172: APPKEY: 76...46 - Size: 32
D (7371) RAK3172: Transmit command: AT+DEVEUI=50...49
D (7441) RAK3172:     Status: OK
D (7441) RAK3172:     Error: 0
D (7441) RAK3172: Transmit command: AT+APPEUI=00...00
D (7481) RAK3172:     Status: OK
D (7481) RAK3172:     Error: 0
D (7481) RAK3172: Transmit command: AT+APPKEY=76...46
D (7581) RAK3172:     Status: OK
D (7581) RAK3172:     Error: 0
  1. The device reboots again and check. Now the device check the JOIN status and perform a JOIN when the module isn´t joined
D (1262) RAK3172: Transmit command: AT+NJS=?
D (1292) RAK3172:     Value: 0
D (1292) RAK3172:     Status: OK
D (1292) RAK3172:     Error: 0
D (1292) LoRaWAN: Not joined. Rejoin...
D (1292) RAK3172: Transmit command: AT+JOIN=1:1:30:5
D (1362) RAK3172:     Status: OK
D (1362) RAK3172:     Error: 0
  1. TTI is displaying a MIC mismatch
  2. I power off the device and power it on again
  3. Die device is repeating the steps from step 3 and step 4 but TTI is displaying Accept join-request this time and the transmission succeed.

We have updated the device to V1.0.3 before I wrote this answer. I have verified the steps before writing this answer and the issue still exsist.