I actualy can use Serial.println(Ethernet.localIP());
It works just fine, but when i try to use twitter.post(Ethernet.localIP()); I can't because of uint32_t to const char* conversion.
How could I convert this information from 'uint32_t' to 'const char*' value I could use in twitter.post() function?
You can't cast a non-constant variable to a constant, for -starts-.
is wrong. Sorry. You can but it'd have to be like ((const char*) myStringArray)
So you need to convert the binary value into a char array instead of printing.
This is from the AVR_Libc site (Arduino Reference page near bottom right links to AVR_Libc), it's the page on the General Utilities library. The function to use there is strtoul().
Ethernet.localIP() doesn't return an array of uint8_t values, it returns a single uint32_t value. So the first thing to do is store that in a variable:
uint32_t ipAddress = Ethernet.localIP();
You should then create a uint8_t pointer and have that point to the first byte in ipAddress:
uint8_t *ipPtr = (uint8_t*) &ipAddress;
You can then access the 4 values needed using ipPtr[0], ipPtr[1], ipPtr[2], and ipPtr[3].
However depending on how the ip is returned, you may have an issue with endian-ness in that the IP could come out with the bytes reversed. In which case you would need this:
union IPAddressConverter {
uint32_t ipInteger;
uint8_t ipArray[4];
};
void setup()
{
// This code will only run once, after each powerup or reset of board
IPAddressConverter ipAddress;
ipAddress.ipInteger = Ethernet.localIP();
char buf[16];
sprintf(buf, "%d.%d.%d.%d", ipAddress.ipArray[0], ipAddress.ipArray[1], ipAddress.ipArray[2], ipAddress.ipArray[3]);
//twitter.post(buf);
}
void loop()
{
// This code loops consecutively
}
Oh, I should also mention, you don't need the \0 at the end of sprintf(), it is included for you as part of the " "