Open burakkorman opened 4 years ago
It doesn't seems that mbed.org likes HTTP 1.0 (which really shouldn't come as a surprise) Try sending it as a http 1.1 request, and remember to send the host header
@hoerup I tried, but I get a 400 (Bad Request) error.
Could you paste your updated code
` #include
SoftwareSerial mySerial(PIN_TX,PIN_RX); DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.1\r\n\r\n"; char buffer2[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("cmnet"))) {
Serial.println("Sim808 join network error");
delay(2000);
}
//************ Successful DHCP ****************
Serial.print("IP Address is ");
Serial.println(sim808.getIPAddress());
//*********** Establish a TCP connection ************
if(!sim808.connect(TCP,"mbed.org", 80)) {
Serial.println("Connect error");
}else{
Serial.println("Connect mbed.org success");
}
//*********** Send a GET request *****************
Serial.println("waiting to fetch...");
sim808.send(http_cmd, sizeof(http_cmd)-1);
while (true) {
int ret = sim808.recv(buffer2, sizeof(buffer2)-1);
if (ret <= 0){
Serial.println("fetch over...");
break;
}
buffer2[ret] = '\0';
Serial.print("Recv: ");
Serial.print(ret);
Serial.println(" bytes: ");
Serial.println(buffer2);
break;
}
//************* Close TCP or UDP connections **********
sim808.close();
//*** Disconnect wireless connection, Close Moving Scene *******
sim808.disconnect();
}
void loop(){
}`
in my previous comment i did write "remember to send the host header" which is a mandatory header in http 1.1
Can you share sample code with me?
char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.1\r\nHost:mbed.org\r\n\r\n";
I tried with the last comment and the result was: AT AT+CFUN=1 AT+CPIN? AT+CSTT="sl2sfr","","" AT+CIICR AT+CIFSR IP Address is 100.75.179.118 AT+CIPSTART="TCP","mbed.org",80 Connect mbed.org success waiting to fetch... AT+CIPSEND=70 GET /media/uploads/mbed_official/hello.txt HTTP/1.1 Host:mbed.org
Recv: 442 bytes: HTTP/1.1 301 Moved Permanently Date: Tue, 21 Dec 2021 12:16:41 GMT Content-Type: text/html Content-Length: 162 Connection: keep-alive Location: https://mbed.org/media/uploads/mbed_official/hello.txt Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
AT+CIPSTATUS AT+CIPSHUT
So do you have a solution, please?
The code I wrote:
`#include
include
define PIN_TX 10
define PIN_RX 11
SoftwareSerial mySerial(PIN_TX,PIN_RX); DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
char http_cmd[] = "GET /media/uploads/mbed_official/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("cmnet"))) { Serial.println("Sim808 join network error"); delay(2000); }
//**** Successful DHCP **** Serial.print("IP Address is "); Serial.println(sim808.getIPAddress());
//*** Establish a TCP connection **** if(!sim808.connect(TCP,"mbed.org", 80)) { Serial.println("Connect error"); }else{ Serial.println("Connect mbed.org success"); }
//* Send a GET request *** Serial.println("waiting to fetch..."); sim808.send(http_cmd, sizeof(http_cmd)-1); 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(){
}`
But I get such a result : `