|
|
SMS Server Tools 3 Community |
Welcome, Guest. Please login or register. |
Wed Apr 24, 2024 04:10 |
Login and Post Reply
Page: 1
Author |
Post |
|
#1 Thu Aug 11, 2011 16:05, 154 months ago.
|
Member
Registered: May 2011
Location: Lima, Peru
|
Operating system name and version: Debian Version of smsd: 3.1.14 Smsd installed from: sources Name and model of a modem / phone: SIMCOM SIM 600 Interface: UART
Hi again;
I am testing a SIM600 modem, and when I don't use check_memory_method = 5 it doesn't work, not even can get connected to it. So I looked into modeminit.c and modeminit.h and also smsdcfg.c and smsdcfg.h I found just once AT+CMGL=?
And couldn't get the specific idea of how to initialize this modem.
Could you please show me exactly the code lines for initializing this modem? I mean what is the code involved when a check_memory_method=5 is used?
Thanks
|
|
#2 Sun Aug 14, 2011 20:36, 154 months ago.
|
Member
Registered: May 2011
Location: Lima, Peru
Topic owner
|
Here I show the log, first and last one with check_memory_method = 5, and the middle one with out this configuration. So when I don't use check_memory_method = 5 the program is not able to connect and get an OK from the modem because a protocol error. When I use minicom it always get connected. So I want to know what check_memory_method does in order to get connected to the SIM600 modem.
2011-08-10 17:13:54,7, smsd: All PID's: 2140,2142 2011-08-10 17:13:54,6, smsd: Running a regular_run. 2011-08-10 17:13:54,7, smsd: Running regular_run (mainprocess): /home/gustavo/intentamyce 2011-08-10 17:13:54,5, GSM1: Modem handler 0 has started. PID: 2142. 2011-08-10 17:13:54,7, smsd: Done: regular_run (mainprocess), execution time 0 sec., status: 0 (0) 2011-08-10 17:13:54,5, GSM1: Using check_memory_method 5: CMGL is used. SIM600 compatible, see the manual for details. 2011-08-10 17:13:54,6, GSM1: I have to send 1 short message for /var/spool/sms/checked/answerPo0Ioz 2011-08-10 17:13:54,6, GSM1: Sending SMS from to 997104794 2011-08-10 17:13:54,6, GSM1: Checking if Modem ready 2011-08-10 17:13:54,7, GSM1: -> AT 2011-08-10 17:13:54,7, GSM1: Command Sent, Waiting answer 2011-08-10 17:13:55,7, GSM1: <- OK
-------------------------------------------------------------------------------------------
2011-08-10 17:15:18,7, smsd: All PID's: 2316,2318 2011-08-10 17:15:18,6, smsd: Running a regular_run. 2011-08-10 17:15:18,7, smsd: Running regular_run (mainprocess): /home/gustavo/intentamyce 2011-08-10 17:15:18,5, GSM1: Modem handler 0 has started. PID: 2318. 2011-08-10 17:15:18,7, smsd: Done: regular_run (mainprocess), execution time 0 sec., status: 0 (0) 2011-08-10 17:15:19,3, GSM1: Couldn't open serial port /dev/ttyUSB0, error: Protocol error, Waiting 30 sec. 2011-08-10 17:15:50,3, GSM1: Couldn't open serial port /dev/ttyUSB0, error: Protocol error 2011-08-10 17:15:50,2, GSM1: Modem handler 0 terminated. PID:
-------------------------------------------------------------------------
2011-08-10 17:15:55,7, smsd: All PID's: 2415,2417 2011-08-10 17:15:55,6, smsd: Running a regular_run. 2011-08-10 17:15:55,7, smsd: Running regular_run (mainprocess): /home/gustavo/intentamyce 2011-08-10 17:15:55,5, GSM1: Modem handler 0 has started. PID: 2417. 2011-08-10 17:15:55,7, smsd: Done: regular_run (mainprocess), execution time 0 sec., status: 0 (0) 2011-08-10 17:15:55,5, GSM1: Using check_memory_method 5: CMGL is used. SIM600 compatible, see the manual for details. 2011-08-10 17:15:55,6, GSM1: I have to send 1 short message for /var/spool/sms/checked/answerPo0Ioz 2011-08-10 17:15:55,6, GSM1: Sending SMS from to 997104794 2011-08-10 17:15:55,6, GSM1: Checking if Modem ready 2011-08-10 17:15:55,7, GSM1: -> AT 2011-08-10 17:15:55,7, GSM1: Command Sent, Waiting answer 2011-08-10 17:15:56,7, GSM1: <- OK
Thanks!
|
|
#3 Wed Aug 17, 2011 14:56, 154 months ago.
|
Member
Registered: May 2011
Location: Lima, Peru
Topic owner
|
Hi keke; Good to see that you are here again Well I wrote a code in C(linux) just for sending sms it logs every step I do and the answer I receive from modem, tested it with Motorola phone and even android and it works well but when I try it with my SIM600 it doesn't work, it's basically the same format for every code for serial port. And in modeminit.c I found something similar obviously with the more features in modeminit.c but basically the same if I just want to send sms. But SIM600 only works with smstools with check_memory_method = 5. Could you please tell me what else needs this code from "check_memory_method = 5" in order to work well with this modem? When I use the modem with minicom it goes well at first, but sometimes if I test it first with smstools(without check_memory_method=5) or with a basic code for serial port and modem doesn't answer; then when I try minicom again, the message "Protocol error" or "Permission denied" or "Modem blocked" appears Here is what I tried Thanks in advance! #ifndef SERIAL_H #define SERIAL_H
speed_t baud_to_speed_t(int baudrate) { switch (baudrate){
case 460800: return B460800; //default baudrate for my modem
case 115200: return B115200; case 19200: return B19200; default: log_event (LOG_WRN, "Velocidad no soportada, default 19200"); return B19200; } }
int set_serial_fd(const char *device, int baudrate, int databits, char parity, int stopbits) { //Seteo de la interfaz serial //Baudrate: 19200, 4800, 2400 //Parity: 'E'o'e' = Par, 'O' o 'o' = Impar, 'N' o 'n' u otro = Sin Paridad
struct termios newtio;
int m_fd, mcs = 0;
log_event (LOG_DBG, "intentando acceder a dispositivo serial: %s ", device); if (strlen (device) == 0){ log_event (LOG_ERR , "Dispositivo de comunicacion erroneo"); return -1; } if (( m_fd = open ( device, O_RDWR | O_NOCTTY | O_NDELAY ) ) < 0 ){ log_event (LOG_ERR,"Error abriendo dispositivo serial: %s", __curerr); return m_fd; }
memset (&newtio, 0, sizeof (newtio));
//baudrate cfsetospeed (&newtio, baud_to_speed_t(baudrate)); cfsetispeed (&newtio, baud_to_speed_t(baudrate));
//databits //newtio.c_cflag = (newtio.c_cflag & ~CSIZE) | CS8; newtio.c_cflag &= ~CSIZE; switch (databits){ case 5: newtio.c_cflag |= CS5;break; case 6: newtio.c_cflag |= CS6;break; case 7: newtio.c_cflag |= CS7;break; case 8: newtio.c_cflag |= CS8;break; default: newtio.c_cflag |= CS8; log_event(LOG_WRN, "Databits no soportado, default: 8"); break; }
//stop bits switch (stopbits){ case 1: newtio.c_cflag &= ~CSTOPB; case 2: newtio.c_cflag |= ~CSTOPB; break; default: log_event(LOG_WRN, "Stopbits no soportado, default: 1"); newtio.c_cflag &= ~CSTOPB; break; } //parity switch(parity){ case 'E': //Par case 'e': newtio.c_cflag |= PARENB; newtio.c_cflag &= ~PARODD; break; case 'O': //Impar case 'o': newtio.c_cflag |= PARENB; newtio.c_cflag &= ~PARODD; break; case 'N': //Impar case 'n': newtio.c_cflag &= ~PARENB; break; default://Sin paridad newtio.c_cflag &= ~PARENB; log_event(LOG_WRN, "Parity no soportado, default: SIN PARITY"); break; }
newtio.c_cflag |= CLOCAL | CREAD; //hardware handshake newtio.c_cflag &= ~CRTSCTS; newtio.c_cflag &= ~CSTOPB; newtio.c_iflag = IGNBRK;
//software handshake newtio.c_iflag |= IXON | IXOFF; newtio.c_lflag = 0; newtio.c_oflag = 0;
//control characters newtio.c_cc[VTIME] = 1; //tiempo de espera para datos (1=0.1) newtio.c_cc[VMIN] = 0; //minimo de caracateres a leer
//tcflush(m_fd, TCIFLUSH); if (tcsetattr (m_fd, TCSANOW, &newtio) != 0) log_event (LOG_ERR, "tcsetatty fallo: %s", __curerr); ioctl (m_fd, TIOCMGET, &mcs); mcs |= TIOCM_RTS; ioctl (m_fd, TIOCMSET, &mcs);
if (tcgetattr (m_fd, &newtio)!=0) log_event (LOG_ERR, "tcgetattr fallo: %s", __curerr); if (tcsetattr (m_fd, TCSANOW, &newtio) != 0) log_event (LOG_ERR, "tcgetattr fallo: %s", __curerr);
return m_fd; }
#endif
-----------------------------
#define ATCMD_SET_AT_MODE "AT\r" #define LEN_ATCMD_SET_AT_MODE 3
#define ATCMD_SET_FMT_TXT_MODE "AT+CMGF=1\r" #define LEN_ATCMD_SET_FMT_TXT_MODE 10
#define ATCMD_SET_DST_CEL_SMS "AT+CMGS=\"%s\"\r" #define LEN_ATCMD_SET_DST_CEL_SMS 11
#define ATDEF_OK "OK" #define ATDEF_ERROR "ERROR"
bool at_send_sms_msg(int fd, char *cel_num, char *msg) { //El msg tiene que ser terminado en \0
int ret; char buff[255], cmd_cel[255] = {0}, msg_tmp[255] = {0}; bool res;
snprintf(cmd_cel, 255, ATCMD_SET_DST_CEL_SMS, cel_num); ret = write_packet(fd, cmd_cel, LEN_ATCMD_SET_DST_CEL_SMS + strlen(cel_num));
if (ret < 0){ return -1; }
ret = read_packet(fd, buff);
res = check_at_command(cmd_cel, LEN_ATCMD_SET_DST_CEL_SMS, buff, ret);
if (res == true){ log_event(LOG_DBG, "set destination cel [OK]"); } else{ log_event(LOG_DBG, "set destination cel [ERROR]"); return false; }
bzero(msg_tmp, 255); strncat(msg_tmp, msg, 254); msg_tmp[strlen(msg_tmp)] = 0x1A; //CTRL + Z ret = write_packet(fd, msg_tmp, strlen(msg_tmp) + 2); sleep(10); bzero(buff, 255);
ret = read_packet(fd, buff);
return true; }
bool at_set_fmt_txt_mode(int fd) { int ret; char buff[255]; bool res; ret = write_packet(fd, ATCMD_SET_FMT_TXT_MODE, LEN_ATCMD_SET_FMT_TXT_MODE);
if (ret < 0){ return false; }
ret = read_packet(fd, buff);
res = check_at_command(ATCMD_SET_FMT_TXT_MODE, LEN_ATCMD_SET_FMT_TXT_MODE, buff, ret);
if (res == true){ log_event(LOG_DBG, "set format to TEXT mode [OK]"); } else{ log_event(LOG_DBG, "set format to TEXT mode [ERROR]"); } return res; }
bool at_set_at_mode(int fd) { int ret; char buff[255]; bool res; ret = write_packet(fd, ATCMD_SET_AT_MODE, LEN_ATCMD_SET_AT_MODE);
if (ret < 0){ return -1; }
ret = read_packet(fd, buff);
res = check_at_command(ATCMD_SET_AT_MODE, LEN_ATCMD_SET_AT_MODE, buff, ret);
if (res == true){ log_event(LOG_DBG, "set AT mode [OK]"); } else{ log_event(LOG_DBG, "set AT mode [ERROR]"); } return res; }
bool check_at_command(char *at_cmd, size_t len_cmd, char *at_answ, size_t len_answ) {
if (memcmp(at_cmd, at_answ, len_cmd) == 0) { if (memcmp(at_answ + len_cmd + 2, ATDEF_OK, 2) == 0) //+2 por el cr cl return true; else {//+2 por el cr cl if (memcmp(at_answ + len_cmd + 2, ATDEF_ERROR, 5) == 0) return false; else return true; } } log_event(LOG_DBG,"unknow answer");
return false; }
int read_packet(int fd, char *buff) { struct timeval timeout; fd_set readfs; int ret, all_ret = 0; char buff_part[255]; char buff_prnt[255]; bool once = true;
FD_ZERO (&readfs); FD_SET (fd, &readfs); while (1){ timeout.tv_usec = 10000; //1 milisegundo timeout.tv_sec = 1; //0 segundos if ( select (fd + 1, &readfs, NULL, NULL, &timeout) <= 0 ){ if (once){ log_event(LOG_DBG, "Error leyendo: Timeout"); all_ret = -1; break; }
all_ret = once ? -1 : all_ret; break; }
bzero(buff_part, 255);
ret = read (fd, buff_part, 255); memcpy(buff + all_ret, buff_part, ret);
all_ret += ret;
if (ret < 0){ log_event(LOG_ERR, "reading error: %s", __curerr); all_ret = -2; break; }
once = false; }
bzero(buff_prnt, 255);
bytes_to_str(buff, all_ret, buff_prnt);
log_event(LOG_DBG, "<-- %s", buff_prnt); return ret; }
int write_packet(int fd, char *buff, size_t len) { int ret; char buff_prnt[255];
ret = write(fd, buff, len); if (ret < 0){ log_event(LOG_ERR, "writing error: %s", __curerr); }
bzero(buff_prnt, 255);
bytes_to_str(buff, ret, buff_prnt);
log_event(LOG_DBG, "--> %s", buff_prnt);
return ret; } 'c' Syntax Highlight powered by GeSHi
|
|
#4 Thu Aug 18, 2011 14:30, 154 months ago.
|
Member
Registered: May 2011
Location: Lima, Peru
Topic owner
|
Any news?
|
|
#5 Wed Aug 24, 2011 11:35, 154 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
Your problem is very weird, probably there is something wrong with drivers or libraries. In your previous topic P300U, SIM600 based modem not working there was a problem with UART, and I assume that you have resolved it. At that time the error was received for AT command, byt now your system cannot open the port. The setting check_memory_method should have nothing to do with your current problem. It just defines a way how incoming messages are handled, and nothing more. And you should use this setting, because SIM600 requires it. When testing the setting in post #2, I assume that it has been the only change in the configuration, is this correct? And you made the test many times? If this is the case, you could ensure that smsd is properly compiled and up to date, by executing make clean smsd. I did not review your C code deeply, but your testing shows that you should try to upgade the driver of serial port.
|
Login and Post Reply
Page: 1
Time in this board is UTC.
|
|
|
|
|
|
|