Go Down

Topic: SIM900 works with AT commands only some times (Read 6106 times) previous topic - next topic

Marciokoko

Oct 05, 2016, 08:27 pm Last Edit: Oct 07, 2016, 03:36 am by Marciokoko
What I want to achieve:
> Send an sms from SIM900 module connected to Nano


Libraries used
> MarcoMartines Library (https://github.com/MarcoMartines/GSM-GPRS-GPS-Shield)

What I've tried:
1. Send sms from Mega & library >>> Works w/ SIM900 Rx/Tx to MEGA's 18/19. SIM900Mega_Library.ino
2. Sending sms w/o library w/ Sketch >>> Fails SIM900NanoW_OLibrary.ino --- wow, it worked!
3. Interfacing with the SIM900 directly >>> Fails SIM900NanoSSConnect.ino
4. Trying to make library work >>> Ive gotten the farthest with this option SIM900NanoWLibrary.ino

Results of each:
1/4-sms sent...im uploading the results
2/4-no sms sent...im uploading the results
3/4-CREG comes back 0,0 or 0,2 or 0,4 but never 0,1 or 0,5 which means its registered on the network
4/4-no sms sent...im uploading the results

I know its not the library for that module, since the library is for the shield.  

As it turns out, the library uses a #ifdef MEGA to use Serial1 (18,19) to communicate with between the mega and the sim900.  I messed around with the library and replaced all the Serial1 references (in HWSerial.cpp) with Serial, which sort of makes it work with the nano when I plug in the Rx/Tx from the module to the nano's Rx/Tx pins.  I can see the data coming in from the module and it prints out everything indicating the sms was sent, but I don't get the sms on my phone.

I know the sim works because when I use it on the mega the sms is sent successfully and then I move the sim to another phone I can also send sms messages from it.

-----
Yesterday all of a sudden it worked with scenario #2, the AT commands directly without the library.  I was able to send about 3 messages.  Today its not working anymore.  So the code should be good.  I dont know what to do in order to figure out why it works sometimes but not others.




Marciokoko

#1
Oct 08, 2016, 07:08 pm Last Edit: Oct 08, 2016, 07:10 pm by Marciokoko
I found this function in the library:

Code: [Select]

char SIMCOM900::forceON(){
 char ret_val=0;
 char *p_char;
 char *p_char1;
 
 SimpleWriteln(F("AT+CREG?"));
 WaitResp(5000, 100, "OK");
 if(IsStringReceived("OK")){
 ret_val=1;
 }
 //BCL
 p_char = strchr((char *)(gsm.comm_buf),',');
 p_char1 = p_char+1;  //we are on the first char of BCS
 *(p_char1+2)=0;
 p_char = strchr((char *)(p_char1), ',');
 if (p_char != NULL) {
          *p_char = 0;
    }

 if((*p_char1)=='4'){
 digitalWrite(GSM_ON, HIGH);
 delay(1200);
 digitalWrite(GSM_ON, LOW);
 delay(10000);
 ret_val=2;
 }

 return ret_val;
}


If i understand it correctly, if CREG returns 0,4, it forces the module on with a pulse, which ive read about somewhere.

How could I perform that pulse manually from my arduino sketch?  This is how the pin is defined in the GSM.h file:

Code: [Select]
// pins definition
#define GSM_ON              8 // connect GSM Module turn ON to pin 77


But since this library was made for a shield, it must mean pin 8 is the pin on the shield.  But since I don't have that shield, pin 8 won't have access to pin77 of sim900. Is there a way to access that pin from the module?

Cause basically Ive decided I have 3 possible routes:

A.  Try the Mega/Library combo to see if that jumpstarted anything on the sim900 that might get me through using the sketch without the library (straight at commands) to see if it worked because I think that may have happened the first time.

B. Try to somehow force on the sim900 by pulsing it.  But while researching this issue I discovered that sim900 doesnt have a pin 77.  I looked at the pinout for my module and it only makes it up to pin 68!

C. Researching if there was something i needed to do to register the sim on the network, since CREG always came back either 0, 2 or 4, but never 1 or 5.  I thought this might be viable because whenever I put the sim in the phone, i get a network popup asking me to solicit and then accept the network configuration for the sim.  So I figured that might be impeding the sim's reg on the network.

RESULTS
A - Mega/Library sketch = Sends sms as always, but when I tried the Nano/ATCmds sketch it still didnt work, so somehow kickstarting the sim900 to work by running the Mega/Library doesnt work.  At least not every time.

I did notice that the Mega/Library sketch log returns CPMS like this:

Code: [Select]

ATT:
+CPMS:RIC:
[color=red][b]+CPMS: 3,190,3,190,3,190
OK[/b]
[/color]
ATT:
OKRIC:
OK
ATT:
SHUT OKRIC:
SHUT OK
status=READY
DEBUG:SMS TEST
ATT:
>RIC:
OK
>
DEBUG:>
ATT:
+CMGSRIC:
+CMGS: 42
OK
SMS sent OK


It returns OK after CPMS, not ERROR!

On the other hand, running the nano/modified library Serial1 sketch returns CPMS Error every time.  I had reported this error a way back (http://forum.arduino.cc/index.php?topic=341972.msg2952580#msg2952580) but never really fixed it.

scrumfled

Im finding this a little confusing, CPMS is a configuration string for where you wish to store the messages by default. Usually you set this once then save the module config.

You've then got a bunch of GPRS related commands in there, which i'd be inclined to strip out while you're testing.

The CREG response points to your problem, and the comment about a config message might be important. Networks will often push an auto config to new sim/phone combinations, typically this is the APN etc for your gprs & MMS settings.. Its also possible it contains the SMSC address, but thats quite unusual. Which network are you on?

Personally I'd be using an FTDI board to plug directly into the module and checking a few command responses out;

CFUN
COPS
CPIN (should be ok, but worth checking anyway).
CREG (should be set to auto mode)
CSCA (check validity of the number returned)

Plugging in directly gives a better feel for whats happening...

You can also run a full network scan, i think that cnetscan, just to see if you even have coverage.




Marciokoko

#3
Oct 10, 2016, 01:27 am Last Edit: Oct 10, 2016, 01:28 am by Marciokoko
Thanks.

The GPRS related messages might be due to the fact that Im using that library which runs some other diagnostics as well.

Here are the results:

+CFUN: 1
+COPS: 0
+CPIN: READY
+CREG: 0,4
AT+CSCA? ERROR

The weird thing is that whatever that library does when I plug my SIM900 to my MEGA and use the library, it works because the SMS is sent, which means the SIM must get on the network while connected to the MEGA.

scrumfled

#4
Oct 10, 2016, 01:37 am Last Edit: Oct 10, 2016, 01:46 am by scrumfled
Like i said, if you can, connect DIRECT to the module. PC -FTDI- Module. No arduino, no library....

then try;

AT+CREG=2

If you're seeing an error on csca?, you may need to manually set that (check the at command manual for the syntax, the SMSC address can be specific to each service provider).

Your bigger issue is you're just not registering on the network, putting creg=2 may fix that. Do you know the message content you're getting from your operator? (can be either an SMS, in which case CMGL may reveal where it is), or a USSD message, in which case (cusd=1) will help. I suspect thats a red herring, but its worth checking.

I'd definitely do the cnetscan though, to make sure you have coverage before you go any further.

Once you know for sure that the module/network are doing what you expect, it becomes easier to fault find the arduino :)

ps. the comment about it working with the mega is very interesting. that basically confirms the ME/SIM and config are all ok. When you use it with the nano, how are you powering the module.


Marciokoko

OK.  I'll try to reply what I understand :

1.  I do have an ftdi adapter so I'll try that.  You want to repeat all those codes, specifically the csca one, correct? 

2. You want me to manually do creg=2?  I remember playing around with creg last night and I tried setting it to 0, to 1 and to 2.  In the end I'm pretty sure I got
+creg: 2
+creg: 1
+creg: 0

But I'll try directly with the adapter.

3. What's this service provider message content you mention?  Does it have anything to do with a pop up I get on the phone when I put the sim in the phone?  It asks if I want to request or accept the network configuration settings and I always click Accept of course.  I've always wondered if it's a requisite and how that affects the sim when it's in the module and I can't click on Accept like on my phone. 

4. I'm not sure what you mean by cnetscan.  Can you explain how to do that?  You mention I should do it to check if I have coverage...if it's cell phone coverage I should have it, I'm close to downtown and I always have coverage when the sim is in the phone.

5. I upload the sketches via USB and usually test it that way.  With the Mega, I power it and it works fine with the laptop usb connection.  The odd time it worked in the Nano I'm pretty sure it was plugged into the laptop as well.  But I do all tests from then on both with the laptop and a 5v battery pack (23,000mah 5v rechargeable).

Marciokoko

Here are the results:
at+cnetscan=1
OK

AT+CFUN?
1

at+COPS?
0

at+cpin?
READY

at+creg?
1,2

at+csca?
error

at+cscs?
ira

Yesterday I did something to it that makes it print out CREG queries constantly, I think it was setting CREG=something.  So I saved the results of my coolterm session for the commands above.  Normally the led blinks every second or less (i believe ive read its about 800ms).  After a while of entering the commands, I let it sit there and all of a sudden I got a printout amongst all the CREGs that read Call Ready, and I noticed this because I saw the terminal wasnt spitting out CREG lines anymore, it just sat there.  And I noticed the led blinked every 3 seconds.

After a few seconds it was back to its 800ms business.  Ive attached the terminal logs for the session:

HEe5
+CFUN: 1
+CPIN: READY
+CREG: 0
+CREG: 2
+CREG: 1
RDY
at+cnetscan=1
OK
+CREG: 0
+CREG: 2
+CREG: 1
AT+CFUN?
+CFUN: 1
+CPIN: READY
at+COPS?
+COPS: 0
OK
+CREG: 0
at+cpin?
+CPIN: READY
OK
at+creg?
+CREG: 1,2
OK
+CREG: 1
RDY
+CFUN: 1
+CPIN: READY
at+csca?
ERROR
+CREG: 0
+CREG: 2
+CREG: 1
RDY
+CFUN: 1
+CPIN: READY
+CREG: 0
+CREG: 2
+CREG: 1
Call Ready
AT+CSCS?
+CSCS: "IRA"
OK
at+csca?
ERROR
at+creg?
+CREG: 1,4

scrumfled

#7
Oct 11, 2016, 09:44 am Last Edit: Oct 11, 2016, 10:55 am by scrumfled
Great news, it seems you're now registering on the network (which kind of makes the whole cnetscan redundant, but fyi, its output is along the lines of "Operator:"O2",MCC:234,MNC:10,Rxlev:39,Cellid:7149,Arfcn:101", with a line for each radio carrier).

Before we go on, let me just observe that these modules seems to have many versions and its good to read the AT command manual for *your* version. You can check your version with "ATI". Armed with that, I'd do the following;

1. Check connection quality/signal strength

Usually this is the command "at+csq". You;ll get a response along the lines of "+CSQ: 21,0" (check the manual for the parameters, essentially the first is version of signal strength/rx level, the second is 0, unless you're in an active session).

2. Check SMSC settings

You're going to have to check the manual here for your version of module. On mine the command is "at+csca?" and it responds "+CSCA: "+447802002606",145". If you dont have an SMSC setup, you wont be able to send SMS until you put that info in.

3. Investigate the network message you get when the module first registers to the network.

I *think* the way I did this was to turn on USSD reporting, "AT+CUSD=1" and then save the settings (so they persist through reboot) with "AT&W". When you reboot, *if* the message you're referring to is USSD (as i suspect), you'll see it on the terminal session.


PS. If it helps you feel any better, the sim808 GPS manual is even worse and the documentation on NMEA is pretty much non existent ;)

Marciokoko

#8
Oct 11, 2016, 07:16 pm Last Edit: Oct 13, 2016, 02:50 am by Marciokoko
Ok,

0) Version.  Well ATI returns SIM900 R11.  Im looking at the document provided by sainsmart for my module and i dont really see where it says that documentation is for R11.  I see it reads v1.03 and in the first few pages it has a chart that looks like this:



