Go Down

Topic: TCP conecction with A7 GSM/GPRS/GPS (Read 2805 times) previous topic - next topic

JuanJoseJarChigui

Hello there, im a student trying to get a project done over here, ive tried a lot of things on this one, but its been imposible to solve it. im working to A7 Aithinker company, and had been able to send/recibe sms and calls, but then im triying to send a GET request to a web page, mine by the way, and it just doesnt work.

The connection is done:

AT+CIPSTART="TCP","192.254.182.188",80

CONNECT OK

OK

   
but then when i try to get the document i need this happens:

AT+CIPSEND=

>

GET /css/about-us.css HTTP/1.1

Host: 192.254.182.188:80
Connection: keep-alive

OK

+CIPRCV:431,HTTP/1.1 302 Found
Content-Type: text/html; charset=UTF-8
Content-Length: 211
Location: HTTP://190.102.192.66:8090/?dest_url=http:///css/about-us.css&msisdn=573016322960
Cache-Control: no-cache
Connection: Close

<html><head><title>302 Found</title></head><body><h1>302 Found</h1><p>The document has moved <a href="HTTP://190.102.192.66:8090/?dest_url=http:///css/about-us.css&msisdn=573016322960">here</a></p></body></html>

it hapens the same with every webpage i try, and by the way ive tried to set a server on my computer, unloked the port, and when i try to connec to it from my A7 it connects!!!!! and the port that is listening says: > New Client: 177.252.245.166
but then i try to send info, and it just colapse COMMAND NO RESPONSE

I really need help over here, im a young developer still is one of the big homies willing to help this pour soul?

JohnMattias

What is wrong with this code for A7 Elecrow shield ?




/*
 * Created by Island
 * Modified by keen
 * Date: 17/03/2017
 */
#define S1debug true
#define S_debug true

void setup()
{
  Serial1.begin(115200);   // the GPRS baud rate   
  Serial.begin(115200);    // the GPRS baud rate
 
}
 
void loop()
{
/*
 * After start up the program, you can using terminal to connect the serial of gprs shield,
 * If you input 't' in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
 * If input 'd' in the terminal, it will execute DialVoiceCall(), etc.
 */
  delay(500);
  if (Serial.available()){
    switch(Serial.read()){
     case 't':
       SendTextMessage();
       break;
     case 'd':
       DialVoiceCall();
       break;
     case 'h':
       SubmitHttpRequest();
       break;
     case 'q':
       GetSignalQuality();
       break;
   }
  }
   RecData();
}
 
/*
 * SendTextMessage()
 * This function is to send a sms message
 */
void SendTextMessage()
{
  SendData("",2000,S1debug);
  SendData("AT+CMGF=1",2000,S1debug);//Because we want to send the SMS in text mode
  delay(100);
  SendData("AT+CMGS=+46706015317",2000,S1debug);//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  SendData("GSM test message!",2000,S1debug);//the content of the message
  delay(100);
  Serial1.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
}
 
/*
 * DialVoiceCall
 * This function is to dial a voice call
 */
void DialVoiceCall()
{
   SendData("AT+SNFS=0",2000,S1debug);
   delay(100);
   SendData("ATD+86137xxxxxx",2000,S1debug);// "ATD+86137xxxxxxxx"dial the number
   delay(100);
}
 
/*
 * SubmitHttpRequest()
 * This function is submit a HTTP request
 * attention:the time of delay is very important, it must be set enough
 */
void SubmitHttpRequest(){
   SendData("AT+CREG?",1000,S1debug); //Query network registration
   delay(100);
   
   SendData("AT+CGATT=1",2000,S1debug);
   delay(100);
 
   SendData("AT+CGDCONT=1,\"IP\",\"CMNET\"",2000,S1debug);//setting PDP parameter
   delay(100);
 
   SendData("AT+CGACT=1,1",2000,S1debug); //Activate PDP, open Internet service
   delay(100);
 
   SendData("AT+CIPSTART=\"TCP\",\"www.baidu.com\",80",5000,S1debug); //Establish TCP connection
   delay(100);
 
   SendData("AT+CIPSEND=10,\"asdfg12345\"",2000,S1debug); //Send string "asdfg12345" and the length of string is 10
   delay(100);
   
   SendData("AT+CIPCLOSE",2000,S1debug);     //Close TCP
   delay(100);
}

void GetSignalQuality(){
     Serial_Print("Getting the sinal quality...",S_debug);
     SendData("AT+CSQ",1000,S1debug);
     Serial_Print("Tips:+CSQ: XX,QQ : It means the Signal Quality poorly when the XX less then 10!",S_debug);
}

void SendData(String command, const int timeout, boolean debug){
    String response = "";   
    Serial1.println(command);
    delay(5);
    if(debug){
    long int time = millis();   
    while( (time+timeout) > millis()){
      while(Serial1.available()){       
        response += char(Serial1.read());
      } 
    }   
      Serial.print(response);
    }   
}

void Serial_Print(String data, boolean debug){
  if(debug){
    Serial.println(data);
  }
}

void RecData(){
    String response = "";   
    while(Serial1.available()){       
        response += char(Serial1.read());
      }   
      Serial.print(response);   
}

Go Up