save remoteIP() as ipaddress

I want to send an message and depending on the message i want to save the ip address of the send as a client ip address

void recPacket() {
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    int len = Udp.read(incomingPacket, 2000);
    char verifyStart[7]; //NODEC1 plus null
    char verifyEnd[7]; //C1NODE plus null
    char _data[5];
    strncpy (verifyStart, (char*)incomingPacket, 6);//6 bytes
    strncpy (verifyEnd, (char *)incomingPacket + len - 6 , 6 );//6 bytes
    verifyStart[6] = 0; //null terminate
    verifyEnd[6] = 0; //null terminate
    if (strcmp(verifyStart, "WHO") == 0) {
      if (strcmp(verifyEnd, "OHW") == 0) {

        Serial.println(Udp.remoteIP());

        IPAddress Client1() = Udp.remoteIP(); //problem
        
        Udp.beginPacket(Client1, ServerPort);
        Udp.write("NODEEN");
        Udp.write("NENODE");
        Udp.endPacket();
      }
    }
  }
}

IPAddress Client1IP = Udp.remoteIP();

Juraj:
IPAddress Client1IP = Udp.remoteIP();

Thanks, now how about if i wanted to send messages through a range of ip address.

Udp.beginPacket(RANGE_OF_IPS, PORT);
        Udp.write("ME");
        Udp.write("EM");
        Udp.endPacket();

My attempt to do this isnt working. i because im not sure how to handle the positioning in the char array. please help,

#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <FS.h>
#include <ArduinoJson.h>

IPAddress local_IP(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);

IPAddress Client1(192, 168, 4, 2); //UC CONTROLLER

IPAddress sta_local_IP(10, 0, 0, 232);
IPAddress sta_gateway(10, 0, 0, 1);
IPAddress sta_subnet(255, 0, 0, 0);

const char* ssid = "wfi";
const char* password = "12345";
unsigned int localUdpPort = 4210;  // local port to listen on
char incomingPacket[2000];
unsigned long now = 0;
String ip = "10.0.0.255";
char iparray[50];

WiFiUDP Udp; //ap client port
void setup() {
  Serial.begin(115200);
  WiFi.persistent(0);
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin("Wireless3", "zdkzdkzdk120!!");
  WiFi.config(sta_local_IP, sta_subnet, sta_gateway);
  WiFi.softAP(ssid, password, 12, false, 32);
  WiFi.softAPConfig(local_IP, local_IP, subnet);
  ip.toCharArray(iparray, 50);
  Udp.begin(localUdpPort);
}

void loop() {

  if (millis() - now >= 5000) {
    for (int i = 0; i <= 255; i++) {
      iparray[10] = i;
      Udp.beginPacket(iparray, 4220);
      Udp.write("mesg");
      Udp.write("mesg");
      Udp.endPacket();
      Serial.println(iparray);
    }
    now = millis();
  }
}

So far i have done this and it sort of works. how can i split an ip address string into 4 different values?

  if (millis() - now >= 5000) {
    for (int i = 0; i <= 255; i++) {
      String ips = "";
      ips += "10";
      ips += ".";
      ips += "0";
      ips += ".";
      ips += "0";
      ips += ".";
      ips += i;
      ips.toCharArray(iparray, 50);
      // iparray[]++;
      delay(30);
      Udp.beginPacket(iparray, 4220);
      Udp.write("T1OFFE");
      Udp.write("UT1OFF");
      Udp.endPacket();
      Serial.println(ips);
    }
    now = millis();
  }

You should manipulate an IPAddress object directly.

IPAddress myaddress;

myAddress[0] = 10;
myAddress[1] = 0;
myAddress[2] = 0;
myAddress[3] = 0;

for(int i=0; i<255; ++i ) {
  myAddress[3] = i;
  // do something with myAddress
}

blh64:
You should manipulate an IPAddress object directly.

IPAddress myaddress;

myAddress[0] = 10;
myAddress[1] = 0;
myAddress[2] = 0;
myAddress[3] = 0;

for(int i=0; i<255; ++i ) {
 myAddress[3] = i;
 // do something with myAddress
}

i know how to read the current ipaddress but,

