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