diff --git a/include/config.h.sample b/include/config.h.sample
index d342c1d9d6a693fe1316ab2dcfd220762fe0e4b9..299492ae1e7a8565beb79820c20995d3ba3d96df 100644
--- a/include/config.h.sample
+++ b/include/config.h.sample
@@ -1,6 +1,7 @@
 #define SLEEP_SECONDS       900     // 15 minutes
 #define GPS_INT_SECONDS     1
 #define GPS_WAIT_SECONDS    120
+#define LORA_RETRY          3
 
 #define TTN_DEVEUI { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };  // LSB
 #define TTN_APPEUI { 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0xD5, 0xB3, 0x70 };  // LSB
diff --git a/include/power.h b/include/power.h
index bad45463911eefd7ee7accb33fbaec5f1d37a2c0..1e4943cb38e0e86aa9c92cd6c46f1df5d677b84a 100644
--- a/include/power.h
+++ b/include/power.h
@@ -2,7 +2,6 @@
 
 void powerLed(axp_chgled_mode_t);
 float powerGetBattVoltage();
-void powerSetOutput(uint8_t channel, bool enabled);
 void powerStatus();
 void powerSetup();
 void powerSleep();
diff --git a/platformio.ini b/platformio.ini
index 274a24b08cb3dfa0ea8147ad3adea48514bf4b6d..a75b1471b161012cf7c4810cbc80b1d1d9e2f45d 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -20,7 +20,7 @@ build_flags =
   -D ARDUINO_LMIC_CFG_NETWORK_TTN
   -D CFG_sx1276_radio
   -D CFG_eu868
-  -D LMIC_DEBUG_LEVEL=0
+  -D LMIC_DEBUG_LEVEL=2
 lib_deps =
   AXP202X_Library@1.1.2
   TinyGPSPlus@1.0.2
diff --git a/src/gps.cpp b/src/gps.cpp
index 8d59ca0e0fa7a693d011c973be0c367e3f0baea5..1c41ca94345b010a4857c650b4160e9eb7129b63 100644
--- a/src/gps.cpp
+++ b/src/gps.cpp
@@ -4,7 +4,7 @@
 #include <TinyGPS++.h>
 
 HardwareSerial GPS(1);
-TinyGPSPlus gps;
+extern TinyGPSPlus gps;
 extern int state;
 unsigned long gpsTimer;
 unsigned long gpsCount;
@@ -29,6 +29,7 @@ void gpsStatus()
     Serial.printf("Time       : %02d:%02d:%02d\n", gps.time.hour(), gps.time.minute(), gps.time.second());
     Serial.printf("Speed      : %g\n", gps.speed.kmph());
     Serial.println("#########################\n");
+    gpsCount = 0;
 }
 
 void gpsSetup()
diff --git a/src/lora.cpp b/src/lora.cpp
index 0ea3cb0b747ce9ce4bfa585f67f6e36017bb2ab6..2530b9fc904876b7690f0e4a3fe4ce7ee038b1b4 100644
--- a/src/lora.cpp
+++ b/src/lora.cpp
@@ -7,6 +7,7 @@
 #include <CayenneLPP.h>
 
 extern int state;
+int retry;
 
 class cLoRaWAN : public Arduino_LoRaWAN_ttn
 {
@@ -105,6 +106,7 @@ void onEvent(ev_t ev)
         break;
     case EV_JOINING:
         Serial.println(F("EV_JOINING"));
+        retry = 0;
         break;
     case EV_JOINED:
         Serial.println(F("EV_JOINED"));
@@ -159,8 +161,20 @@ void onEvent(ev_t ev)
         break;
     case EV_JOIN_TXCOMPLETE:
         Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
-        // restart sending
-        state = STATE_READY;
+        if (retry < LORA_RETRY)
+        {
+            //Serial.printf("\nLoRa Join failed, %d retries left.\n\n", LORA_RETRY - retry);
+            // TODO: this will cause "CORRUPT HEAP: Bad head at / assertion "head != NULL" failed / abort() was called"
+            //state = STATE_INIT;
+            
+            Serial.println("\nLoRa Join failed.");
+            state = STATE_DONE;
+        }
+        else
+        {
+            Serial.println("\nLoRa Join failed, no retries left.");
+            state = STATE_DONE;
+        }
         break;
     default:
         Serial.println(F("Unknown event " + (unsigned)ev));
diff --git a/src/main.cpp b/src/main.cpp
index 1c67022aeb76893c5720e033b2604db8d2ce2171..ad5d3a98933dc6b522d2adb45e40bf50dcd32ed9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -8,11 +8,12 @@
 
 int state;
 CayenneLPP payload(55);
+TinyGPSPlus gps;
 
 void createPayload()
 {
     payload.reset();
-    TinyGPSPlus gps = getGps();
+    gps = getGps();
     payload.addGPS(1, gps.location.lat(), gps.location.lng(), gps.altitude.meters());
     payload.addAnalogInput(2, powerGetBattVoltage() / 1000);
 }
diff --git a/src/power.cpp b/src/power.cpp
index 821525630d9cd3318c8dda91409fc2570097d425..bbf29c477801cceda0265a7b29e5f94a294a8f7a 100644
--- a/src/power.cpp
+++ b/src/power.cpp
@@ -15,11 +15,6 @@ float powerGetBattVoltage()
     return axp.getBattVoltage();
 }
 
-void powerSetOutput(uint8_t channel, bool enabled)
-{
-    axp.setPowerOutPut(channel, enabled);
-}
-
 void powerStatus()
 {
     Serial.println("\n########## Power ##########");
@@ -78,9 +73,9 @@ void powerSleep()
 {
     Serial.printf("\nSystem has been up for %llu seconds.\n", esp_timer_get_time()/1000000);
     Serial.printf("Going to sleep for %d seconds.\n", SLEEP_SECONDS);
-    powerSetOutput(AXP192_LDO2, AXP202_OFF); // LORA : off
-    powerSetOutput(AXP192_LDO3, AXP202_OFF); // GPS  : off
-    powerLed(AXP20X_LED_OFF);
+    axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF); // LORA : off
+    axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF); // GPS  : off
+    axp.setChgLEDMode(AXP20X_LED_OFF);
     esp_sleep_enable_ext0_wakeup(GPIO_NUM_38, LOW); // wake up with "user" button (middle)
     esp_sleep_enable_timer_wakeup(1000000 * SLEEP_SECONDS);
     Serial.println("\n### END ###");