#7839
Hello everyone.
First of all, I am working on a project using Arduino Uno and Shield GPS/GPRS/GSM Module V3.0, wich one I need to be able to send data to a web page and after get the anwser back in my arduino.
Until now, I can send the data to my web page, but I don't know how to get the anwser of the web page.

Searching about this over the internet, I found that maybe I need to use some AT Commands as for example "AT+ATHTTPREAD", but the problem is that I didn't get good results.

So, if someone know how to get the data from a URL and show it at arduino, please help me !
Thanks a lot!
#7846
Hi leff.
In my case, I really need to use this Shield, because my arduino won't have Wifi signal available.
The webservice that I am using, it´s a Jersey webservice, which one always will answer in a Json format. So
if you do a request to this webservice to send data and expects an answer, you need to be able to manipulate Json data.

But my friend, the code in this url that you posted really worked, after few changes of course, because wouldn' t be that easy
HAHAHAHA

The only problem is that always the last character of the answer is shown as a weird character, but it's not a big deal because in my case it will be always quotation marks.

Anyway, thanks again

Code: Select all
int data_size;
char data[512];
char aux;
int x = 0;
int8_t answer;
char aux_str[100];

void setup()
 {
   //Init the driver pins for GSM function
    pinMode(3,OUTPUT);
    pinMode(4,OUTPUT);
    pinMode(5,OUTPUT);
   //Output GSM Timing
    digitalWrite(5,HIGH);
    delay(1500);
    digitalWrite(5,LOW);
    Serial.begin(9600);
        // Use these commands instead of the hardware switch 'UART select' in order to enable each mode
    // If you want to use both GMS and GPS. enable the required one in your code and disable the other one for each access.
    digitalWrite(3,LOW);//enable GSM TX、RX
    digitalWrite(4,HIGH);//disable GPS TX、RX
   
    delay(20000);
   
    start_GSM();
 }
 
 void loop(){
   send_GPRS();
   delay(30000);
 }
 
 void start_GSM(){
    Serial.println("AT");
    delay(2000);
    Serial.println("AT+CREG?");
    delay(2000);
// I am using a brazilian mobile operator
    Serial.println("AT+SAPBR=3,1,\"APN\",\"zap.vivo.com.br\"");
    delay(2000);
    Serial.println("AT+SAPBR=3,1,\"USER\",\"vivo\"");
    delay(2000);
    Serial.println("AT+SAPBR=3,1,\"PWD\",\"vivo\"");
    delay(2000);
    Serial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
    delay(2000);
    Serial.println("AT+SAPBR=1,1");
    delay(10000);
    Serial.println("AT+HTTPINIT");
    delay(2000);
    Serial.println("AT+HTTPPARA=\"CID\",1");
    delay(2000);
 }
 
 void send_GPRS(){
    digitalWrite(3,LOW);//Enable GSM mode
    digitalWrite(4,HIGH);//Disable GPS mode
    Serial.print("AT+HTTPPARA=\"URL\",\"your_url/");
    Serial.print("parameter 1");
    Serial.print("/");
    Serial.print("parameter 2");
    Serial.println("\"");
    delay(2000);
    Serial.println("AT+HTTPACTION=0"); //now GET action 
    delay(10000);
   
    x=0;
    do{
        sprintf(aux_str, "AT+HTTPREAD=%d,100", x);
        if (sendATcommand2(aux_str, "+HTTPREAD:", "ERROR", 3000) == 1)
        {
            data_size = 0;
            while(Serial.available()==0);
            aux = Serial.read();
            do{
                data_size *= 10;
                data_size += (aux-0x30);
                while(Serial.available()==0);
                aux = Serial.read();       
            }while(aux != 0x0D);

            if (data_size > 0)
            {
                while(Serial.available() < data_size);
                Serial.read();

                for (int y = 0; y < data_size; y++)
                {
                    data[x] = Serial.read();
                    x++;
                }
                data[x] = '\0';
            }
            else
            {
                Serial.println("Download finished");   
            }
        }
        else if (answer == 2)
        {
            Serial.println("Error from HTTP");
        }
        else
        {
            Serial.println("No more data available");
            data_size = 0;
        }
       
        sendATcommand("", "+HTTPACTION:0,200", 2000);
    }while (data_size > 0);
   
    Serial.print("Data received: ");
    Serial.println(data);

    //sendATcommand("AT+HTTPTERM", "OK", 5000);
    //delay(5000);
}
 
int8_t sendATcommand(char* ATcommand, char* expected_answer1, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialize the string

    delay(100);

    while( Serial.available() > 0) Serial.read();    // Clean the input buffer

    Serial.println(ATcommand);    // Send the AT command


        x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        if(Serial.available() != 0){   
            response[x] = Serial.read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer1) != NULL)   
            {
                answer = 1;
            }
        }
        // Waits for the asnwer with time out
    }
    while((answer == 0) && ((millis() - previous) < timeout));   

    return answer;
}



int8_t sendATcommand2(char* ATcommand, char* expected_answer1,
char* expected_answer2, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialize the string

    delay(100);

    while( Serial.available() > 0) Serial.read();    // Clean the input buffer

    Serial.println(ATcommand);    // Send the AT command


        x = 0;
    previous = millis();

    // this loop waits for the answer
    do{       
        if(Serial.available() != 0){   
            response[x] = Serial.read();
            x++;
            // check if the desired answer 1 is in the response of the module
            if (strstr(response, expected_answer1) != NULL)   
            {
                answer = 1;
            }
            // check if the desired answer 2 is in the response of the module
            if (strstr(response, expected_answer2) != NULL)   
            {
                answer = 2;
            }
        }
        // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < timeout));   

    return answer;
}
#8573
[quote="leandro08rezende"]Hello everyone.
First of all, I am working on a project using Arduino Uno and Shield GPS/GPRS/GSM Module V3.0, wich one I need to be able to send data to a web page and after get the anwser back in my arduino.
Until now, I can send the data to my web page, but I don't know how to get the anwser of the web page.

[b]Could you tell me how you do that?[/b]
#9602
[quote="leandro08rezende"]Hi leff.
In my case, I really need to use this Shield, because my arduino won't have Wifi signal available.
The webservice that I am using, it´s a Jersey webservice, which one always will answer in a Json format. So
if you do a request to this webservice to send data and expects an answer, you need to be able to manipulate Json data.

But my friend, the code in this url that you posted really worked, after few changes of course, because wouldn' t be that easy
HAHAHAHA

The only problem is that always the last character of the answer is shown as a weird character, but it's not a big deal because in my case it will be always quotation marks.


hey, Is this a code that worked for you?