2016-10-16 6 views
0

안녕하세요, 코드 arduino ide를 사용하여 값 형식을 테스트하고 WIFIClient 예제를 수정하여 GET을 사용하여 로컬 호스트에 값을 보내도록 수정했습니다. 그것은 나에게 나쁜 요청 오류를 제공합니다. 어떤 도움이나 제안400 잘못된 요청 arduino esp8266

수정 WIFIClinet

#include <ESP8266WiFi.h> 

const char* ssid  = "ssid"; 
const char* password = "pwd"; 


const char* host = "http://10.0.0.39/edu/arduino.php"; 



void setup() { 
    Serial.begin(115200); 
    delay(10); 

    // We start by connecting to a WiFi network 

    Serial.println(); 
    Serial.println(); 
    Serial.print("Connecting to "); 
    Serial.println(ssid); 

    WiFi.begin(ssid, password); 

    while (WiFi.status() != WL_CONNECTED) { 
    delay(500); 
    Serial.print("."); 
    } 

    Serial.println(""); 
    Serial.println("WiFi connected"); 
    Serial.println("IP address: "); 
    Serial.println(WiFi.localIP()); 
} 

int value = 0; 

void loop() { 
    delay(5000); 
    ++value; 

    Serial.print("connecting to "); 
    Serial.println(host); 

    // Use WiFiClient class to create TCP connections 
    WiFiClient client; 
    const int httpPort = 80; 
    if (!client.connect(host, httpPort)) { 
    Serial.println("connection failed"); 
    return; 
    } 




    // We now create a URI for the request 
    String url ="?v=we"; 
// 
// 
Serial.print("Requesting URL: "); 
    Serial.println(url); 

// This will send the request to the server 
    client.print(String("GET ") + url + " HTTP/1.1\r\n" + 
       "Host: " + host + "\r\n" + 
       "Connection: close\r\n\r\n"); 
// 
unsigned long timeout = millis(); 
    while (client.available() == 0) { 
    if (millis() - timeout > 5000) { 
     Serial.println(">>> Client Timeout !"); 
     client.stop(); 
     return; 
    } 
    } 

    // Read all the lines of the reply from server and print them to Serial 
    while(client.available()){ 
    String line = client.readStringUntil('\r'); 
    Serial.print(line); 
    } 

    Serial.println(); 
    Serial.println("closing connection"); 

} 시리얼 모니터

출력을 감사

connecting to http://10.0.0.39/edu/arduino.php 
Requesting URL: ?v=we 
HTTP/1.0 400 Bad Request 
Server: httpd 
Date: Sat, 01 Jan 2011 22:02:19 GMT 
Content-Type: text/html 
Connection: close 

<HTML><HEAD><TITLE>400 Bad Request</TITLE></HEAD> 
<BODY BGCOLOR="#cc9999"><H4>400 Bad Request</H4> 
Bad filename. 
</BODY></HTML> 

답변

1

나는이 지역에서이 작업을 실행 사람들에게 도움이 될 것입니다 희망 호스트 변경됨

const char* host = "http://10.0.0.39/edu/arduino.php"; 
to 
const char* host = "10.0.0.39"; 

String url ="?v=we"; 
to 

String url ="/edu/arduino.php?v=we";