ESP32 - invalid conversion from 'char*' to 'uint8_t'

Greetings All

Thank you in advance

I am a newbee, manage most problems, usually!

Been banging my head against the wall for a few days now, to no success on this one.

This code has been used on the ESP8266 which works great and given me many hours of entertainment.

Tried to migrate to the ESP32, on compilation getting error

" invalid conversion from ‘char*’ to ‘uint8_t’ "

void sendLedData(uint32_t data, uint8_t op_mode)
{
struct led_command send_data;
send_data.opmode = op_mode;
send_data.data = data;
for (int i = 0; i < NUMBER_OF_CLIENTS; i++)
{
IPAddress ip(192,168,4,2 + i);
UDP.beginPacket(ip, 7001);
UDP.write((char*)&send_data, sizeof(struct led_command)); <--------- ???
UDP.endPacket();
}
}

I know

esp32 - UDPWiFi.h is unable to handle UDP.write(( |- not sure why

Char* - is a pointer
&send_data - gets the address
sizeof - gets the size of the array

just unable to visualize or unable to make the connection on how is all relates.

Any help would be great even a * would be helpful.

Cheers :slight_smile:
Nozynoz

void sendLedData(uint32_t data, uint8_t op_mode)
{
struct led_command send_data;
send_data.opmode = op_mode;
send_data.data = data;
for (int i = 0; i < NUMBER_OF_CLIENTS; i++)
{
IPAddress ip(192,168,4,2 + i);
UDP.beginPacket(ip, 7001);

UDP.write((char*)&send_data,sizeof(struct led_command)); <----------------------------------
UDP.endPacket();
}
}

Instead of (char*) try (uint8_t*) if that does not work, look here (pt. 6)..

The error implies that UDP has a “.write(byte)” but not a “.write(char *, int)”. You may need to add a loop to write each byte separately.

   for (int i=0; i< sizeof(struct led_command); i++)
      UDP.write( ((byte *)&send_data)[i] );