 void gsm_reset() {
   pinMode(GSM_RESET_PIN, OUTPUT);
   digitalWrite(GSM_RESET_PIN, HIGH);
-  delay(1000);
+  delay(100);
   digitalWrite(GSM_RESET_PIN, LOW);
-  delay(1000);
+  delay(100);
   digitalWrite(GSM_RESET_PIN, HIGH);
-  delay(1000);
+  delay(100);
 }
 
 uint8_t gsm_init() {
-  if (gsm_send_command_P(F("AT"))) {
+  gsm_reset();
+  
+  bool success = false;
+  
+  for (uint8_t i = 0; i < 10; ++i) {
+    if (gsm_send_command_P(F("AT")) == 0) {
+      success = true;
+      break;
+    }
+  }
+
+  if (!success) {
     return 1;
   }
 

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

      if (expected && strstr(_gsm_serial_buffer, expected)) {
        return 0;
      } else if (strstr_P(_gsm_serial_buffer, PSTR("OK\r"))) {
        return 0;
      } else if (strstr_P(_gsm_serial_buffer, PSTR("ERROR\r"))) {
        return 1;
      }
    }
  } while (millis() - t < timeout);

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

      if (expected) {
        if (strstr(_gsm_serial_buffer, expected)) {
          return 0;
        } else if (strstr_P(_gsm_serial_buffer, PSTR("ERROR\r"))) {
          return 1;
        }
      } else {
        if (strstr_P(_gsm_serial_buffer, PSTR("OK\r"))) {
          return 0;
        } else if (strstr_P(_gsm_serial_buffer, PSTR("ERROR\r"))) {
          return 1;
        }
      }
    }
  } while (millis() - t < timeout);
