How to send the IP address by the serial uart?

People, Friday's question is:

How do I join the 4 octets leaving the format 196.187.34.56 for example?

ipaddress[4] is returning = 0

Then I'm going to send it via the serial uart from one esp to another, I certainly hope to see the same format there at the destination 196.187.34.56

In setup()

IPAddress localIp = WiFi.localIP();
    uint8_t firstOctet = localIp[0];
    uint8_t secondOctet = localIp[1];
    uint8_t thirdOctet = localIp[2];
    uint8_t fourthOctet = localIp[3]; 
    uint32_t ipaddress[4] = {localIp[0], localIp[1], localIp[2], localIp[3]};
  Serial.print("ipaddress é: ");Serial.println(ipaddress[4]);

What code snippet could I try here?

PS: Look, I'm not asking you for programs. But pasting here an excerpt from among the thousands of functional codes that I know you have in your repertoire.

Thanks

There is no ipaddress[4]. The index only goes from 0-3 which gives you 4 elements. You are reading memory out of bounds of the array

But if I put 3 it gives error

error: too many initializers for 'uint8_t [3] {aka unsigned char [3]}'
uint8_t ipaddress[3] = {localIp[0], localIp[1], localIp[2], localIp[3]};

You're correct. You do need the "4" here:

uint32_t ipaddress[4] = {localIp[0], localIp[1], localIp[2], localIp[3]};

But this is wrong:

Serial.println(ipaddress[4]);

You can't print element #4 of the array because it doesn't exist. Remember arrays start at "0" (like you correctly used in the other statement). So element #4 is the fifth element which does not exist.

But then how do I get the 4 octets in the correct format, inclusive, separated by "."

When I put Serial.println((localIp[3]); it only shows the value of the last octet

and if I put Serial.println((localIp[4]) it gives an error as we have seen.

Try:

	Serial.println(WiFi.localIP());

That's how it's always been, and that's how it works. But as I said at the beginning of the topic I want to send it by serial

remember serial.transfer? I'm in it and I've done it like this, it works too:

String strLocalIp = WiFi.localIP().toString();
const char* dadostx = strLocalIp.c_str();
uint16_t sendSize = 0;
sendSize = myTransfer.txObj(dadostx, sendSize);
myTransfer.sendData(sendSize);

On the other side I have String datatx ​​but it doesn't arrive correctly.

I've tried several settings.

Serial.println() does "send it by serial". You failed to mention Serial Transfer library in your post.

All right, let's wait for someone else willing to help.

You haven't posted any code for the "other side". Nor have you specified what "several settings" you've tried.

For the question of the initial topic none of this is necessary. Those who read it know that I'm asking about how the variable to read the 4 octets of the IP address would be. Just that.

Given that you don't know how to do it, it's odd that you think you know what's necessary.

Strange that you find that strange. But rest assured, go in peace, enjoy the weekend, and leave me here with my doubts waiting for others who want to help.

I can now receive the IP address in its standard format via the serial UART 192.168.XX.YY

It is equal to datatx ​​which is a char[30]

The problem is that I want to use this char outside this void

char dadostx[30];
const char* recebedados;

if (myTransfer.available() > 0)  {    
      
    uint16_t recSize = 0;
    recSize = myTransfer.rxObj(dadostx, recSize);
     if(recSize == 30) {
      recebedados = dadostx;
     }
    Serial.println(recebedados);
   }

But I can not. I tried to make that receiveddata only be equal to datatx ​​when its length is = 30 which would indicate the end of receiving by the serial uart but it doesn't work.

Anywhere else in the code, datatx ​​or received is always empty

I think it makes sense because datatx ​​will be empty very quickly, right after receiving the data, if receiveddata = datatx ​​then it will also be empty.

I tried to make the equality between received = datatx ​​only when resize was equal to 13 (because 192.168.xx.yy contains 13 characters).

But it did not.

Does anybody know how to solve this ? and could you post the code?

let the user enter the ip address with dots
split the entry with strtok.
put each token in the correct index of localIp.

What code snippet could I try here?

start with the Serial Input Basic Tutorial (you should find it) and come back to us when you have a question.

I won't do as you say. I will always ask first, or during my apprenticeship.

Just don't type anything when you see it. It ends up getting in the way instead of helping.

The question I asked in post #15 has no error. I just got it wrong here. I am now able to get the IP address outside of void communication().

That is, you may not even read what I wrote.

But okay, thank you for the minutes you wasted.

Good weekend.

void ipToSafeString(SafeString& p_RefToSS, IPAddress ip) {
  p_RefToSS = ip[0];
  p_RefToSS += ".";
  p_RefToSS += ip[1];
  p_RefToSS += ".";
  p_RefToSS += ip[2];
  p_RefToSS += ".";
  p_RefToSS += ip[3];
}

Finally, someone who has read and understood what I ask for here in this community.

Thank you friend.

I had already solved it, but this post of yours deserves thanks.

I was wanting to fragment and then join the octets of the IP address because I was not able to send it through the serial uart from an esp32 cam to an esp32.

My stupidity, one more.

I did it like this and managed to send it without fragmenting anything:

#include "SerialTransfer.h"
SerialTransfer myTransfer;
String dadostx;

uint16_t sendSize = 0;
       
dadostx = WiFi.localIP().toString();
dadostx.toCharArray(buf, 30);
dadostx.toCharArray(buf, dadostx.length() + 1);
  
sendSize = myTransfer.txObj(buf, sendSize);
myTransfer.sendData(sendSize);