【发布时间】: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