     static const PROGMEM u1_t devaddr[] = DEVADDR;
     static_assert(sizeof(settings.DevAddr) == sizeof(devaddr), "DEVADDR needs to be 4 bytes");
     _memcpy(settings.DevAddr, devaddr, sizeof(settings.DevAddr));
+    settings.flags |= FLAG_DEV_ADDR_SET;
+    debugLogData("Setting DevAddr", settings.DevAddr, sizeof(settings.DevAddr));
+    write = true;
+  #endif
+  #if defined(NWKSKEY)
+    static const PROGMEM u1_t nwkskey[] = NWKSKEY;
+    static_assert(sizeof(settings.NwkSKey) == sizeof(nwkskey), "NWKSKEY needs to be 16 bytes");
+    _memcpy(settings.NwkSKey, nwkskey, sizeof(settings.NwkSKey));
+    settings.flags |= FLAG_NWK_SKEY_SET;
+    debugLogData("Setting NwkSKey", settings.NwkSKey, sizeof(settings.NwkSKey));
+    write = true;
   #endif
   #if defined(APPSKEY)
     static const PROGMEM u1_t appskey[] = APPSKEY;
     static_assert(sizeof(settings.AppSKey) == sizeof(appskey), "APPSKEY needs to be 16 bytes");
     _memcpy(settings.AppSKey, appskey, sizeof(settings.AppSKey));
-  #endif
-  #if defined(NWKSKEY)
-    static const PROGMEM u1_t nwkskey[] = NWKSKEY;
-    static_assert(sizeof(settings.NwkSKey) == sizeof(nwkskey), "NWKSKEY needs to be 16 bytes");
-    _memcpy(settings.NwkSKey, nwkskey, sizeof(settings.NwkSKey));
-  #endif
-  #if defined(DEVADDR) && defined(APPSKEY) && defined(NWKSKEY)
-    settings.flags |= FLAG_SESSION_VARS_SET;
+    settings.flags |= FLAG_APP_SKEY_SET;
+    debugLogData("Setting AppSKey", settings.AppSKey, sizeof(settings.AppSKey));
     write = true;
   #endif
 


  uint32_t seq_no;

#define FLAG_SESSION_VARS_SET (1 << 0) // Set of DevAddr, NwkSKey, and AppSKey set.
  u1_t DevAddr[4];
  u1_t NwkSKey[16];
  u1_t AppSKey[16];

// Separate set flags because BLE can't send all at once
#define FLAG_APP_KEY_SET (1 << 1)

    return;
  }

  if ((settings.flags & FLAG_SESSION_VARS_SET)==FLAG_SESSION_VARS_SET) {
    debugPrint("Session vars set - initializing lora");
    loraSetSessionKeys(settings.seq_no, settings.AppSKey, settings.NwkSKey, settings.DevAddr);

    reportSessionVars();
  }
  else if ((settings.flags & FLAG_JOIN_VARS_SET)==FLAG_JOIN_VARS_SET) {
    debugPrint("Join keys set - initializing lora join");
    loraJoin(settings.seq_no, settings.AppKey, settings.AppEUI, settings.DevEUI, onJoin);
  }
