SIM800 - How to send mms with c++

532 views Asked by At

I have a project where I have to send an mms on a raspberry via the sim800 shield, I have at the beginning to test with a program in python which works but when I pass in c++ I do not manage to make the passage.

Here is the program in python

# coding=utf-8
import serial
import RPi.GPIO as GPIO      
import time


#Activation du port série
phone = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)

phone.write('AT+CMMSEDIT=0\r')
time.sleep(1)

phone.write('AT+CMMSTERM\r')
time.sleep(1)

phone.write('AT\r\n')
time.sleep(1)

phone.write('AT+CMMSINIT\r\n')
time.sleep(2)

phone.write('AT+CMMSCURL=\"mms1\"\r')
time.sleep(1)

phone.write('AT+CMMSCID=1\r')
time.sleep(1)

phone.write('AT+CMMSPROTO=\"10.151.0.1\",8080\r')
time.sleep(1)

phone.write('AT+CMMSSENDCFG=6,3,0,0,2,4,1,0\r')
time.sleep(1)

phone.write('AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r')
time.sleep(1)

phone.write('AT+SAPBR=3,1,\"APN\",\"sl2sfr\"\r')
time.sleep(1)

phone.write('AT+SAPBR=1,1\r')
time.sleep(4)

phone.write('AT+SAPBR=2,1\r')
time.sleep(1)

phone.write('AT+CMMSEDIT=1\r')
time.sleep(1)

phone.write('AT+CMMSDOWN=\"PIC\",85102,200000,\"/home/pi/Downloads/bastien.png\"\r') 
time.sleep(1)

photo = open ("/home/pi/Downloads/bastien.png", "r")
dataphoto = photo.read()

phone.write(dataphoto)
time.sleep(1)

phone.write('\rAT+CMMSRECP=\"+336274xxxx\"\r')
time.sleep(1)

phone.write('AT+CMMSVIEW\r')
time.sleep(1)

phone.write('AT+CMMSSEND\r')
time.sleep(15)

phone.write('AT+CMMSEDIT=0\r')
time.sleep(1)

phone.write('AT+CMMSTERM\r')
time.sleep(1)

photo.close()

and this is what I tried in c++

  long lSize;
  char * buffer;
  size_t result;   
int connection=0;


printf("Opening connection \n");
connection = serialOpen("/dev/ttyS0", 9600);
delay(1000);
printf("Connection:  %d\n", connection);
printf("\n");
serialPuts(connection,"AT+CMMSEDIT=0\r");
delay(1000);
serialPuts(connection,"AT+CMMSTERM\r");
delay(1000);0
delay(1000);
serialPuts(connection,"AT+CMMSINIT\r\n");
delay(1000);
serialPuts(connection,"AT+CMMSCURL=\"mms1\"\r");
delay(1000);
serialPuts(connection,"AT+CMMSCID=1\r");
delay(1000);
serialPuts(connection,"AT+CMMSPROTO=\"10.151.0.1\",8080\r");
delay(1000);
serialPuts(connection,"AT+CMMSSENDCFG=6,3,0,0,2,4,1,0\r");
delay(1000);
serialPuts(connection,"AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r");
delay(1000);
serialPuts(connection,"AT+SAPBR=3,1,\"APN\",\"sl2sfr\"\r");
delay(1000);
serialPuts(connection,"AT+SAPBR=1,1\r");
delay(1000);
serialPuts(connection,"AT+SAPBR=2,1\r");
delay(1000);
serialPuts(connection,"AT+CMMSEDIT=1\r");
delay(1000);
serialPuts(connection,"AT+CMMSDOWN=\"PIC\",6793,80000,\"mon-image.jpg\"\r"); 
  pFile = fopen ( "/home/pi/Pictures/mon-image.jpg" , "rb" );
  if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

  // obtain file size:
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);

  // allocate memory to contain the whole file:
  buffer = (char*) malloc (sizeof(char)*lSize);
  if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}

  // copy the file into the buffer:
  result = fread (buffer,1,lSize,pFile);
  if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
  printf("%s",buffer);
serialPuts(connection,buffer);
serialPuts(connection,"\rAT+CMMSRECP=\"+33627xxxxxx\"\r");
delay(1000);
serialPuts(connection,"AT+CMMSVIEW\r");
delay(1000);
serialPuts(connection,"AT+CMMSSEND\r");
delay(15000);
serialPuts(connection,"AT+CMMSEDIT=0\r");
delay(1000);
serialPuts(connection,"AT+CMMSTERM\r");
delay(1000);

  fclose (pFile);
  free (buffer);

For the c++ I think the problem comes from the reading of the image but after many attempts that did not work I still did not solve the problem.

thanks for helping me

0

There are 0 answers