SMS command line advice.

SMS command line advice. SearchSearch

SMS & MMS Technical Forum » NowSMS Support - SMS Issues (Product Support Only) » Archive through June 21, 2007 » SMS command line advice. « Previous || Next »
Author Message
Waleed Hameed
New member
Username: Waleed_k

Post Number: 12
Registered: 02-2007
Posted on Tuesday, April 03, 2007 - 10:27 am:   

Hello,
I would like to fiends out what wrong with my 2-way sms vbscript.

I am trying to use WSH & VBscript to be triggered when sms been received to log it into Access table.

The script is:-

command to execute: c:\windows\system32\wscript.exe c:\dbtest.vbs % "/sender:@@SENDER@@" "/prefix:@@SMSPREFIX@@" "/message:@@FULLSMS@@" % "/date:@@MSGDATE@@" "/time:@@MSGTIME@@"

------------------- dbtest.vbs ----------------------------

Set argsNamed = WScript.Arguments.Named

SenderTxt = argsNamed.Item("sender")
Prefix = argsNamed.Item("prefix")
Sms = argsNamed.Item("message")
Smstime = argsNamed.Item("time")
Smsdate = argsNamed.Item("date")

Dim strCN, objCN, objRS1, strSQL

strCN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & "database\db1.mdb"
Set objCN = WScript.CreateObject("ADODB.Connection")
objCN.Open strCN
Set objRS1 = objCN.OpenSchema(20)

strSQL = "INSERT INTO smstable ( [sender], [perfix], [sms], [smstime], [smsdate] ) VALUES ( '" & Sender & "','" & Prefix & "','" & Sms & "','" & Smstime & "','" & Smsdate & "')"

Set objRS1 = objCN.Execute(strSQL)


Set argsNamed = nothing

------------------------------------------------
The database connection is fully functioning, as when I force Sender= "some str" it does write it in the table. But it is not picking up the sms elements from the command to execute.

I used the same why of coding to log into file and i works perfectly.

Can some one give me some advice what might be wrong with my approach and code.

Thanks,

Waleed Hamed
MSc. Mobile Computing
Staffordshire University.
Waleed Hameed
New member
Username: Waleed_k

Post Number: 13
Registered: 02-2007
Posted on Wednesday, April 04, 2007 - 02:57 pm:   

hi again,

I am still working on the above issue. May i have some advice ASAP?

regards
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 7023
Registered: 10-2002
Posted on Wednesday, April 04, 2007 - 04:07 pm:   

Hi Waleed,

My only advice would be to enable the SMSDEBUG.LOG (checkbox on the "Serial #" page of the configuration dialog).

Send in another message, then look at the SMSDEBUG.LOG file, as this should show you exactly the command line that is being processed.

Then try issuing that same command manually, and see if you don't have the same problem (and you can then try manual variations to troubleshoot).

If the command works manually, but not from the 2-way ... then I have seen some programs that behave differently if they are run by the command processor (CMD.EXE), compared to being run directly. You can configure NowSMS to spawn the command processor to run your program by prefixing your command with:

c:\windows\system32\cmd.exe /c

(This assumes CMD.EXE is in c:\windows\system32, which is the default location, but it could be different on your system.)

-bn
Waleed Hameed
New member
Username: Waleed_k

Post Number: 14
Registered: 02-2007
Posted on Thursday, April 05, 2007 - 11:28 am:   

Hello Bryce,

Many thanks for the support. I changed to CMD.EXE with checking all the bath is right within the command to execute.
The script is:-

Command to execute: c:\windows\system32\cmd.exe c:\testdb.vbs % "/sender:@@SENDER@@" "/prefix:@@SMSPREFIX@@" "/message:@@FULLSMS@@" % "/date:@@MSGDATE@@" "/time:@@MSGTIME@@"

------------------- testdb.vbs ----------------------------

Set argsNamed = WScript.Arguments.Named

SenderTxt = argsNamed.Item("sender")
Prefix = argsNamed.Item("prefix")
Sms = argsNamed.Item("message")
Smstime = argsNamed.Item("time")
Smsdate = argsNamed.Item("date")

Dim strCN, objCN, objRS1, strSQL

