   Serial.println(_interval);
 
   for (;;) {
-    gsm_reset();
+    Serial.println(F("Initializing GSM..."));
     uint8_t result = gsm_init();
     if (result == 0) break;
+
+    Serial.print(F("Error code: "));
+    Serial.println(result);
+    delay(2000);
+  }
+
+  for (;;) {
+    uint8_t result = gsm_setup();
+    if (result == 0) break;
+
+    Serial.print(F("Error code: "));
+    Serial.println(result);
+    delay(2000);
   }
 
   gps_init_values();

  }

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

  if (millis() - _last_upload > _interval) {
    uint8_t battery_percentage = 78;
    uint16_t battery_voltage = 4700;
    int8_t signal_strength = 20;
  
    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);

    uint8_t result = gsm_send_post_request("seth.bekti.io/api/v1/location", params_buffer);

    if (result != 0) {
      ++_failure_count;
    } else {
      _failure_count = 0;
    }

    if (_failure_count >= 1) {
      reboot();
    }


  Serial.println(_apn);

  if (gsm_send_command_P(F("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\""))) {
    return 4;
  }

  _gsm_serial.listen();
