conversion from 'IPAddress' to 'uint8_t* {aka unsigned char*}' is ambiguous

Hey @all,

in a larger project, there is one problem left.
I like to implement a function to convert an object of the class IPAddress to a array of char.
I use a NodeMCU 1.0 and Arduino 1.8.10.
Following is a little sample sketch demonstrating what i'm trying to do:

#include <ESP8266WiFi.h>

char test_s[16] = "123.234.111.222";
IPAddress test_ip(0, 0, 0, 0);

void stoiIP( const char *in_s, uint8_t *out_ip) {
    char temp_c;
    uint8_t octet_i = 0;
    uint8_t octet_p = 0;;
    for (uint8_t i = 0; i < strlen(in_s); i++ ) {
        temp_c = in_s[i];
        if (temp_c == '.') {
            out_ip[octet_p] = octet_i;
            octet_i = 0;
            octet_p += 1;
        } else {
            octet_i *= 10;
            octet_i += temp_c - '0';
        }
    }
    out_ip[octet_p] = octet_i;
}

void setup() {
    stoiIP(test_s, test_ip);
}

void loop() {
  // nothing to do ;)
}

But this results in the following error:

conversion from 'IPAddress' to 'uint8_t* {aka unsigned char*}' is ambiguous

I have tried some different ways to pass the IPAddress to the function, but all result to different errors.
By now i do it "by hand" writing directly to the octets, witch are accessible like a array of four int, but i have to do it for a view different conversions and there for a universal function would be much better.
This looks like the following and work so far.

void parseAddress (void) {
    char temp_c;
    uint8_t octet_i = 0;
    uint8_t octet_p = 0;;
    for (uint8_t i = 0; i < strlen(addr_s); i++ ) {
        temp_c = addr_s[i];
        if (temp_c == '.') {
            addr_ip[octet_p] = octet_i;
            octet_i = 0;
            octet_p += 1;
        } else {
            octet_i *= 10;
            octet_i += temp_c - '0';
        }
    }
    addr_ip[octet_p] = octet_i;
}

I hope someone can help me to solve this little problem.

Thanks a lot
Lena

if you want to print it, it is printable

Serial.println(ip);

Thanks Juraj!
I know it's a printable class, but i want to use the array in other parts of my program and to say it before someone tell me to do so, i don't want to use the IP as a String objekt - i really need it as an array.

Best regards

Lena

Lena:
Thanks Juraj!
I know it's a printable class, but i want to use the array in other parts of my program and to say it before someone tell me to do so, i don't want to use the IP as a String objekt - i really need it as an array.

Best regards

Lena

array of bytes?

arr[0] = ip[0];
arr[1] = ip[1];
arr[2] = ip[2];
arr[3] = ip[3];

#include "Arduino.h"
#include <ESP8266WiFi.h>

char test_s[16] = "123.234.111.222";
IPAddress test_ip(0, 0, 0, 0);

void setup(){
	Serial.begin(115200);
	delay(1000);
	Serial.println();

	if (test_ip.fromString(test_s)) {
		Serial.print("Success, IP Address = ");
		Serial.println(test_ip);
	} else {
		Serial.println("Failed");
	}
}

void loop(){
}

Hey gfvalvo,
this is not what i'm looking for.
As you can see in the function in my first post, i need to modyfy the objekt IPAddress.
This objekt can behave like an array of char or uint8, im not shure, but i can not pass it's pointer to a function and that's what i'm looking for. No String conversion, no printing and i don't want to use any String objekts - the hole project only uses one large buffer and a view small c-strings for all file handling, display drawing and webpage generation.
So please stay focused to the main problem, passing a pointer to the IPAddress object.
For me it seems like the object has several representations for the data and that's why this way of conversion is ambiguous. But how can i specify witch representation i like to use?

Greetings Lena

void stoiIP( const char *in_s, IPAddress& out_ip) { ?

Juraj:
void stoiIP( const char *in_s, IPAddress& out_ip) { ?

hey, the test sketch compiles without errors - now i'll check it in the real program.
Thanks a lot - stay tuned some minutes.

Looks like i have another bug in my program.
I have tried the test sketch on another board and it seems to work fine - i really have to learn more about poitners, references and dereferencing :frowning:

Thank you very much Juraj!
In my main project i get the error

'IPAddress' has not been declared

wich i don't understand, because they are declared global and used all over the program - strange.
But i think i will figure it out by myself.

Best regards

Lena

Lena:
Looks like i have another bug in my program.
I have tried the test sketch on another board and it seems to work fine - i really have to learn more about poitners, references and dereferencing :frowning:

Thank you very much Juraj!
In my main project i get the errorwich i don't understand, because they are declared global and used all over the program - strange.
But i think i will figure it out by myself.

Best regards

Lena

IPAddress is in core, but it is not included in Arduino.h
the networking libraries include it
so if you use it in a utility h or cpp file, which doesn't include the networking library header, include IPAddress.h

Very interesting!
If i split the test sketch like the main program in several tabs, i get the same error.
the tabs are called sketchname, 01_globals and 02_code.
This has worked all the time, but in this case...?
Any suggestions?

Greetings

Lena

the first is always the sketch with the same name as the project folder

and why not use ip.fromString(test_s);?

Juraj:
the first is always the sketch with the same name as the project folder

and why not use ip.fromString(test_s);?

because test_s is a c-string and not an Arduino String object.
What i don't understand is the fakt, that i can redeclare the IPAddress objekt in the 02_code tab, wich have to throw an redeclaration error, but i get the same error.
I have tried to include IPAddress.h in both tabs without any change.

Did you bother to look at the code I posted? It uses c-string, not String class. 'fromString()' has overloads for both. You just need to expend the effort and look in 'IPAddress.h':

bool fromString(const char *address);

Oh damned, it could be so easy if you know how to do it :confused:

and why not use ip.fromString(test_s);?

I'm shure i have tried it before without succsess, but it works fine - and it works in tabs :slight_smile:

Thank you very much for your patience!

Best regards

Lena