GSMShield ArduinoUno
Arduino

Receive Caller ID and dial USSD via AT commands

Sample code :

#include "SIM900.h"
#include 
//#include "inetGSM.h"
//#include "sms.h"
//#include "call.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to communicate with SIM900 through AT commands.

//InetGSM inet;
//CallGSM call;
//SMSGSM sms;

int numdata;
char inSerial[40];
int i=0;
String substring;

void setup()
{
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(9600))
          Serial.println("\nstatus=READY");
     else Serial.println("\nstatus=IDLE");
};

void loop()
{
     //Read for new byte on NewSoftSerial.
     serialswread();
};


void serialswread()
{
     //gsm.SimpleRead();
     //gsm.SimpleWriteln("ATD + +94785056197;");
     //delay(10000);
     //gsm.SimpleWriteln("AT+CUSD=1,\"*344#\"");   //sending AT+CUSD=1,"*344#"

          char msg[100];
          gsm.read(msg, 100);
          //Serial.println(msg);

                    //Substring the incoming caller id from AT string
                    if(strstr(msg, "+CLIP:")) {
                      String input = "";
                      delay(100);
                      //input += msg;
                      input = msg;
                      String input_trimmed = input;
                      substring = input_trimmed.substring(18, 28); // get the callers number.
                      Serial.print("Your Number is: ");
                      Serial.println(substring);
                      delay(5000);
                      }
                      
          String ussd4 =  "*10*1#\"\"";
          String ussd1 = "\"AT+CUSD=1,\"*121*";
          String ussd = ussd1+substring+ussd4;
          
          //String ussd3 = ussd2 + ussd4;
          
          Serial.println(ussd);
          //gsm.SimpleWriteln("AT+CUSD=1,\"*121*0786007019*10*1#\"");   //sending AT+CUSD=1,"*121#"
         // gsm.SimpleWrite(ussd);  
          delay(5000);
          char resp[100];
          gsm.read(resp, 100); //this command will send the response to the serial port and, at the same time, copy to "resp" string
}

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *