EtherCard and converting string for ether.hisip

Hi Guys

I have a project i been working on it works. but i wanted to take it a litter further in a way

what my could does its this
1.connects to network and shows IP
2.Looks for a UDP Broadcaster and gets it IP
3.Connects to HTTP Server (hard coded IP) and retrieves data.

what i want to do is use the IP Address that the UDP Side of the code gets and inserts it into the ether.hisip.

my variables.

String ipaddy;
String CurrentTime;
String MainBroadcastIP;
String MainBroadcastIP2;

const char website[] PROGMEM = "192.168.15.3";

my UDP Code is this

ether.udpServerListenOnPort(&udpSerialPrint, 8888);

void udpSerialPrint(word port, byte ip[4], const char *data, word len) {
IPAddress src(ip[0], ip[1], ip[2], ip[3]);
  //Serial.println(src);
  char a1[10],a2[10],a3[10],a4[10];
        sprintf(a1,"%d",src[0]);
        sprintf(a2,"%d",src[1]);
        sprintf(a3,"%d",src[2]);
        sprintf(a4,"%d",src[3]);

        MainBroadcastIP = String(a1) + "." + a2 + "." + a3 + "." + a4;
        //MainBroadcastIP2 = src;
      //Serial.println(MainBroadcastIP);
      return;
}

My Code for the HTTP Server connection is this.

    #if 1
      // use DNS to resolve the website's IP address
      if (!ether.dnsLookup(website))
        Serial.println("DNS failed");
    #elif 2
      // if website is a string containing an IP address instead of a domain name,
      // then use it directly. Note: the string can not be in PROGMEM.
      char websiteIP[] = "192.168.1.1";
      ether.parseIp(ether.hisip, websiteIP);
    #else
      // or provide a numeric IP address instead of a string
      byte hisip[] = { 192,168,1,1 };
      ether.copyIp(ether.hisip, hisip);
    #endif

      ether.printIp("SRV: ", ether.hisip);


void loop(){
      ether.packetLoop(ether.packetReceive());

  if (millis() > timer) {
    timer = millis() + 1000;
    Serial.println();
    Serial.print("<<< REQ ");
    ether.hisport = 8181;
    ether.browseUrl(PSTR("/arduino"), "", website, my_callback);
  }
 
}

i want to be able to get the IP Address the the UDP part of the codes get and put it in place of where the ip address of “192.168.15.3” is.

I’m still a newb and still trying to get the right char, strings, etc. with no luck.

i’ve looked everywhere with no success.

Anyone???????

jeremy450:
Anyone???????

If you have a string like "192.168.2.24", you need to use strtok() to parse the string. Use atoi() to convert a token to a byte, and store the byte in an array.

Use ether.copyIp() to copy the array into ether.hisip.

Actually, converting the byte array to 4 strings, and creating a String from the strings, so that you can then convert the String to a byte array does not make sense.

Hey Paul

So your saying if i put the IPAddress src at the top of the sketch and then use ether.copyIp(src) it should work?

sorry still getting my head around the arduino code. different to the coding i normally do.

regards
Jeremy

anyone?

So your saying if i put the IPAddress src at the top of the sketch and then use ether.copyIp(src) it should work?

If the code is written correctly, yes.

Hi Paul

From the code you have seen can it been done?

sorry as i said from the start. I am a newb at this.

regards
Jeremy

anyone???