|
|
SMS Server Tools 3 Community |
Welcome, Guest. The forum is currently read-only, but will open soon. |
Fri Mar 14, 2025 10:50 |
Page: 1
Keywords: Mode: All keywords (AND) |
Thu Aug 18, 2011 14:30
|
|
Wed Aug 17, 2011 20:03
|
tavillo: Hi;
I hadrecently started with smstools and had a similar question like you...
So, you have to config an eventhandler(is a script that runs as soon as the sms is received)
and the script is something like this... You have to edit the numbers that you want to be the recipients, in this case is for answering to the same number that sent the sms...
Hope this helps you.
Good luck
#!/bin/sh
# Please read the description in the manual of SMS Server Tools.
#run this script only when a message was received.
if [ "$1" != "RECEIVED" ]; then exit; fi;
#Extract data from the SMS file
FROM=`formail -zx From: < $2`
TEXT=`formail -I "" <$2 | sed -e"1d"`
#Create an answer SM with the amount
FILENAME=`mktemp /var/spool/sms/outgoing/answerXXXXXX`
echo "To: $FROM" >$FILENAME
echo "" >> $FILENAME
echo "$TEXT" >>$FILENAME
|
Wed Aug 17, 2011 14:56
|
tavillo: Hi keke; Good to see that you are here again :D
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 :shock:
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;
}
|
Sun Aug 14, 2011 20:36
|
tavillo: 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!
|
Thu Aug 11, 2011 16:05
|
tavillo: 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
|
Sat Aug 06, 2011 16:43
|
tavillo: Thanks man!
Finally I succeded in doing this.
VBS creates textfiles with unicode encoding by default so it was necessary to create the textfile using ANSI encoding.
And yes, there are 2 arguments that I had to capture, the only "trouble" was that the argument that gives the location of file is in unix format I mean /var/spool/sms/incoming/XXXX.XXXXXX
So it was necessary to put it in wind@w$ format \var\spool\sms...
Really interesting days being an absolutelly noob, lol! Thanks a lot for the tips man!
Now my last game it's only to work with 2 modems one for sending and one for receiving SMS configuring them with the required incoming = yes and outgoing = no, and viceversa.
Thanks again man!
|
Fri Aug 05, 2011 17:38
|
tavillo: Hi again;
I am still in the sending part, I don't attack the receiving yet :(
Well I already created an .exe file which I use in regular_run and it connects to SQL, read data from it and creates a text file in the outgoing directory with the next format
To: 9999999
This is a Test or whatever
My problem is that this text file created as soon as it's in outgoing directory goes to Failed directory, log says No destination defined and when I open the text file in Failed directory it says
□□□□>□□□□□□□□□□□□□□□□□□□□□□This is a Test or whatever
So obviously there is no destination
When I create the text file manually every thing is ok.
Please can you tell me what difference can you find between this 2 text files with exactly the same info? :S
Text File(Manually created) 38 bytes
http://www.bigupload.com/en/file/11075/gsm1.7rc7ah.html
Text File(.exe created) 80 bytes
http://www.bigupload.com/en/file/11077/gsm1.qamfmn.html
Please tell me what difference you find so I can then look into the code but actually the code creates the text file :shock:
Thanks!
|
Thu Aug 04, 2011 19:47
|
tavillo: Ok keke thanks and sorry I didn't paste the python code I used, actually is the one from this forum :)
My confussion is the next one...
$1 is the same variable for VBS?
$2 the same variable for VBS?
I get a little bit confused about how smstools works. I already made 2 different vb scripts for eventhandler and for regular run, and both run.
But, I want to know, this $1(flag for received) where does the script read it from?
If there are more than 1 sms in incoming folder, how will this script know which one is the new sms?
Sorry for so many questions :(
#!/bin/sh
# Please read the description in the manual of SMS Server Tools.
#run this script only when a message was received.
if [ "$1" != "RECEIVED" ]; then exit; fi;
#Define the database parameters
SQL_HOST=localhost
SQL_USER=user
SQL_PASSWORD=password
SQL_DATABASE=mydatabase
SQL_TABLE=tablemysql
#Extract data from the SMS file
FROM=`formail -zx From: < $2`
TEXT=`formail -I "" <$2 | sed -e"1d"`
#Set some SQL parameters
if [ "$SQL_PASSWORD" != "" ]; then
SQL_ARGS="-p$SQL_PASSWORD";
else
SQL_ARGS="";
fi
SQL_ARGS="-h $SQL_HOST -u $SQL_USER $SQL_ARGS -D $SQL_DATABASE -s -e"
#Do the SQL Query
#mysql $SQL_ARGS "UPDATE $SQL_TABLE SET stat=\"1\" WHERE cel=\"$FROM\";"
mysql $SQL_ARGS "insert into $SQL_TABLE (cel,txt) values (substring(\"$FROM\",-9),\"$TEXT\");"
#Create an answer SM with the amount
#FILENAME=`mktemp /var/spool/sms/outgoing/answerXXXXXX`
#echo "To: $FROM" >$FILENAME
#echo "" >> $FILENAME
#echo "Your amount is $AMOUNT" >>$FILENAME
|
Thu Aug 04, 2011 16:43
|
tavillo: You're right, thanks a lot!
Actually I used an .exe file and it works.
Now I have a new "homework" How to deal with sending and receiving sms in smstools through vb?
For sending well I'll have to look for info in order to create a file with certain format located in var/spool/sms/outgoing using VB.
But when eventhandler(new sms is received), what does smstools do? Because in the example in python the code never opens the file(sms received) it just check If $1 = Received, and now it's a different language, running outside cygwin(I mean the .exe app created) So how could I "translate" the python code to vb, what considerations should I have?
Please could you give me any tip for this?
Thanks!
|
Wed Aug 03, 2011 23:02
|
tavillo: Hi again;
Well I tried to do by "linux" side I mean I installed freetds, unixODBC, python.
I tried to install pyodbc and pymssql without success and I couldnt succed in cygwin for connecting sql server :(
Then I tried visual studio, actually I used a code for VB 2005 and it worked on windows side, but when I put it like an eventhandler for smstools under cygwin, if I give a path like /home/myapp.vbs then in smsd.log I see that it tries to execute each line of code and obviously it get errors because it's not a prog language known for cygwin.
When I give C:\directorytest\myapp.vbs I see in smsd.log the message "C:\directorytest\myapp.vbs is not executable for smsd
Definitely I guess I'm being really a big noob but can't succeed into it.
keke you mentioned "You can use MS SQL with eventhandler, if you have suitable command line interface available. I do have examples about those, because most systems runs under Linux" so please can you post those examples please?
I wanted to use python because I already tested extracting info from sms with it, but I guess it's not possible under cygwin.
Thanks in advance!
|
Mon Aug 01, 2011 16:41
|
tavillo: Ok;
Well actually I have to say that I'm newbie at programming. So that's why smstools is really useful for me.
I already use mysql database, but I need using smstools under windows(specifically 2003 server) and read&write from Ms SQL database located in the same server.
As I see, definitely you know how to do this. Well I connected before to Ms Sql using visual basic code; my question is, if I put this code in eventhandler, will it work without any other driver under cygwin? Or maybe it gives error?
Thanks!
Gustavo
|
Mon Aug 01, 2011 15:52
|
tavillo: Hi again;
I've been testing smstools with excellent results about what I wanted I mean eventhandler and regular run working with MySql under Debian Linux.
Everything is great.
Then I succeeded in "migrating" smstools from Linux to window$ but my new "homework" is getting eventhandler and regular run working with ms sql under window$.
Can you tell me if I need new drivers, new libraries, or if this is possible? :S
Or I should get anyway to "migrate" the full code of smstools to window$ so I can use smstools like any window$ application and then I can use the window$ libraries for connecting ms sql? :S
If there is any example of how to connect to a ms sql from smstools(cygwin) please tell me, thanks!
Gustavo :P
|
Fri Jul 08, 2011 19:22
|
tavillo: It's just text only 'a-z''A-Z''0-9' and blank spaces with no other symbols. I tested with 4 incoming SMS with more than 50 chars but when it's transfered to MySql it always get the first 50 chars.
I will test with your recommendation.
|
Fri Jul 08, 2011 17:30
|
tavillo: Actually was my mistake, smstools is correctly getting the full incoming sms. But when I use sample code for inserting incoming sms into MySql table, the text is not complete.
The field txt in MySql table is varchar(220) so it would fit any sms.
But I only get the first 50 chars in MySql table. How to fix this? Thanks!
The code is
#Extract data from the SMS file
FROM=`formail -zx From: < $2`
TEXT=`formail -I "" <$2 | sed -e"1d"`
#Set some SQL parameters
if [ "$SQL_PASSWORD" != "" ]; then
SQL_ARGS="-p$SQL_PASSWORD";
else
SQL_ARGS="";
fi
SQL_ARGS="-h $SQL_HOST -u $SQL_USER $SQL_ARGS -D $SQL_DATABASE -s -e"
#Do the SQL Query
#mysql $SQL_ARGS "UPDATE $SQL_TABLE SET stat=\"1\" WHERE cel=\"$FROM\";"
mysql $SQL_ARGS "insert into $SQL_TABLE (cel,txt) values (substring(\"$FROM\",-9),\"$TEXT\");"
|
Thu Jul 07, 2011 21:13
|
tavillo: Operating system name and version: Debian Squeeze
Version of smsd: 3.1.14
Smsd installed from: apt-get install
Name and model of a modem / phone: SIM548C
Interface: USB-Serial
Hi friends;
I want to know if it's possible to configure the max length of a sms. It's only that I am testing smstools with a modem just for receiving sms's and even the sms has 100 characters, smstools only get the first 50 chars.
Please tell me where can I configure this.
Thanks!
|
Mon Jul 04, 2011 19:44
|
tavillo: Yes Im still running smstools3 on debian.
I thought there would be a similar way of connecting to MS Sql, using eventhandler like the one posted for MySql.
Well I'll follow your instructions. PHP would be ok, so in eventhandler is not necessarily a python code?
Ok, then I hope you could get some time for releasing the new version :D
Thanks man!
|
Mon Jul 04, 2011 15:47
|
tavillo: Hi guys
First of all thanks for posting codes for MySql, really useful; but please could you help me showing the code for connecting to a MS Sql please?
Thanks in advance!
|
Fri Jun 17, 2011 22:04
|
tavillo: Ok, welll actually wht says in the log is protocol error, the program sends an AT command to the modem and this doesn't retunr the expected OK
So obviously my problem is that Linux is not recognizing my modem (P300U) based on SIM600 as a modem. I found that with this program I could succeed in connecting my modem but I CAN'T and it's necessary for me, please if someone knows a way of making this P300U modem work under Linux Debian, please let me know.
Thanks in advance.
|
Tue May 24, 2011 18:08
|
tavillo: Operating system name and version: Linus Debian Squeeze
Version of smsd: 3.1.14
Smsd installed from: sources
Name and model of a modem / phone: modem P300U
Interface: Cygnal Integrated USB to UART
I can't recognize this as a modem under linux. I configured with the option check_memory = 5 like said in instructions but nothing. Anyone whi had this problem please help me :(
No minicom, no nothing :(
|
Page: 1
Time in this board is UTC.
|
|
|
 |
|
 |
|