| 
 | 
4#
 
 
 樓主 |
發表於 2012-1-11 18:32:54
|
只看該作者
 
 
 
謝謝樓上的兩位大大的講解。 
 
我現在就只有做這樣簡單的事(#define和include沒打上來,很多),就如同我上面說的,如果用電腦的usb供電的話,去連這個網頁,看的到字,但如果是用外接電源,則會連不上這個網頁。 
 
void setup() 
{ 
    Ethernet.begin(mac, ip, gateway, subnet); 
    server.begin(); 
} 
 
 
void loop() 
{ 
    Client client = server.available(); 
 
    if (client)  
    { 
        while (client.connected()) 
        { 
            if (client.available()) 
            { 
                char c = client.read(); 
                //read char by char HTTP request 
                if (readString.length() < 30)  
                { 
                    //store characters to string  
                    readString += c; 
                }//end if (readString.length() < 30)  
 
                //output chars to serial port 
                //Serial.print(c); 
 
                //if HTTP request has ended 
                if (c == '\n')  
                { 
                    // now output HTML data starting with standart header 
                    client.println("HTTP/1.1 200 OK"); 
                    client.println("Content-Type: text/html"); 
                    client.println(); 
                    client.print("<body>"); 
                    //想show在網頁上的寫在這---start---- 
                    client.println("<h1>HTTP test routines</h1>"); 
                    //想show在網頁上的寫在這---end---- 
                    client.println("</body></html>"); 
                    //clearing string for next read 
                    readString=""; 
                    //stopping client 
                    client.stop(); 
                }//end if (c == '\n') 
 
            }//end if (client.available()) 
 
        }//end while (client.connected()) 
    }//end if (client)  
} |   
 
 
 
 |