1) Why do you say it seems like Im registering onto the network?  Which result tells you that, +CREG:1?  Because what worries me is that it prints out 0, then 1, then 2 continuously.  I thought only 1 and 5 meant the sim was registered.

2)COMMANDS EXECUTED

AT+CSQ=?  
+CSQ: (0-31,99),(0-7,99)
AT+CSQ?
ERROR
AT+CSQ
+CSQ: 0,0
===============

AT+CPAS=?
+CPAS: (0,2,3,4)

AT+CPAS?
ERROR

AT+CPAS
+CPAS:2
===============
AT+CSCA=?
OK
AT+CSCA?
ERROR
AT+CSCA
ERROR

3)
AT+CUSD=?
+CUSD: (0,1,2)

AT+CUSD?
+CUSD=0

AT+CUSD=1
OK

AT&W
OK

Even after AT+CUSD=1 and AT&W, I unplugged the sim900 and replugged it in and I still get CUSD:0.

A) Why isnt my module responding to AT commands are listed in the manual?

B) I just noticed that my module, after sitting for a while started blinking led every 3 seconds and again it logged Call ready in the Serial Terminal program and its just sitting there waiting.


scrumfled

Yes, CREG=1 indicates a successful registration.  It looks like you register, then the network is booting you off. That can be caused by a number of things...and isnt entirely easy to diagnose. Q1. Which network are you connecting to? Q2. How quickly does it then move to CREG=2 (searching for network)?

