I have an ESP32-CAM with a code based on the CameraWebServer example and a PCB with a code based on Arduino.
I'm trying to send the IP Address that the ESP32 is connected to, to my PCB through I2C.
I obtain the IP address with WiFi.localIP().
I really don't know how to do it.
Yes, so if I print to serial "WiFi.localIP()" I will see for example "192.168.1.27" What I want is to send this to my other board (ideally in that same format).
If you look at the IPAddress class, you can see it's implemented as an array of 4 uint8_t values (or the corresponding 32 bit value):
class IPAddress : public Printable {
private:
union {
uint8_t bytes[4]; // IPv4 address
uint32_t dword;
} _address;
These correspond to the 4 octets in your address '192.168.1.27'. You can access the individual octets using the [] operator.
So you have two options really. If you literally want to send a string to the other board, I think you'd need to format the address yourself. Possibly the libc inet_ntop function might be of use, unless IPAddress itself offers a means of rendering to a string or char array (it has a printTo method but I'm not sure whether that's easily useful for this or not).
Alternatively you could send the individual octets.
It really boils down to what you want the other board to do with the address. If you want to use it as an IP address for communication the octet variant is probably more useful since it avoids the other board having to parse the address all over again.
So to explain a bit, the esp32 connects to an IP that can change as it will connect to different WIFIs, I want the IP to be sent to my board and this will be sent with BLE to an app that will check the once the IP (ideally every time the device is connected).
I know more or less how to send data using I2C, but I'm struggling to send the IP.
For example, I have 192 168 1 27. Every time I try to send the IP as Byte,int ,uint32_t... I receive 192 255 255 255. I think the problem is the way I receive the data:
Wire.requestFrom(106, 4); // request 4 bytes from slave device #106
//int Buffer[4];
while (Wire.available()) {
uint8_t c = Wire.read();
Serial.println(c);
}
Additionally, I think there should be some brokering between the two boards (one should be master, one slave) -- I'm assuming you have that all set up OK?