DFRobot / DFRobot_SIM808

SIM808
MIT License
69 stars 56 forks source link

is_connected() not working, send() problems. #9

Open lvj opened 7 years ago

lvj commented 7 years ago

With code belowe I have problems.

  1. is_connected() does not seem to work
  2. Every few GETs some other string is sent instead GET /hello.txt ...
  3. I get send error but I can see in webserver log that there is request made

BTW what is the proper way of making regular get requests, I thought it would be check if connected, if not connect, send request.

Serial monitor

AT+CIPSTART="TCP","f.example.org",8666
Connect error
AT+CIPSTATUS
TCP NOT CONNECTED
Sending CMD
GET /hello.txt HTTP/1.0

AT+CIPSEND=27
GET /hello.txt HTTP/1.0

Webserver LOG

5.41.3.224 - - [04/Sep/2017:12:57:07 +0200] "GET /hello.txt HTTP/1.0" 200 5 "-" "-"
95.41.3.224 - - [04/Sep/2017:12:57:27 +0200] "GET /hello.txt HTTP/1.0" 200 5 "-" "-"
31.2.54.24 - - [04/Sep/2017:12:58:30 +0200] "AT+CIPSTART=\x22TCP\x22,\x22f.example." 400 173 "-" "-"
31.2.54.24 - - [04/Sep/2017:12:59:00 +0200] "GET /hello.txt HTTP/1.0" 200 5 "-" "-"

Code

/*
### Connect TCP and send GET request.
1. This example is used to test DFRobot_SIM808 GPS/GPRS/GSM Shield's connect TCP and send GET request.
2. Open the SIM808_TCPConnection example or copy these code to your project
3. Download and dial the function switch to Arduino
4. Open serial helper
5. Waiting for a few minutes, until serial has sent "Connect mbed.org success"
6. Serial will send "Hello world!"

create on 2016/09/23, version: 1.0
by jason
*/
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>

//#define PIN_TX    10
//#define PIN_RX    11
//SoftwareSerial mySerial(PIN_TX,PIN_RX);
//DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

//make sure that the baud rate of SIM900 is 9600!
//you can use the AT Command(AT+IPR=9600) to set it through SerialDebug

DFRobot_SIM808 sim808(&Serial);

char http_cmd[] = "GET /hello.txt HTTP/1.0\r\n\r\n";
char buffer[512];

void setup(){
  //mySerial.begin(9600);
  Serial.begin(9600);

  //******** Initialize sim808 module *************
  while(!sim808.init()) {
      delay(1000);
       Serial.print("Sim808 init error\r\n");
  }
  delay(3000);  

  //*********** Attempt DHCP *******************
  while(!sim808.join(F("internet"))) {
       Serial.println("Sim808 join network error");
      delay(2000);
  }

  //************ Successful DHCP ****************
  Serial.print("IP Address is ");
  Serial.println(sim808.getIPAddress());

}

void makeGetReq()
{

  //*********** Establish a TCP connection ************

  if(!sim808.connect(TCP,"f.example.org", 8666)) {
       Serial.println("Connect error");
  }else{
      Serial.println("Connect mbed.org success");
  }

  if(sim808.is_connected() == false)
  {
    Serial.println("TCP NOT CONNECTED");
  } else if (sim808.is_connected() == true)
  {
    Serial.println("TCP CONNECTED");
  }

  //*********** Send a GET request *****************
   Serial.println("Sending CMD");
   Serial.println(http_cmd);
  sim808.send(http_cmd, sizeof(http_cmd)-1);
  delay(5000);
//  while (true) {
//      int ret = sim808.recv(buffer, sizeof(buffer)-1);
//      if (ret <= 0){
//          Serial.println("fetch over...");
//          break; 
//      }
//      buffer[ret] = '\0';
//      Serial.print("Recv: ");
//      Serial.print(ret);
//      Serial.print(" bytes: ");
//      Serial.println(buffer);
//      break;
//  }

  //************* Close TCP or UDP connections **********
  //sim808.close();

  //*** Disconnect wireless connection, Close Moving Scene *******
  //sim808.disconnect();
}

void loop(){

  makeGetReq();

}
danielkp1234 commented 5 years ago

how did u fix this @lvj

interstellarturk commented 1 year ago

Yeah, I'm trying use sim808.send method for POST request my webserver with TCP connection. After connection established, it looks like .send method doesn't work. Because of even delay(5000); method it doesn't send my payload to my webserver.