I cant answer your questions about why your module doesnt respond to commands in the manual. It may help if you could provide links to your (Q3) module and the (Q4) manual version you are using. The table you linked is about document revisions, not module revisions. Fundamentally, that question needs to go to whoever you bought the module from.

(Q5) My understanding is that you have put the exact same sim into a phone and successfully registered/sent an SMS?

(Q6), what result do you get from the command AT+COPS=?










Marciokoko

+Cops returns 0.
It takes about 1 second on each creg0, then another second in creg2 and again on creg 1 and starts over again.  I did notice a second time that after about 5 minutes it reaches a point where the LED blinks every 3 seconds and I get a call ready log and it sits there.

The links are:

http://www.sainsmart.com/sim900-gprs-gsm-board-quad-band-module-kit-for-arduino-high-quality-new.html

I bought it on Amazon.  Their support rep gave me these links:

https://s3-ap-northeast-1.amazonaws.com/sain-amzn/20/20-012-106/EN.zip

https://s3-ap-northeast-1.amazonaws.com/sain-amzn/20/20-012-106/KUN_CON_TC35.zip

https://s3-ap-northeast-1.amazonaws.com/sain-amzn/20/20-012-106/SIM900_A_+Module+Series+Debug+_unfinished_.pdf

https://s3-ap-northeast-1.amazonaws.com/sain-amzn/20/20-012-106/SIM900_MINI_English_V1.pdf