strCN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & "database\db1.mdb"
Set objCN = WScript.CreateObject("ADODB.Connection")
objCN.Open strCN
Set objRS1 = objCN.OpenSchema(20)

strSQL = "INSERT INTO smstable ( [sender], [perfix], [sms], [smstime], [smsdate] ) VALUES ( '" & Sender & "','" & Prefix & "','" & Sms & "','" & Smstime & "','" & Smsdate & "')"

Set objRS1 = objCN.Execute(strSQL)


Set argsNamed = nothing

------------------------------------------------
When I test the script manually by setting:

SenderTxt = "test"
Prefix = "test"
Sms = "test"
Smstime = "test"
Smsdate = "test"

The database connection is working and the SQL gets executed. So the script is working fine, but when i link it to 2-way nothing happen.

I have the smsdebug file activated which it tell me nothing about the problem.
The funny thing is, I am receiving the SMS over and over???!!!! And each time the debug stops at execute for good 5-10min.

I have attached the SMSDEBUG file for your kind attention. Please let me know your advice about it......

Off this issue, how can I expand my knowledge about understanding the debug file statements? Have you got extra documentation about NowSMS Debug?

Well keep trying and thanks again for your help.

Regards,

Waleed Hamed
MSc.Mobile Computer System
Staffordshire University
application/octet-stream
SMSDEBUG.LOG (25.1 k)
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 7056
Registered: 10-2002
Posted on Thursday, April 05, 2007 - 06:06 pm:   

Hi Waleed,

Put a "/c" between cmd.exe and your command ...

For example:

c:\windows\system32\cmd.exe /c c:\testdb.vbs % "/sender:@@SENDER@@" "/prefix:@@SMSPREFIX@@" "/message:@@FULLSMS@@" % "/date:@@MSGDATE@@" "/time:@@MSGTIME@@"

Without the "/c", cmd.exe runs the command, but then it never terminates.

And actually, you still need to include c:\windows\system32\wscript.exe as well. So that would be:

c:\windows\system32\cmd.exe /c c:\windows\system32\wscript.exe c:\testdb.vbs % "/sender:@@SENDER@@" "/prefix:@@SMSPREFIX@@" "/message:@@FULLSMS@@" % "/date:@@MSGDATE@@" "/time:@@MSGTIME@@"


But as I think about this ... I might be leading you down the wrong path. If you are running a Windows script file, then you should not need to launch in this manner.

But you should be using cscript.exe instead of wscript.exe ...

Regarding what I was saying about the SMSDEBUG.LOG ... I was referring to the line in the file where it shows "Executing" and then a command line ... this is the exact command line that NowSMS is trying to executed.

For example, the following is from your log:

Executing c:\windows\system32\cmd.exe c:\testdb.vbs % "/sender:+447872840155" "/prefix:database" "/message:database test with cdm.exe" % "/date:20070405" "/time:122549"

So I'm suggesting that you try executing the exact same command from the command line to see if it works as you expect.

-bn
Waleed Hameed
New member
Username: Waleed_k

Post Number: 15
Registered: 02-2007
Posted on Thursday, April 19, 2007 - 09:19 am:   

Hello Bryce,
About the Issue of integrating with Database using 2-way sms command line written in WSH.
I have managed to log the SMS within access database by using the code bellow:

Command to execute: c:\windows\system32\cmd.exe c:\testdb.vbs % "/sender:@@SENDER@@" "/prefix:@@SMSPREFIX@@" "/message:@@FULLSMS@@" % "/date:@@MSGDATE@@" "/time:@@MSGTIME@@"

------------------- testdb.vbs ----------------------------

Set argsNamed = WScript.Arguments.Named

SenderTxt = argsNamed.Item("sender")
Prefix = argsNamed.Item("prefix")
Sms = argsNamed.Item("message")
Smstime = argsNamed.Item("time")
Smsdate = argsNamed.Item("date")

Dim strCN, objCN, objRS1, strSQL

strCN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & "c:\database\db1.mdb"
Set objCN = WScript.CreateObject("ADODB.Connection")
objCN.Open strCN
Set objRS1 = objCN.OpenSchema(20)

