 #define COMMISSIONING_MODE  1
 #define APPS_STATE          2
 
+// The number of join retries. Set to -1 if you want to retry indefinatly.
+static const int8_t RETRIES = 10;
+
 //TheThingsNetwork anonymous config
 static const char *devAddr = "26011F0F";
 static const char *nwkSKey = "ADAFF80790E39125AD12F170768A6A97";

    }
    if(serialDataIn.startsWith("rejoin"))                               //rejoins LoRa network with new keys (i.e. reboot)
    {
      joined_network = ttn.join();         //Join TTN network and show progress on via serial
      if (joined_network) {
        usbserial.print("ack\n");
        current_state = APPS_STATE;

    } else if (strcmp(appEui, "0000000000000000") == 0) {
      ttn.personalize(devAddr, nwkSKey, appSKey);
    } else {
      ttn.join(RETRIES, 10000);
    }
    joined_network = 1;
  }