scrumfled

#11
Oct 11, 2016, 11:22 pm Last Edit: Oct 11, 2016, 11:50 pm by scrumfled
ok, third time lucky ;)... which network are you trying to connect to?

For the cops test, can you take a screenshot showing the command and response...

So is it consistently achieving a stable registration after 5 mins?

Next time you have a steady reg, hit it with the following and screenshot the results.

AT+CSQ
AT+CIMI
AT+COPS=?
AT+CPSN?





Marciokoko

#12
Oct 12, 2016, 01:16 am Last Edit: Oct 12, 2016, 01:48 am by Marciokoko
Plugged it in at 501p, immediately it starts CREG0,2,1...0,2,1...

Before I forget, Im in Honduras, the carrier is Tigo (millicom)

511pm i got call ready and 3 second blink...So about 10 minutes in.  Ok here are the results:

Call Ready
AT+CSQ
+CREG: 1
AT+CIMI

ERROR
AT+CSQ?

ERROR
AT+CIMI?

ERROR
AT+COPS=?

+COPS: (2,"TIGO","","70802"),(3,"","","708001"),(3,"","","70803"),,(0,1,4),(0,1,2)

OK
AT+CPSN?

ERROR
AT+CPSN?.

ERROR
AT+CSQ

+CSQ: 19,0

OK
AT+CIMI

708020033374370

OK
AT+CPSN

ERROR
AT+CPSN?

ERROR
AT+CPSN=?

ERROR

The thing is, what happens during those 10 minutes?  Because I cant have the sketch wait 10 minutes.  Maybe that network message popup gives up?  Btw, this time I ran AT+CUSD=1, and now when I ask it AT+CUSD? I get 1.  I also did AT&W :-)

Oh hey!  I also got the sms to work:

Code: [Select]
+CUSD: 1

OK
AT+CMGF=1

OK
AT+CMGS="+504mynumber"

> tuti

> 26

> 0x1A

> z

>
+CMGS: 45

OK


In the end I had to hit ctrl-z on my keyboard, dont know why 0x1A didnt work, or 26.  Probably because it sends commands as strings or something.

So how can I make the sim register at will, or at least in less time, as it apparently does with the Mega/Library sketch?

scrumfled

To be honest, because you're not connecting directly to the module (as requested), its hard to see where the delays are coming from. I also get the feeling the library is filtering the parameters in the modules response (and possibly some of the commands as well).

If this were my module, I'd be connecting *directly* to it using an FTDI board and NOT using an arduino at all, for the first step of testing. Once you know for sure how the module is behaving, you've at least got a baseline for your fault finding with the arduino and whichever library you are using.

I checked your carrier out for the obvious items (incompatibile RF bearer etc), that seems ok.

Ten minutes is a wierd time out. I cant think of any network timers of that duration, maybe theres a service platform involved.... my gut feeling is you *need* to get the text from that popup message, which i suspect isnt being transited through the library (again, a direct connection may help here).





Marciokoko

I am directly connected to the module via pl2032 adapter. 

Go Up