0
votes

I have c++ server and Arduino UNO client with Ethernet Shield. My problem is that the server detcect any disconnection (c# server, Android application), except the Arduino one. With no reason, I guess that the Arduino socket still run, even after the Arduino has no power supply. This is the Arduino code:

#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?

1
I'm sorry, but that is not very clear:(Martin James
What is not clear for you? @MartinJamesP.Kole

1 Answers

0
votes

With just Arduino, you can't. Arduino cannot close its socket automatically when it has no power supply. Arduino is not like laptop or Android as they have a battery pack of their own, with little brain to respond accordingly. 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. You can read this powerbank's voltage level and set the threshold point to make your Arduino close its connections and go to sleep.