 }
 
 uint8_t gsm_send_post_request(const char* url, const char* params) {
-  if (gsm_send_command_P(F("AT+SAPBR=1,1"), 10000)) {
+  bool connected = false;
+  
+  for (uint8_t i = 0; i < 10; ++i) {
+    uint8_t result = gsm_send_command_P(F("AT+SAPBR=1,1"), 10000);
+    if (result == 0) {
+      connected = true;
+      break;
+    }
+  }
+
+  if (!connected) {
     return 1;
   }
 

  }

  if (!success) {
    return 5;
  }

  if (gsm_send_command_P(F("AT+CMGF=1"))) {
    return 6;
  }

  if (gsm_send_command_P(F("AT+CPMS=\"SM\",\"SM\",\"SM\""))) {
    return 7;
  }

  eeprom_read_block((void*)&_apn, (const void*)&_apn_E, sizeof(_apn) - 1);

  }

  if (millis() - _last_sms_check > 5000) {
    Serial.println(F("Checking SMS..."));
    gsm_check_sms();
    _last_sms_check = millis();
  }

  if (millis() - _last_upload > _interval) {
    uint8_t battery_percentage;
    uint16_t battery_voltage;
    gsm_get_battery_level(&battery_percentage, &battery_voltage);
    int8_t signal_strength = gsm_get_signal_quality();
  
    char params_buffer[200];
    sprintf_P(params_buffer, _format_post, _device_id, _fix, _lat, _lng, _altitude, _speed, _course, _date_day, _date_month, _date_year, _time_hour, _time_minute, _time_second, _satellites, _hdop, _age, battery_percentage, battery_voltage, signal_strength);
    Serial.println(params_buffer);

    Serial.print(F("Sending HTTP request... "));
    uint8_t result = gsm_send_post_request("seth.bekti.io/api/v1/location", params_buffer);

    if (result != 0) {
      ++_failure_count;
      Serial.print(F("ERROR "));
      Serial.println(result);
    } else {
      _failure_count = 0;
      Serial.println(F("OK"));
    }

    if (_failure_count >= 1) {
      Serial.println(F("Rebooting..."));
      delay(1000);
      reboot();
    }