What i want is to get the current ip address and split it into 4 parts. this way i can use a for loop to incriment the last octave of the ipaddress.

this is what i tried but its not working the way id like. it seems the 4th entry to sa is only right sometimes?

  if (millis() - now >= 5000) {
    if (WiFi.status() == WL_CONNECTED) {
      int sa[16], r = 0, t = 0;
      String oneLine = WiFi.localIP().toString() ;
      oneLine += ".";
      for (int i = 0; i < oneLine.length(); i++)
      {
        if (oneLine.charAt(i) == '.')
        {
          sa[t] = oneLine.substring(r, i).toInt();
          r = (i + 1);
          t++;
          Serial.println(sa[0]);
          Serial.println(sa[1]);
          Serial.println(sa[2]);
          Serial.println(sa[3]);
          Serial.println(WiFi.localIP());
        }
      }
    }

Thanks i got it working

  if (millis() - now >= 5000) {
    if (WiFi.status() == WL_CONNECTED) {
      IPAddress myaddress = WiFi.localIP();
      myaddress[3] = 0;
      for (int i = 0; i < 255; ++i ) {
        myaddress[3] = i;
        delay(30);
        Udp.beginPacket(myaddress, 4220);
        Udp.write("T1OFFE");
        Udp.write("UT1OFF");
        Udp.endPacket();
        Serial.println(myaddress);
      }
    }
    now = millis();
  }
}

I wrote a function to send data via udp. if i use the ip address from the char array in eeprom it causes a long pause and udp.beginPacket. the message is still sent and the receiver gets the messagebut it causes a few second pause. if i use usp.beginPacket("xxx.xxx.xxx.xxx") there is no pause?

struct {
  char UV_IP[16];
  char  sta_ssid[15];
  char  sta_password[15];
  char  system_password[15];
} _EEPROM;
String UV_IP = "";
void handleDisableuv() {
  Serial.println("1");
  Udp.beginPacket(_EEPROM.UV_IP, 4220);
   Serial.println("3");
  Udp.write("NODEDI");
   Serial.println("4");
  Udp.write("IDNODE");
   Serial.println("5");
  Udp.endPacket();
   Serial.println("6");
  //sendCommand(Client1, 0, 1,"NODEDI","IDNODE");
  server.send(200, "text/html", "Okay!"); //redirrect to settings
   Serial.println("7");
}

any idea for the delay?

Udp.beginPacket(_EEPROM.UV_IP, ServerPort); //CHAR ARRAY AS IP, CAUSES LONG DELAY
Udp.beginPacket("0.0.0.0", ServerPort); //string as ip works fine no delay
Udp.beginPacket(uvip, ServerPort); //String object as ip dont compile

do i need to convert the char array ip address to IPaddress class? isnt Ipaddress char array? whats going on

I cant figure this out i really need some help. the docs suck they dont mention hardly anything

CHAR ARRAY AS IP, CAUSES LONG DELAY

struct {
  char UV_IP[16];
  char  sta_ssid[15];
  char  sta_password[15];
  char  system_password[15];
} _EEPROM;

Udp.beginPacket(_EEPROM.UV_IP, 4220);

Is _EEPROM.UV.IP as actually stored in the struct a null terminated character array of the four byte .decimal format "0.0.0.0"

What does a byte by byte serial print of the characters in UV_IP[16] show?

Perhaps if Udp.beginPacket() does not see a null terminator there is a timeout.

When i print _EEPROM.UV_IP it prints ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ but some how udp.beginPacket still uses it as an ipaddress but its buggy.

so many different threads. sorry i keep running into lots of problems. need help with the logic maybe.

i just want to store the ipaddress return from udp.getRemoteIP() into a char array only so i can store it in the eeprom and use it like a IPAddress class object so i can UDP.BeginPacket(ip_array, port);

the logic behind this is, master connect to WLAN then sends out upd messages to all addresses and when a client gets the message the client saves that ip address as the server address. then the client responds to the sending address and the master saves the clients ip address

you can store the IP address in EEPROM. the 4 bytes. then read it into a variable in memory and use that variable in beginPacket

in the end it wasn't storing the cahr array because i was calling my function wrong. i called,

_writeEEPROM; i needed _writeEEPROM(); lol