简体   繁体   English

Arduino以太网盾未检测到断开连接

[英]Arduino Ethernet Shield doesn't Detect Disconnection

I have c++ server and Arduino UNO client with Ethernet Shield. 我有带有以太网屏蔽的c ++服务器和Arduino UNO客户端。 My problem is that the server detcect any disconnection (c# server, Android application), except the Arduino one. 我的问题是,除了Arduino之外,服务器会检测到任何断开连接(C#服务器,Android应用程序)。 With no reason, I guess that the Arduino socket still run, even after the Arduino has no power supply. 没有理由,我猜想即使在Arduino没有电源的情况下,Arduino插座仍然可以运行。 This is the Arduino code: 这是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;
 }
}

How can the Arduino close it's socket automatically when it has no power supply? Arduino在没有电源的情况下如何自动关闭其插座?

With just Arduino , you can't. 仅使用Arduino ,您做不到。 Arduino cannot close its socket automatically when it has no power supply . Arduino在没有电源的情况下无法自动关闭其插槽 Arduino is not like laptop or Android as they have a battery pack of their own, with little brain to respond accordingly. Arduino与笔记本电脑或Android不同,它们拥有自己的电池组,几乎没有相应的反应能力。 Also the poor thing doesn't even know when the power is going to blow out. 而且,可怜的东西甚至不知道什么时候电源会断电。

However , it can be done. 但是 ,可以做到。 Give your Arduino one of its own power bank. 给您的Arduino自己的移动电源之一。 You can read this powerbank's voltage level and set the threshold point to make your Arduino close its connections and go to sleep. 您可以读取此移动电源的电压电平并设置阈值点,以使Arduino关闭其连接并进入睡眠状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM