2017-12-28 78 views
0

ESP8266 및 Arduino를 사용하여 Rpi- 서버에서 실행되는 간단한 웹 페이지에 액세스하려고합니다.Arduino-Uno에서 GET 요청이 실패했습니다.

나는 this similar SO question을 심판 하였지만 내 문제의 해결책이 아닙니다.

#include "WiFiEsp.h" 

// Emulate Serial1 on pins 6/7 if not present 
#ifndef HAVE_HWSERIAL1 
#include "SoftwareSerial.h" 
SoftwareSerial Serial1(2,3); // RX, TX 
#endif 

char ssid[] = "RPi";   // your network SSID (name) 
char pass[] = "raspberry";  // your network password 
int status = WL_IDLE_STATUS;  // the Wifi radio's status 

char server[] = "192.168.50.1"; 

// Initialize the Ethernet client object 
WiFiEspClient client; 

void setup() 
{ 
    // initialize serial for debugging 
    Serial.begin(9600); 
    // initialize serial for ESP module 
    Serial1.begin(9600); 
    // initialize ESP module 
    WiFi.init(&Serial1); 

    // check for the presence of the shield 
    if (WiFi.status() == WL_NO_SHIELD) { 
    Serial.println("WiFi shield not present"); 
    // don't continue 
    while (true); 
    } 

    // attempt to connect to WiFi network 
    while (status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to WPA SSID: "); 
    Serial.println(ssid); 
    // Connect to WPA/WPA2 network 
    status = WiFi.begin(ssid, pass); 
    } 

    // you're connected now, so print out the data 
    Serial.println("You're connected to the network"); 

    printWifiStatus(); 

    Serial.println(); 
    Serial.println("Starting connection to server..."); 
    // if you get a connection, report back via serial 
    if (client.connect(server, 80)) { 
    Serial.println("Connected to server"); 
    // Make a HTTP request 
    client.println("GET /simple.html HTTP/1.1"); 
    client.println("Host: 192.168.50.1"); 
    client.println("Connection: close"); 
    client.println(); 
    } 
} 

void loop() 
{ 

    while (client.available()) { 
    char c = client.read(); 
    Serial.write(c); 
    } 

    // if the server's disconnected, stop the client 
    if (!client.connected()) { 
    Serial.println(); 
    Serial.println("Disconnecting from server..."); 
    client.stop(); 

    // do nothing forevermore 
    while (true); 
    } 

void printWifiStatus() 
{ 
    // print the SSID of the network you're attached to 
    Serial.print("SSID: "); 
    Serial.println(WiFi.SSID()); 

    // print your WiFi shield's IP address 
    IPAddress ip = WiFi.localIP(); 
    Serial.print("IP Address: "); 
    Serial.println(ip); 

    // print the received signal strength 
    long rssi = WiFi.RSSI(); 
    Serial.print("Signal strength (RSSI):"); 
    Serial.print(rssi); 
    Serial.println(" dBm"); 
} 

출력 :

Starting connection to server... 
[WiFiEsp] Connecting to 192.168.50.1 
Connected to server 
[WiFiEsp] Data packet send error (2) 
[WiFiEsp] Failed to write to socket 3 
[WiFiEsp] Disconnecting 3 

simple.html은 다음과 같습니다

여기에 내 현재 아두 이노 코드입니다.

<html> 
    <body> 

     <p>1</p> 

    </body> 
</html> 

} 

웹 브라우저에서이 페이지에 액세스하고 콘텐츠를 올바르게 표시합니다. 무엇이 누락 되었습니까?

미리 감사드립니다.

+0

esp8266 충분히 강한 전원 공급 장치가? Arduino의 3.3V 핀은 WiFi 데이터 전송에 필요한 암페어를 공급할 수 없습니다. – Juraj

답변

0

코드에서이 줄을 시도

client.print("GET /simple.html HTTP/1.0\r\n\r\n");