1

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

julien L
  • 11
  • 1
  • Your sleeps are shorter for the C++ version if you compare them, this might be the cause of the error. Is there any way for you to wait for the command to finish instead of relying on sleeps? Otherwise, try matching the sleep times to your python version to make sure they're a 1-to-1 match. – lfxgroove May 06 '21 at 07:59
  • I just put the sleeps at the same time as on the python version but the error is the same, when I look at the error display when the image recovery command runs it shows me "CME ERROR: This operation is overtime" – julien L May 06 '21 at 08:36
  • Not sure what that might mean unfortunately, try taking a look at the documentation for CMMSDOWN here: https://www.microchip.ua/simcom/2G/SIM800%20Series_AT%20Command%20Manual_V1.12.pdf. It might be that you've set a too short time for the image to be transmitted (80000 ms). Try using the exact same image as you did in your Python version and see if that might work. Try removing your `printf("%s", buffer);` aswell as that probably takes a fair amount of time, during which the SIM module expects data. Other than that I'm not sure what it might be. – lfxgroove May 17 '21 at 06:39

0 Answers0