strSQL = "INSERT INTO smstable ( [sender], [perfix], [sms], [smstime], [smsdate] ) VALUES ( '" & Sender & "','" & Prefix & "','" & Sms & "','" & Smstime & "','" & Smsdate & "')"

Set objRS1 = objCN.Execute(strSQL)


Set argsNamed = nothing

------------------------------------------------

It is as same as the previous one but i just added "C:\" for the database path LOL.

So I would be happy to present this code for any one looking to address such DB integration.

Other thing, I need your help with. What are the usual script methods to command sending SMS back??

Many thanks for all.

Regards
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 7124
Registered: 10-2002
Posted on Thursday, April 19, 2007 - 11:45 am:   

Hello Waleed,

Thank you for sharing your script.

From a command line program, to return a reply to the SMS, it can just echo its text response to the display. Of course, it is running as a service under control of NowSMS, so the application is not actually writing to a display ... but NowSMS captures this output that would normally be displayed on screen, and sends it back in a reply SMS.

The above only happens if you have "Command returns response text" checked in the 2-way command definition.

If you need more control or flexibility, then it is possible for you to issue HTTP requests from your program to send messages. There is a simple Windows script example here:

http://www.nowsms.com/support/bulletins/tb-nowsms-008.htm

-bn
Waleed Hameed
New member
Username: Waleed_k

Post Number: 16
Registered: 02-2007
Posted on Monday, April 23, 2007 - 08:43 am:   

Hi Bryce,
Many thanks; I had looked at the Jscript code you recommended.
I am still trying to make it in VBscript, but anyway I couldn’t run the Jscript from Nowsms 2-way service. I mean who should the command to execute syntax Look like???
"C:\windows\system32\cscript.exe c:\sms.js" !!!!
Look for your kind support.
Regards
Waleed Hameed
New member
Username: Waleed_k

Post Number: 17
Registered: 02-2007
Posted on Tuesday, April 24, 2007 - 12:42 pm:   

Hello,
Can I plz have your advice about this problem

I use this code to log SMS and send back to the sender.

----------------------------------------
et argsNamed = WScript.Arguments.Named

Dim strRequest
NowSMSServerAddress = "http://127.0.0.1:80"


Sender = argsNamed.Item("sender")
Prefix = argsNamed.Item("prefix")
Sms = argsNamed.Item("message")
Smstime = argsNamed.Item("time")
Smsdate = argsNamed.Item("date")

Dim strCN, objCN, objRS1, strSQL

strCN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & "c:\database\db1.mdb"
Set objCN = WScript.CreateObject("ADODB.Connection")
objCN.Open strCN
Set objRS1 = objCN.OpenSchema(20)

strSQL = "INSERT INTO smstable ( [sender], [perfix], [sms], [smstime], [smsdate] ) VALUES ( '" & Sender & "','" & Prefix & "','" & Sms & "','" & Smstime & "','" & Smsdate & "')"

Set objRS1 = objCN.Execute(strSQL)

strRequest = NowSMSServerAddress + "/?PhoneNumber=" + argsNamed.Item("sender") + "&text= Got your SMS "

WScript.Echo(HTTPGET(strRequest))


Set argsNamed = nothing



function HTTPGET(strURL)

Dim strResult
Dim Http

Set Http = CreateObject("MSXML2.XMLHTTP")

Http.Open "GET", strURL , False

Http.send

strResult = Http.ResponseText

HTTPGET = strResult

End function
-----------------------------------------------
It is not sending back !!!! I attached the log file, it may help explane.
Regards

Waleed Hameed
application/octet-stream
SMSDEBUG.LOG (28.3 k)
Waleed Hameed
New member
Username: Waleed_k

Post Number: 18
Registered: 02-2007
Posted on Thursday, April 26, 2007 - 10:12 am:   

Hello, about the above problem.
It looks like the commaned get execute and a HTTP GET sends to 127.0.0.1:xxx but when start

11:52:52:031 [7] ThreadProcessConnection: Processing connection from 127.0.0.1...

