2016-04-22 95 views
0

我有C++服務器和Arduino UNO客戶端以太網盾。 我的問題是,服務器會檢測任何斷開連接(c#服務器,Android應用程序),除Arduino之外。沒有理由,即使在Arduino沒有電源供應之後,我猜Arduino插座仍在運行。 這是Arduino的代碼:Arduino以太網盾不檢測斷開

#include <SPI.h> 
#include <Ethernet.h> 

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 

IPAddress ip(192, 168, 1, 4); 

EthernetClient client; 

void setup() 
{ 
    Serial.begin(9600); 
    while (!Serial) 
    { 
    ; 
    } 

    if (Ethernet.begin(mac) == 0) 
    { 
    Serial.println("Failed to configure Ethernet using DHCP"); 
    Ethernet.begin(mac, ip); 
    } 

    delay(1000); 
    Serial.println("connecting..."); 

    if (client.connect("192.168.1.11", 1626)) 
    { 
    Serial.println("connected"); 
    } 
    else 
    { 
    Serial.println("connection failed"); 
    } 

} 

void loop() 
{ 
    client.write("hello", strlen("hello")+1); 

    if (!client.connected()) 
    { 
     Serial.println("connection failed"); 
    client.stop(); 
    return; 
} 
} 

Arduino的如何可以關閉它的插座時自動它沒有電源?

+0

對不起,但那不是很清楚:( –

+0

有什麼不明白的嗎?@MartinJames –

回答

0

只有Arduino,你不能。 Arduino在沒有電源的情況下無法自動關閉插座。 Arduino不像筆記本電腦或Android,因爲他們擁有自己的電池組,因此幾乎沒有相應的迴應。此外,這個可憐的東西甚至不知道什麼時候電力會被吹掉。

但是,可以這樣做。給你的Arduino一個自己的電源銀行。你可以閱讀這個powerbank的電壓水平並設置閾值點,讓你的Arduino關閉它的連接並進入睡眠狀態。

+1

_「你不能。」「可以這樣做。」_決定你的想法吧? –

+0

請不要使用散文的代碼格式。 –

相關問題