SIM900 MMS INIT ERROR

I am using the arduino mega 2560 board and the sim900 gsm module to send MMS ads to many numbers.
I can send one MMS and then when I want to send the second MMS, the AT+CMMSINIT commands returns ERROR.

Here’s my full code:

#include "SD.h"

#define PWR 31
#define CS 53

File dataFile;
int i;
unsigned char data = 0;
String message = "hello";

void setup() {
  pinMode(PWR, OUTPUT);
  pinMode(CS, OUTPUT);
  Serial.begin(9600);
  Serial2.begin(9600); 
  
  digitalWrite(PWR, LOW);
  delay(10);
  digitalWrite(PWR, HIGH);
  delay(10);

  if (!SD.begin(CS)) Serial.println("init not ok!");
  else Serial.println("init ok.");
}

void loop() {
  
  if (Serial2.available()) {
    while (Serial2.available()) {
      data = Serial2.read();
      Serial.write(data);
    }
    data = 0;
  }

  if (Serial.available()) {
    data = Serial.read();
  }

  if (data == 'r') {
   Serial2.print("AT\r\n");  
  }

  if (data == 'a') {
   Serial2.print("AT+CSQ\r");   //signal quality
  }

  if (data == 'b') {
   Serial2.print("AT+CREG=0\r"); //enable network registration  
  }

  if (data == 'c') {
   Serial2.print("AT+CREG=?\r"); //current network registration  
  }

  if (data == 'd') {
   Serial2.print("AT+COPS=?\r"); //list of available operators  
  }

  if (data == 'e') {
   Serial2.print("AT+CREG=1\r"); //disable network registration  
  }

  if (data == 'f') {
   Serial2.print("AT+COPS?\r"); //current operator  
  }
  
  if (data == 'p') {
    Serial2.print("AT+CPIN=1234\r");
  }
  if (data == '1') {
    Serial2.print("AT+CGMI\r"); // Identification du fabricant
  }
  if (data == '2') {
    Serial2.print("AT+CGMM\r"); //Identification du modèle
  }

  if (data == '3') {
    Serial2.print("AT+CGMR\r"); //Version du Firmware
  }

  if (data == '4') {
    Serial2.print("AT+CGSN\r"); //Numéro IMEI
  }

  if (data == '5') {
    Serial2.print("ATDnumber;\r"); //Appels (ATD+numero à appeler)
  }

  if (data == '6') {
    Serial2.print("ATH\r"); //Racrocher un appel
  }

  if (data == '7') //Envoyer un SMS
  {
    Serial2.println("AT");
    delay(500);
    Serial2.print("AT+CMGF=1\r"); //Activation mode Texte
    delay(500);
    Serial2.println("AT+CMGS=\"number\""); //Numéro du destinataire
    delay(500);
    //Serial2.print(message);//Message à envoyer 
    Serial2.print("bonjour ceci est mon message"); //2eme methode pour envoyer un message 
    delay(500);
    Serial2.write((char) 26); //Envoi du message
  }

  if (data == '8') {
    Serial2.print("AT+CMGR=1\r"); //Lire message
  }

  if (data == '9') {
    Serial2.print("AT+CMGD=1,0\r"); //Effacer un message
  }
  if (data == 'd') {
    Serial2.print("ATDT\r"); //Décrocher un appel
  }

  if (data == 's') sendMMS(); //Envoyer un MMS
  data = 0;
}

void sendMMS() //Envoi de MMS avec paramètre APN La poste mobile
//Regarder sur le site des opérateurs pour les paramètres APN, MMSCURL, CMMSPROTO
{
  Serial2.println("AT+CMMSINIT");
  delay(1000); //100
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSCURL=\"mmsdebitel\"\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSCID=1\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSPROTO=\"10.143.156.003\",8080\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSSENDCFG=0,1,0,0,2,1,2,0\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=3,1,\"APN\",\"mmsdebitel\"\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=1,1\r");
  delay(4000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=2,1\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSEDIT=1\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSDOWN=\"PIC\",6313,2000000,\"image.jpg\"\r");

  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }

  dataFile = SD.open("image.jpg");
  i = 0;
  if (dataFile) {
    while (dataFile.available()) {
      data = dataFile.read();
      if (data < 0x10) Serial.print("0");
      Serial.print(data, HEX);
      i++;
      if ((i % 40) == 0) Serial.println();
      Serial2.write(data);
    }
    dataFile.close();
  } else {
    Serial.println("error opening image.jpg");
  }

  delay(1000);
  Serial2.print("AT+CMMSRECP=\"number\"\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSVIEW\r");
  delay(2000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSSEND\r"); //Envoi du MMS
  delay(2000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSEDIT=0\r");
  delay(2000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSTERM\r"); // Fin du MMS
  delay(2000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
}

If anyone has an idea…

Hi !

in void sendMMS() just use one time init. (ie: init configurations just one time or init. in setup() function)

this part :

{
  Serial2.println("AT+CMMSINIT");
  delay(1000); //100
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSCURL=\"mmsdebitel\"\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSCID=1\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSPROTO=\"10.143.156.003\",8080\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+CMMSSENDCFG=0,1,0,0,2,1,2,0\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=3,1,\"APN\",\"mmsdebitel\"\r");
  delay(1000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=1,1\r");
  delay(4000);
  if (Serial2.available()) {
    while (Serial2.available()) Serial.write(Serial2.read());
  }
  Serial2.print("AT+SAPBR=2,1\r");
  delay(1000);