Hi,
I am using several arduinos each with a W5500 module to collect data and on request from a client program on the PC, send that data back to be logged. The PC knows what the MAC addresses I have assigned to each arduino is but it cant know what IP address the DHCP is going to assign so it uses the ARP table to find out.
I found that when the arduino connects to the network and is given an IP address by the DHCP, it does not show up in the ARP table. If I ping its IP address (which I can find out if I have the serial monitor running on the IDE) from the PC, it does show up on the table. I also found that if I try to connect to the PC as a client, then the arduino's IP address does get added to the ARP table immediately.
Now, my PC is on IP address 192.168.1.14 so in my sketch I declare
IPAddress ip(192,168,1,14);
and my code for joining the network is as follows
void StartEther()
{
int l=0;
bool inc= false;
bool conok = false;
memset(confirm, 0, 5);
digitalWrite(NWK_LED,LOW);
if(Ethernet.begin(mac))
{
digitalWrite(NWK_LED,HIGH);
nwkon=true;
server.begin();
Serial.print("Server IP : ");
Serial.println(Ethernet.localIP());
Serial.print("Sending ENQ to Client ... ");
arp.connect(ip, 1234);
delay(100);
if(arp.connected())
{
arp.println("ENQ~");
delay(100);
inc = true;
while (arp.connected() && inc == true)
{
if (arp.available())
{
char c = arp.read();
lastChr = millis();
if (c == '~' && l<4)
inc = false;
else
{
confirm[l]=c;
l++;
if(l>3)
{
Serial.println("Incorrect reply");
arp.flush();
inc = false;
}
}
}
if(inc && (millis()-lastChr)> CTIMEOUT)
{
arp.flush();
memset(confirm, 0, 5);
inc = false;
}
}
}
if(confirm[0]=='A' && confirm[1]=='C' && confirm[2]=='K') // Enquiry confirmed with "ACK"
{
Serial.println("Client present");
clientfound = true;
}
else
{
Serial.println("No Client found");
clientfound = false;
}
arp.stop();
}
else
{
Serial.println("Network FAIL");
nwkon=false;
}
}
This work fine but if for any reason my PC started up and was given a different IP address, the whole thing would fail. I have tried setting the IP address to connect to as client to the broadcast address 255.255.255.255 but that doesn't work.
Any different ideas how I can make the IP address of the arduino appear on the ARP table automatically