Author Topic: 'Call for Balance' function - A pointer or two required please  (Read 277 times)

Offline ghosty

  • Jr. Member
  • **
  • Posts: 40
'Call for Balance' function - A pointer or two required please
« on: September 18, 2017, 07:18:39 AM »
Hello,

When my Geo awakens from 'SLEEP' I thought a 'call balance' enquiry would be handy information to know (PAYG sim).

The code is pretty basic and works IF it is run in its own sketch. When I try to incorporate the code into Geo sketch I do not receive the response* on the serial monitor.
*I can see the response arrive if I probe the GSM RX/TX lines.

I have delved into many things blindly hoping to find the issues, but I have to concede I am not having the greatest of success.

My RX capture:
Code: [Select]
RDY

+CFUN: 1

+CPIN: READY

+PACSP: 1

Call Ready
AT+CMEE=1

OK
AT+IPR=9600

OK
AT+CMGF=1

OK
AT+CNMI=0,0,0,0,0

OK
AT
AT
AT+CSCLK=2

OK
AT+CMGF=1

OK
AT+CMGS="150"


> balance


+CMGS: 177

OK
AT
AT
AT+CSCLK=0

OK
AT+CSQ

+CSQ: 7,0

OK
AT+CPMS?

+CPMS: "SM",1,20,"SM",1,20,"SM",1,20

OK
AT+CMGR=1

+CMGR: "REC UNREAD","150","","17/09/13,12:00:34+04"
Your current balance as of today 12:00 is L0.00. Your last top up was L5.00 on 29/06/2017 at 16:26.

OK
AT+CMGD=1
AT
AT
AT+CSCLK=2

OK
AT
AT
AT+CSCLK=0

OK
AT+CSQ

+CSQ: 7,0

OK
AT+CPMS?

+CPMS: "SM",1,20,"SM",1,20,"SM",1,20

OK
AT+CMGR=1

+CMGR: "REC UNREAD","150","","17/09/13,12:00:34+04"
 for 24 hours or L5 for 5 days. Reply ONE or FIVE by midnight 18th of September.

OK
AT+CMGD=1
AT
AT
AT+CSCLK=2

OK

My Serial Monitor:

Code: [Select]
3F
0
true
AT+CMGF=1

OK
AT+CMGS="150"

> balance

+CMGS: 236

OK

AT+CMGD=1
AT
AT
AT+CSCLK=2

OK

AT+CMGD=1
AT
AT
AT+CSCLK=2

OK


The code I am testing with:

Code: [Select]
//Compose SMS request
void sendMessage1()
{
  a = 2;
  oldTime = millis();
  GSM.println("AT+CMGF=1");
}

void sendMessage2()
{
  a = 3;
  oldTime = millis();
  GSM.println("AT+CMGS=\"150\"\r");
}

void sendMessage3()
{
  a=4;
  oldTime = millis();
  GSM.print("balance");
}

void sendMessage4(){
  oldTime = millis();
  GSM.println((char)26);
  a=0; 
}

//Send SMS request if flag set
void dialNumber(){
  if(smsStart){
    sendMessage1();
    smsStart = false;
  }
  if ((millis() - oldTime >=pause)&& (a == 2)){
    sendMessage2();
  }
  else if ((millis() - oldTime >=pause)&& (a == 3)){
    sendMessage3();
  }
  else if ((millis() - oldTime >=pause/10)&& (a == 4)){
    sendMessage4();
  }
}

// here to process incoming serial data after a terminator received
void process_data ( const char * data)
{
 // strcpy (inData,data);
  Serial.println(data);
}  // end of process_data

void processIncomingByte (const char inByte)// inByte == GSM.read()
{
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;
  switch (inByte)
  {
  case '\n':   // end of text
    input_line [input_pos] = 0;  // terminating null byte
    // terminator reached! process input_line here ...
    process_data (input_line);
    // reset buffer for next time
    input_pos = 0; 
    break;
  case '\r':  // discard carriage return
    break;
  default:
    // keep adding if not full ... allow for terminating null byte
    if (input_pos < (MAX_INPUT - 1))
      input_line [input_pos++] = inByte;
    break;
  }  // end of switch
} // end of processIncomingByte

In my Loop() i have:

Code: [Select]
dialNumber();
  while(GSM.available()>0){
    processIncomingByte (GSM.read());
  }

Could anyone offer any pointers if they see any glaring mistakes, but more importantly, why the lack of response to the Serial Monitor?

(I should really ask; Any hints at using the SIMCOM class to achieve the same aim, but more efficiently?)

Thank you

Offline ghosty

  • Jr. Member
  • **
  • Posts: 40
Re: 'Call for Balance' function - A pointer or two required please
« Reply #1 on: October 27, 2017, 07:38:00 AM »
Apologises for the poorly worded question above (admin can stop banging his head against the keyboard now) :D That was due simply to my own, continuing, lack of understanding of some of the the basics!

Trying to bridge the knowledge gap I experimented  with stream.h and other FIFO with varying success and failures. Returning to plan I was discovering how to utilise the sim900.<> and smsData.<> . I had a 'listen' function in the loop but felt there must be a better way to capture the sms arrival. This remains a block towards my understanding at the moment.

I now have a more detrimental issue with the SIM900 inasmuch as I can talk to it through Putty; Set clock time, CSQ, return version and reset  etc. but all to no avail.
The sim, although registered to the network, no longer sends or receives to the wider world. Any manner of resets I have tried have no effect: I think geo#2 is broken :(

Geo #1 is waiting to take up the challenge - hope I don't break this, my last one!