   }
 
   if (gps.altitude.isUpdated()) {
-    altitude = gps.altitude.value(); 
+    altitude = gps.altitude.value();
   }
 
   if (gps.satellites.isUpdated()) {


  if (millis() - last > 10000) {
    Serial.println(F("Interval"));

    uint8_t batteryPercentage;
    uint16_t batteryVoltage;
    gsmGetBatteryLevel(&batteryPercentage, &batteryVoltage);
    int16_t signalStrength = gsmGetSignalQuality();

    if (gps.location.isValid()) {
      char paramsBuffer[200];
      sprintf(paramsBuffer, "id=%d&lat=%c%u.%lu&lng=%c%u.%lu&date=%lu&time=%lu&speed=%lu&course=%lu&alt=%lu&sat=%lu&hdop=%lu&age=%lu&charge=%d&voltage=%u&signal=%d", ID, latSign, latDeg, latFrac, lngSign, lngDeg, lngFrac, date, time, speed, course, altitude, satellites, hdop, age, batteryPercentage, batteryVoltage, signalStrength);
      Serial.println(paramsBuffer);
      gsmSendPOSTRequest("seth.bekti.io/api/v1/location", paramsBuffer);
    } else {
      char paramsBuffer[50];
      sprintf(paramsBuffer, "id=%d&charge=%d&voltage=%u&signal=%d", ID, batteryPercentage, batteryVoltage, signalStrength);
      gsmSendPOSTRequest("seth.bekti.io/api/v1/location", paramsBuffer);
    }
    
    last = millis();
  }
}


uint8_t gsmSendCommand(const char* cmd, uint16_t timeout, const char* expected) {
  gsmSerial.listen();

  if (cmd) {
    gsmPurgeSerialBuffer();
    gsmSerial.println(cmd);
  }

  uint32_t t = millis();
  uint8_t n = 0;

  do {
    if (gsmSerial.available()) {
      char c = gsmSerial.read();
      Serial.write(c);

      if (n >= sizeof(gsmSerialBuffer) - 1) {
        // buffer full, discard first half
        n = sizeof(gsmSerialBuffer) / 2 - 1;
        memcpy(gsmSerialBuffer, gsmSerialBuffer + sizeof(gsmSerialBuffer) / 2, n);
      }

      gsmSerialBuffer[n++] = c;
      gsmSerialBuffer[n] = 0;

      if (strstr(gsmSerialBuffer, expected ? expected : "OK\r")) {
        return n;
      }
    }
  } while (millis() - t < timeout);

  return 0;
}

uint8_t gsmSendCommand_P(const __FlashStringHelper* cmd, uint16_t timeout, const char* expected) {
  gsmSerial.listen();

  if (cmd) {
    gsmPurgeSerialBuffer();
    gsmSerial.println(cmd);
  }

  uint32_t t = millis();
  uint8_t n = 0;

  do {
    if (gsmSerial.available()) {
      char c = gsmSerial.read();
      Serial.write(c);

      if (n >= sizeof(gsmSerialBuffer) - 1) {
        // buffer full, discard first half
        n = sizeof(gsmSerialBuffer) / 2 - 1;
        memcpy(gsmSerialBuffer, gsmSerialBuffer + sizeof(gsmSerialBuffer) / 2, n);
      }

      gsmSerialBuffer[n++] = c;
      gsmSerialBuffer[n] = 0;

      if (strstr(gsmSerialBuffer, expected ? expected : "OK\r")) {
        return n;
      }
    }
  } while (millis() - t < timeout);

  return 0;
}

void reboot() {
  digitalWrite(ARDUINO_RESET_PIN, LOW);
}

void setup() {
  digitalWrite(ARDUINO_RESET_PIN, HIGH);
  pinMode(ARDUINO_RESET_PIN, OUTPUT);
  
  Serial.begin(9600);
  gpsSerial.begin(9600);
  gsmSerial.begin(9600);

  for (;;) {
    Serial.println(F("Initializing GSM... "));
    uint8_t ret = gsmInit();
    
    if (ret == 0) {
      Serial.println(F("OK"));
      break;
    }
    
    Serial.print(F("Error code: "));
    Serial.println(ret);
  }

  for (;;) {
    Serial.println(F("Setting up network... "));
    uint8_t ret = gsmSetup(APN);
    
    if (ret == 0) {
      Serial.println(F("OK"));
      break;
    }
    
    Serial.print(F("Error code: "));
    Serial.println(ret);
  }
}

void loop() {
  gpsSerial.listen();

  while (gpsSerial.available()) {
    gps.encode(gpsSerial.read());
    gpsUpdateValues();
