0

I'm trying to write an Arduino sketch which pings multiple hosts and switches some RGB LEDs to indicate the status of the devices on my network. This question is a followup of ParseIP in the EtherCard library does not parse an address twice

I've gone back to the "pings" example sketch from the Ethercard library and modified it a little, so it only pings a single host. In my previous question timemage explained that parseIP was destructive, so I needed to include a function to set the ether.hisip value instead of using parseIP. However, when I switch the commented lines from parseIP to the Set_Ether_IP function, I no longer get ping replies.

Here is my code:

#include <EtherCard.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
static void gotPinged (byte* ptr) 
{
 ether.printIp(">>> ping from: ", ptr);
}
void setup () 
{
 Serial.begin(115200);
 Serial.println("\n[pings]");
 if (ether.begin(sizeof Ethernet::buffer, mymac, 8) == 0)
 Serial.println(F("Failed to access Ethernet controller"));
 if (!ether.dhcpSetup())
 Serial.println(F("DHCP failed"));
 ether.printIp("IP: ", ether.myip);
 ether.printIp("GW: ", ether.gwip);
 // Set_Ether_IP("192.168.123.150");
 ether.parseIp(ether.hisip, "192.168.123.150");
 ether.printIp("SRV: ", ether.hisip);
 ether.registerPingCallback(gotPinged);
 timer = -9999999; // start timing out right away
 Serial.println();
}
void loop () 
{
 word len = ether.packetReceive(); // go receive new packets
 word pos = ether.packetLoop(len); // respond to incoming pings
 if (len > 0)
 {
 Serial.println(len);
 }
 // if (len > 0 && ether.packetLoopIcmpCheckReply(Set_Ether_IP("192.168.123.150")))
 if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip))
 {
 Serial.print(" ");
 Serial.print((micros() - timer) * 0.001, 3);
 Serial.println(" ms");
 }
 // ping a remote server once every few seconds
 if (micros() - timer >= 5000000)
 {
 ether.printIp("Pinging: ", ether.hisip);
 timer = micros();
 // ether.clientIcmpRequest(Set_Ether_IP("192.168.123.150"));
 ether.clientIcmpRequest(ether.hisip);
 ether.printIp("Pinged: ", ether.hisip);
 }
}
uint8_t Set_Ether_IP(const char *dotted_quad)
{
 char destructable_dotted_quad[sizeof "aaa.bbb.ccc.ddd"];
 strncpy(destructable_dotted_quad, dotted_quad, sizeof destructable_dotted_quad);
 return ether.parseIp(ether.hisip, destructable_dotted_quad);
}

So basically when I use parseIp the sketch works (but then I cannot elaborate the sketch to ping multiple hosts one after the other because of the destructive nature of parseIp), and when I use the function Set_Ether_IP, I no longer get replies to my pings...

What do I need to change in order to get ping replies while using this Set_Ether_IP function?

asked Aug 8 at 14:30
2
  • You were trying to run ether.packetLoopIcmpCheckReply(Set_Ether_IP("192.168.123.150")) ? Commented Aug 8 at 17:25
  • @timemage Yes. I also tried ether.packetLoopIcmpCheckReply(ether.hisip) as well as ether.packetLoopIcmpCheckReply("192.168.123.150") because I figured ether.hisip isn't set here, but none of those worked. Commented Aug 8 at 22:26

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.