4

I would like to send following AT commands automatically by creating a .bat file using PuTTy.

AT

ok

AT+CPIN = 1234

ok

I can do it manually so far. But I would like to do it automatically by executing the above commands by just clicking on a batch file. Can someone please help me with the commands to prepare my .bat file? Thanks in advance!

user3812823
  • 41
  • 1
  • 1
  • 3
  • hey, downvoter, this is a goodish question, while not the best, there is no reason on the face of this earth for you to downvote it without commenting. (or to down vote it period..... IMHO) – cure Jul 07 '14 at 15:29

1 Answers1

2

try something like this:

commands.bat:

@echo off
echo AT
timeout /t 1 /nobreak >nul 2>&1
echo AT+CPIN = 1234
timeout /t 1 /nobreak >nul 2>&1
pause >nul 2>&1

send.bat:

commands.bat | putty -load test

where send.bat and commands.bat are in the same directory, and you execute send.bat

cure
  • 2,588
  • 1
  • 17
  • 25
  • Thanks for your quick answer. AT commands are used to connect to modem via a COM port to make a call or send sms. So far in putty, I have saved a session called 'test' with COM5 and speed 9600 and created a batch file with following command in send.bat: plink -load test pause – user3812823 Jul 07 '14 at 15:06
  • I have saved a session called 'test' with COM5 and speed 9600 and created a batch file with following command in send.bat: plink -load test pause After each command, I need to press enter to get response 'ok' from the modem. Example: AT AT+CPIN = 1234 How can I accompilish this using .bat file? – user3812823 Jul 07 '14 at 15:14
  • see, the newline is automatically sent if its in commands.txt, just put EXACTLY what you would type into commands.txt, and the pipe will (hopefully) cause plink to think you are typing the contents of commands.txt. – cure Jul 07 '14 at 15:17
  • ohk..after wrtiting the above commands in commands.txt, now my send.bat file will look like this: echo off plink -load test type commands.txt pause am I right nephi12? – user3812823 Jul 07 '14 at 15:24
  • no, it will look like the send.bat im updating in my answer right now. – cure Jul 07 '14 at 15:26
  • ok nephi, got it. And do we also have some command to wait for getting the OK response from modem? Or is it done automatically after plink 'READS' enter in the commands.txt? – user3812823 Jul 07 '14 at 15:34
  • well, it *should* be done automatically... but... here is the thing. plink is gonna take the input from commands.txt as fast as it can, so it *might* send the second command too soon... it really depends on whether plink will take input while the modem is sending back ok... you *should* be fine though, and if you arent, we can try another solution that im cooking up, but i dont know if it will work or not. try what we have now if you can, and get back to me with the results, btw, i have to go in .... about 2ish hours. – cure Jul 07 '14 at 15:38
  • ok, thanks for your help. Unfortunately, I cannot try it _now_ as I do not have the modem at my place. However, I _may_ try it tomorrow. In any case, I will get back to you with the results as soon as I try it, @nephi. :-) – user3812823 Jul 07 '14 at 15:46
  • alright, ill be on tomorrow between approx 2 hrs ago, and 4 hours after that (timezones are weird) so aim for that time slot – cure Jul 07 '14 at 15:48
  • Hi nephi, sorry for the late reply. Was busy working on other projects. – user3812823 Sep 05 '14 at 15:12
  • Meanwhile, I have tried your solution. I have 4 commands, which I have typed in a .txt file. And 'READ' then using the batch file. First command is entered fine and I also get a reply OK. But then, the next command is skipped and the third command is 'READ' onto the cmd prompt. I think it is reading too fast. Ideally, we should wait (sleep for about 0.5s)before reading the next command from the txt file. What do u suggest? – user3812823 Sep 06 '14 at 08:30
  • use `timeout /t 1 /nobreak >nul 2>&1` to pause for one second. – cure Sep 08 '14 at 20:05
  • this line should be inserted in the .txt file after each of my command..Am I right? – user3812823 Sep 09 '14 at 11:47
  • I think, we should pause for 1s after 'READING' enter and before 'READING' the next command from the txt file. – user3812823 Sep 09 '14 at 14:06
  • I have inserted the pause line (timeout /t 2 /nobreak >nul 2>&1) for 2seconds in the .txt file as u suggested. It reads fine till the pause line. And then it simply stops there and does not proceed further i.e. the remaining lines are not read from the txt file. – user3812823 Sep 09 '14 at 16:44