SIM900 AT Commands response parsing

前端 未结 3 1620
梦如初夏
梦如初夏 2020-12-18 16:16

i am using sim900 gps/gprs module shield connected to an Arduino Uno, how will i be able to parse the response of my AT commands? Or how will i be able to remove the 1st lin

3条回答
  •  清歌不尽
    2020-12-18 16:48

    If you are using arduino I would recommend to use a good library! You don't need to deal about these stuff. Try http://www.gsmlib.org/ or you can find any other you like.

    I will include one example here.

    #include "SIM900.h"
    #include 
    //If not used, is better to exclude the HTTP library,
    //for RAM saving.
    //If your sketch reboots itself proprably you have finished,
    //your memory available.
    //#include "inetGSM.h"
    
    //If you want to use the Arduino functions to manage SMS, uncomment the lines below.
    #include "sms.h"
    SMSGSM sms;
    
    //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 send and receive SMS.
    
    int numdata;
    boolean started=false;
    char smsbuffer[160];
    char n[20];
    
    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(2400)){
        Serial.println("\nstatus=READY");
        started=true;  
      }
      else Serial.println("\nstatus=IDLE");
    
      if(started){
        //Enable this two lines if you want to send an SMS.
        //if (sms.SendSMS("3471234567", "Arduino SMS"))
          //Serial.println("\nSMS sent OK");
      }
    
    };
    
    void loop() 
    {
      if(started){
        //Read if there are messages on SIM card and print them.
        if(gsm.readSMS(smsbuffer, 160, n, 20))
        {
          Serial.println(n);
          Serial.println(smsbuffer);
        }
        delay(1000);
      }
    };
    

提交回复
热议问题