2017-12-12 3 views
0

ESP8266을 사용하여 Arduino Uno에서 PHP를 통해 Firebase로 데이터를 보내려고합니다. Firebase DB와 PHP 사이의 연결은 브라우저를 통해 수동으로 데이터를 보낼 수 있기 때문에 괜찮은 것 같습니다. 그러나 Arduino에서 PHP로 데이터를 보낼 수 없습니다.ESP8266 GET 요청이 작동하지 않습니다.

다음
#include "SoftwareSerial.h" 

String ssid ="xxxx"; 
String password="xxxx"; 

String server = "firstfirebase.000webhostapp.com"; // www.example.com 
String uri = "/firebaseTest.php";// our example is /esppost.php 

SoftwareSerial esp(2, 3);// RX, TX 

void setup() { 
    esp.begin(9600); 
    Serial.begin(9600); 
    reset(); 
    connectWifi(); 
} 

void reset() { 
    esp.println("AT+RST"); 
    delay(1000); 
    if(esp.find("OK")) 
    Serial.println("Module Reset"); 
} 

void connectWifi() { 
    String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\""; 
    esp.println(cmd); 
    delay(4000); 
    if(esp.find("OK")) { 
    Serial.println("Connected!"); 
    } else { 
    connectWifi(); 
    Serial.println("Cannot connect to wifi"); 
    } 
} 

void loop() { 
    httppost(); 
    delay(1000); 
} 

void httppost() { 
    esp.println("AT+CIPSTART=\"TCP\",\"firstfirebase.000webhostapp.com\",80");//start a TCP connection. 
    if(esp.find("OK")) { 
    Serial.println("TCP connection ready"); 
    } 
    delay(1000); 
    String getRequest = "GET firebaseTest.php?arduino_data=56.00 HTTP/1.1\r\nHost: firstfirebase.000webhostapp.com\r\n\r\n"; 
    String sendCmd = "AT+CIPSEND";//determine the number of caracters to be sent. 
    esp.print(sendCmd); 
    esp.println(getRequest.length()); 
    delay(500); 
    if(esp.find(">")) { 
    Serial.println("Sending.."); 
    esp.print(getRequest+"\r\n\r\n"); 
    delay(500); 
    esp.println("AT+CIPSTATUS"); 
    if(esp.find("SEND OK")) { 
     Serial.println("Packet sent"); 
     while (esp.available()) { 
     String tmpResp = esp.readString(); 
     Serial.println(tmpResp); 
     } 
     // close the connection 
     esp.println("AT+CIPCLOSE"); 
    } 
    } 
} 

직렬 모니터의 스크린 샷입니다 :

+0

를 사용하지 않을 경우은'server'의 포인트와'uri' 변수가 무엇입니까? –

+0

문자열을 제대로 연결하지 못했기 때문에 사용하지 않았습니다. 하지만 그건 내 질문에 대답하지 않는다. – DJoyekurun

답변

1

당신은 당신의 경로 앞에 / 누락

다음은 아두 이노 코드입니다.

이 있어야한다 :

String getRequest = "GET /firebaseTest.php?arduino_data=56.00 HTTP/1.1\r\nHost: firstfirebase.000webhostapp.com\r\n\r\n"; 
관련 문제