Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Send more than one SMS at the same time with SIMCom Sim 300

Status
Not open for further replies.

fernando_castro

Newbie level 4
Joined
Mar 10, 2011
Messages
5
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Campo Grande, Mato Grosso do Sul, Brasil
Activity points
1,316
Hi everybody!

Yesterday I started to work with the SIMCOM_SIM300 GSM/GPRS Modem. And I've coded a C program that sends a SMS. Everything is ok! I can send and receive SMS normally. But my question is: can I send a message to several numbers at the same time, just like our regular cell phones? If yes, could anyone tell me how to do that?

I've already looked at google and the SIM300D_ATC pdf with no luck.

I tried this: AT+CMGS="06755555555","06766666666"
but only the first cell phone (55555555) got the message.

Thanks a lot
 

you cannot send it like this and nor does normal cell phones do that way. they send data one by one and cell phone uses message queue mechanism to do it ... so you need to send the data to different numbers using some loop where you store the number in an array and call this array seperately...
 
Thanks for the prompt replay ckshivaram.

I already expected this was not possible :) I'll change my C program to do some kind of loop, or a FIFO stack with the numbers. Than I'll came back here to post the results and the source code. Maybe someone need it, right!?

Best regards

PS. I'll not close the thread yeat, as I said before, I'll post a feedback here.
 

Hi folks..

As I said before, here is my C code to send SMS from linux, if someone needs..

The code is very simple and straightforward. Just to send one SMS message. Based on it, my application sends about 300 messages per day. With no problem.

The code is based on this fine tutorial (Serial Programming Guide for POSIX Operating Systems)

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>

#define STANDARD_BAUDRATE	B115200
#define MODEM_TTY "/dev/ttyS0"

static int open_port(void)
{
	int fd;
	fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
	if (fd == -1)
	{
		perror("open_port: Unable to open /dev/ttyS0 - ");
	}
	else
		fcntl(fd, F_SETFL, 0);

	return (fd);
}

static int sendModemChars(int fd, char *phone, char *msg)
{
	char buffer[255], *bufptr, foo[255];
	int  nbytes, msgLen;
	const char byte = 26;

	memset(buffer, 0x00, sizeof(buffer));
	memset(foo, 0x00, sizeof(foo));
	msgLen = strlen(msg);

	if (write(fd, "AT\r", 3) < 3)
	{
		printf("command AT failed!\n");
		return -1;
	}
	/* ler os caracteres retornado pelo MODEM */
	bufptr = buffer;
	while ( ( nbytes = read( fd, bufptr, (255 - 1) ) ) > 0 )
		bufptr += nbytes;

	*bufptr = '\0';
	nbytes = strlen(buffer);
	printf("command: %s\n", buffer);
	if (strncmp(&buffer[nbytes-4], "OK", 2) != 0)
	{
		printf("MODEM NOT_OK!!");
		return (-1);
	}

	printf("MODEM OK!!\n");
	sprintf(foo, "AT+CMGS=\"%s\"\r", phone);
	/* enviar comando para SMS do mondem */
	if (write(fd, foo, 25) < 25)
	{
		printf("comando AT+CMGS=\"%s\" falied!\n", phone);
		return -1;
	}
	memset(buffer, 0x00, sizeof(buffer));
	bufptr = buffer;
	while ( ( nbytes = read( fd, bufptr, (255 - 1) ) ) > 0 )
		bufptr += nbytes;

	*bufptr = '\0';
	nbytes = strlen(buffer);
	if (strncmp(&buffer[nbytes+5], ">", 1) == 0)
	{
		memset(foo, 0x00, sizeof(foo));
		sprintf(foo, "%s%c", msg, byte);
		if (write(fd, foo, (msgLen+1)) < (msgLen+1))
		{
			printf("msg Buffer failed.\n");
			return -1;
		}
		while ( ( nbytes = read( fd, bufptr, (255 - 1) ) ) > 0 ) /*just read*/

		sleep(2);
		memset(buffer, 0x00, sizeof(buffer));
		bufptr = buffer;
		while ( ( nbytes = read( fd, bufptr, (255 - 1) ) ) > 0 )
			bufptr += nbytes;

		*bufptr = '\0';
		nbytes = strlen(buffer);
		if (strncmp(&buffer[nbytes-4], "OK", 2) == 0)
		{
			printf("%s\n", buffer);
			return (0);
		}
		else return (-1);
	}
	return (-1);
}

int main( int argc, char *argv[] )
{
	int fd, ret;
	struct termios options;
	char phone[12+1], msg[160+1];

	memset(phone, 0x00, sizeof(phone));
	memset(msg, 0x00, sizeof(msg));
	memcpy(msg, "TEST SMS", 8);
	if(argc < 2 || argc > 2)
	{
		printf("Oops.. phone number??\n");
		exit(EXIT_FAILURE);
	}
	memcpy(phone, argv[1], strlen(argv[1]));
	fd = open_port();
	if ( fd < 0 )
	{
		perror(MODEM_TTY);
		exit(-1);
	}

	/* get the current options */
	tcgetattr(fd, &options);

	/* set raw input, 1 second timeout */
	options.c_cflag     |= ( CLOCAL | CREAD );
	options.c_lflag     &= ~(ICANON | ECHO | ECHOE | ISIG);
	options.c_oflag     &= ~OPOST;
	options.c_cc[VMIN]  = 0;
	options.c_cc[VTIME] = 10;

	/* set the options */
	tcsetattr(fd, TCSANOW, &options);

	ret = sendModemChars(fd, phone, msg);
	if ( ret == -1 )
		printf("modem NOK!!\n");

	close(fd);
	return 0;
}

regards
 
  • Like
Reactions: picpen

    picpen

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top