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 = "";

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]);
  char a1[10],a2[10],a3[10],a4[10];

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

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[] = "";
      ether.parseIp(ether.hisip, websiteIP);
      // or provide a numeric IP address instead of a string
      byte hisip[] = { 192,168,1,1 };
      ether.copyIp(ether.hisip, hisip);

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

void loop(){

  if (millis() > timer) {
    timer = millis() + 1000;
    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 “” 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.



If you have a string like "", 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.



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.