11:52:52:031 [7] ThreadProcessConnection: Processing request /?PhoneNumber=+447872840155&text=%20%20Got%20your%20SMS%20??
11:52:52:031 [7] Debug: 1 recipient entries
11:52:52:031 [7] ThreadProcessConnection: Before message loop
11:52:52:031 [7] ThreadProcessConnection: Before message loop
11:52:52:031 [7] ThreadProcessConnection: Begin message loop
11:52:52:031 [7] ThreadProcessConnection: End message loop
11:52:52:046 [7] ThreadProcessConnection: Request processing complete
11:52:52:546 [3] ThreadProcessModem: Processing 4630809C.req...
11:52:52:546 [3] ThreadProcessModem: OUT: AT+CMGS=26

11:52:52:593 [3] ThreadProcessModem: IN:
>
11:52:52:593 [3] ThreadProcessModem: OUT: 0001150C8144872748105500000E20D0F14D07E5DF753968DA9C02
11:52:56:500 [3] ThreadProcessModem: ERROR - Modem Response (2): +CMS ERROR: 500
11:52:56:500 [3] ThreadProcessModem: Error: ERROR - Modem Response (2): +CMS ERROR: 500

And keeps trying to Processing 4630809C.req..........

}over and over
Waleed Hameed
New member
Username: Waleed_k

Post Number: 19
Registered: 02-2007
Posted on Thursday, April 26, 2007 - 12:18 pm:   

Hello Bryce,
By looking at other posts u made about "+CMS ERROR: 500". Ok it means unknown error!!! But i can send sms from web to other mobiles using the modem and it receives sms.
That mean the signal is ok, the SIM is working, and modem is not been used by other software!!!
The Modem i am using is Huawei E220 USB.

So have you got any idea, where it’s going wrong!! Thanks

Regards
Waleed Hameed
New member
Username: Waleed_k

Post Number: 20
Registered: 02-2007
Posted on Friday, May 04, 2007 - 08:54 am:   

Hello Bryce,
I am still having the above problem, please let me know ur advice to over come such +cms ERROR: 500.
thanks.

Waleed Hameed
Waleed Hameed
New member
Username: Waleed_k

Post Number: 21
Registered: 02-2007
Posted on Friday, May 11, 2007 - 08:02 am:   

Hello,
The problem has been solved. I was able to send and receive SMS from the gateway by using the vbscript bellow............. it is simple but very useful for further integrations. Coz it capture the received SMS, connect to DB, and send back SMS using HTTP GET request for 172.0.0.1:xx.

httpget.vbs
-------------------------------------------

Set argsNamed = WScript.Arguments.Named

Dim strRequest
NowSMSServerAddress = "http://127.0.0.1:80"


Sender = argsNamed.Item("sender")
Prefix = argsNamed.Item("prefix")
Sms = argsNamed.Item("message")
Smstime = argsNamed.Item("time")
Smsdate = argsNamed.Item("date")

Dim strCN, objCN, objRS1, strSQL

strCN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & "c:\database\db1.mdb"
Set objCN = WScript.CreateObject("ADODB.Connection")
objCN.Open strCN
Set objRS1 = objCN.OpenSchema(20)

strSQL = "INSERT INTO smstable ( [sender], [perfix], [sms], [smstime], [smsdate] ) VALUES ( '" & Sender & "','" & Prefix & "','" & Sms & "','" & Smstime & "','" & Smsdate & "')"

Set objRS1 = objCN.Execute(strSQL)

Sender = Replace (Sender, "+" , "%2B")
strRequest = NowSMSServerAddress +"/?PhoneNumber="+ Sender +"&text=Got your SMS"

Wscript.Echo(HTTPGET(strRequest))


Set argsNamed = nothing



function HTTPGET(strURL)

Dim strResult
Dim Http

Set Http = CreateObject("MSXML2.XMLHTTP")

Http.Open "GET", strURL , False

Http.send
strResult = Http.ResponseText


HTTPGET = strResult


End function
--------------------------------------------

Thanks for the support, anyone feel free to use this script.

I am still trying to understand the +cms Error: 500. Where I can fine good documents to read about GSM modem communication with NowSMS software? To be able to understand the SMSDEBUG file lines better.

Thanks anyway, look forward to hear from you.

Regards

Waleed Hameed
MSc. Mobile Computer Systems
Staffordshire University.

Login Login / Register Logout Logout Search Last 30 Days Topics Topics