The pings are not consistently stable

Hi Everyone,

I'm using
Arduino ide: 1.8.15
UIPEthernet :2.0.12
Ethernet Module : ENC28J60
Controller :ATmega4809(MegaCoreX)

#include <SPI.h>
#include <EthernetENC.h>
uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};

IPAddress serverIP(192, 168, 1, 92);

IPAddress myIP(192, 168, 1, 143);

EthernetServer server = EthernetServer(5000);

void setup()
{
  Serial2.begin(9600);
  Ethernet.init(7);
  Ethernet.begin(mac, myIP);

  server.begin();
}

void loop() {
  if (ping(serverIP)) {
    Serial2.println("Ping successful!");
  } else {
    Serial2.println("Ping failed!");
  }

  size_t size;

  if (EthernetClient client = server.available())
  {
    while ((size = client.available()) > 0)
    {
      uint8_t* msg = (uint8_t*)malloc(size);
      size = client.read(msg, size);
      Serial2.write(msg, size);
      free(msg);
    }
    client.println("DATA from Server!");
    client.stop();
  }

  //  delay(500);  // Wait for 5 seconds before pinging again
}

bool ping(IPAddress ip) {
  EthernetClient client;

  if (client.connect(ip, 5000)) {  // Use a common port like 7
    client.stop();
    return true;
  } else {
    client.stop();
    return false;
  }
}

I am conducting a simple ping test, and it is showing unstable results. The pings are not consistently stable. Could you please review the code for any potential issues?

That is 1/2 second, change it to about 2000 and see if things improve after enabling it. The target has other things to do beside responding to pings.

1 Like

I'm not pinging the target; I'm pinging my IP address only. When I connect my switch locally, it pings perfectly. However, whenever I connect my switch to the network, it does not ping successfully.
And I'm changed to 2000 delay. it's not working.

delay will not work. the library only handles network (including ping replay) if the functions of the library are invoked.

please use the EthernetENC library

I used EthernetENC too, but its not working.

how is it not working? if UIPEthernet works I am sure EthernetENC works too

I didn't recommend EthernetENC for this specific problem, but in general. I am the maintainer of both these libraries.

Let me know how to reslove this issue.

comment out the if (ping(serverIP)) {

yes i comment out the if(ping(serverIP)) {

//#include<SPI.h>
#include <UIPEthernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 143);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

IPAddress serverIP(192, 168, 1, 92);



EthernetServer server = EthernetServer(5000);

void setup()
{
  Serial2.begin(9600);
//  SPI.begin();
  Ethernet.init(7);
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
}

void loop() {
//  if (ping(serverIP)) {
//    Serial2.println("Ping successful!");
//  } else {
//    Serial2.println("Ping failed!");
//  }
//


  if (EthernetClient client = server.available())
  {
    while (client.available() > 0)
    {
//      uint8_t* msg = (uint8_t*)malloc(size);
//      size = client.read(msg, size);
//      Serial2.write(msg, size);
//      free(msg);
    }
//    client.println("DATA from Server!");
    client.stop();
  }

  //    delay(2000);  // Wait for 5 seconds before pinging again
}

//bool ping(IPAddress ip) {
//  EthernetClient client;
//
//  if (client.connect(ip, 5000)) {  // Use a common port like 7
//    client.stop();
//    return true;
//  } else {
//    client.stop();
//    return false;
//  }
//}


Still I'm facing the same problem.

is the MAC address and IP address unique?

yes, its was unique.

Why not use a modern baud rate? Are you sending your data to a teletype?
WACsOperateTeletype

just a thought.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.