Go Down

Topic: SIM800 OPEN GPRS ON SETUP (Read 867 times) previous topic - next topic

n3mub

I'm following a guide https://bigdanzblog.wordpress.com/2015/03/18/arduino-gps-and-sms-where-are-you-arny-the-arduino/ you find the code in that site

So I'm trying to add a void that will open GPRS

Code: [Select]

void upGprs(){
  sendAtCmd("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"","OK",500);
  delay(500);
  sendAtCmd("AT+SAPBR=3,1,\"APN\",\"GPRS\"","OK",500);
  delay(500);
  sendAtCmd("AT+SAPBR=1,1","OK",500);
  delay(500);
  //to test if working, simple get http
  sendAtCmd("AT+HTTPINIT","OK","500);
  delay(500);
  sendAtCmd("AT+HTTPARA=\"URL\",\"mysite.com/fn=test\"","OK",500);
  delay(500);
  sendAtCmd("AT+HTTPACTION=0");
}


here is the sendAtCmd(if you dont want to dl sa code in the link given)

Code: [Select]

int8_t sendAtCmd(
    char*               atCmd,
    char*               matchStr,
    unsigned int        timeout
    ){

    char                c;
    uint8_t             x               = 0;
    uint8_t             answer          = 0;
    unsigned long       previous;

delay(100);

while (ssGprs.available() > 0)                          // flush buffer
    ssGprs.read();

ssGprs.println(atCmd);                              // Send the AT command

previous = millis();

// this loop waits for the answer
do {
    if (x == sizeof(s)-1) {
        Serial.println(F("**Serial buffer overflow**"));
        while (true) {}
        }

    // if there is data in the input buffer, read it and check for the asnwer
    if(ssGprs.available() != 0) {
        c = ssGprs.read();
        if (c == '\r' || c == '\n')                         // if a full line is read w/o finding text, clear buffer
            x = 0;
        s[x]   = c;
        s[x+1] = '\0';
//      Serial.print(s[x]);                                 // uncomment if you need to see modem responses

        // check if the desired answer is in the response of the module
        if (strstr(s, matchStr) != NULL) {
            answer = 1;
            }
        x    = x + 1;
        }
    // Waits for the answer with time out
    } while ((answer == 0) && ((millis() - previous) < timeout));

return answer;

}
Newbie

Go Up