0

I am trying to send sms using at commands in c program. I am able to send the sms successfully sometimes. However during sometimes i will not be able to send the sms. In that case i am getting CMS ERROR as Buffer Overflow. This is random case.

Could anyone help regarding this issue. What does the buffer overflow indicate? How should we debug this issue? This is happening randomly. Sometimes while testing, in all cases the sms will be sent successfully. But sometimes we will get this error.

My code snippet is given below:

int fd_at;
char at_cmd[25];
char *number = "+91xxxxxxxxxx";
fd_at = open("/dev/ttyUSB2", O_RDWR | O_NOCTTY);
sprintf(at_cmd, "AT+CMGF=1\r");
ret = write(fd_at, at_cmd, strlen(at_cmd));
sprintf(at_cmd, "AT+CMGS=\"%s\"\r", number);
ret = write(fd_at, at_cmd, strlen(at_cmd));
ret = write(fd_at, "Hello\032", 6);
close(fd_at);

I have checked the return values of write in all cases. In all cases it is a showing the value needed. Is there any other thing needed for sending sms other than this.

Please help.

The error i am getting is given below.

+CMS ERROR: Buffer overflow

Thanks

Niks
  • 1
  • 2
  • Does it randomly happen with same data or with different length messages? How do you check your result codes? – Gerhardh Jul 18 '17 at 12:19
  • It happens randomly with same data also. – Niks Jul 18 '17 at 12:39
  • @Gerhardh It happens randomly with same data also. We have written a function to read the response of AT commands in a node. – Niks Jul 18 '17 at 13:00
  • 1
    It might help to wait for a response from your modem before sending the next command – Ctx Jul 18 '17 at 14:47
  • Is the function to read the response called in a different thread? How do you match responses to the related commands? – Gerhardh Jul 18 '17 at 15:09
  • @Ctx i tried with usleep(50000) but still got the issue. – Niks Jul 18 '17 at 15:41
  • @Gerhardh we are not using another thread for reading the response. – Niks Jul 18 '17 at 15:42
  • @Niks 50ms is not much when talking to a GSM modem, you should really try to wait for each command ack/nak before sending the next. – Ctx Jul 18 '17 at 16:54
  • @Ctx ok will try with much more delay. – Niks Jul 18 '17 at 17:52
  • **NO!** Using `delay` is [never OK](https://stackoverflow.com/a/15591673/23118). You must [**read and parse**](https://stackoverflow.com/a/35531529/23118) the responses you get. – hlovdal Aug 06 '17 at 00:43

0 Answers0