【问题标题】:Arduino Ethernet Shield doesn't Detect DisconnectionArduino Ethernet Shield 未检测到断开连接
【发布时间】:2016-04-22 13:11:12
【问题描述】:

我有带有 Ethernet Shield 的 c++ 服务器和 Arduino UNO 客户端。 我的问题是服务器检测到任何断开连接(c# 服务器、Android 应用程序),除了 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如何在没有电源的情况下自动关闭它的插座?

【问题讨论】:

  • 对不起,这不是很清楚:(
  • 您有什么不清楚的地方? @MartinJames

标签: c++ sockets arduino client-server ethernet


【解决方案1】:

只有 Arduino,你不能。 Arduino 在没有电源的情况下无法自动关闭其插座。 Arduino 不像笔记本电脑或 Android,因为它们有自己的电池组,几乎没有大脑做出相应的反应。而且这可怜的东西甚至不知道什么时候会断电。

不过,是可以做到的。给你的 Arduino 一个自己的移动电源。您可以读取此移动电源的电压水平并设置阈值点以使您的 Arduino 关闭其连接并进入睡眠状态。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多