0

I am just a newbie, don't know how to solve this issue

void loop()
{
  UdpSend("Test", "192.168.0.240", 4210);
}

void UdpSend(const char* message, uint8_t * ipaddress, int port){
      Serial.println("Send message: ");
      Udp.beginPacket(ipaddress, port);
      Udp.write(message);
      Udp.endPacket();
}

Arduino IDE can't compile.

The error message: invalid conversion from 'const char' to 'uint8_t* {aka unsigned char*}' [-fpermissive]*

Trying to change with this code:

void UdpSend(uint8_t * message, uint8_t * ipaddress, int port){
      Serial.println("Send message: ");
      Udp.beginPacket(ipaddress, port);
      Udp.write(message);
      Udp.endPacket();
}

Also doesn't work, the error message: invalid conversion from 'const char' to 'uint8_t* {aka unsigned char*}' [-fpermissive]*

Please help...

closed as off-topic by per1234, sempaiscuba, gre_gor, Greenonline, MatsK Jan 8 at 14:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – per1234, sempaiscuba, gre_gor, Greenonline, MatsK
If this question can be reworded to fit the rules in the help center, please edit the question.

  • you changed the wrong one ... try changing uint8_t * ipaddress to const char * ipaddress ... then in Udp.beginPacket((uint8_t *) ipaddress, ... – Jaromanda X Dec 23 '18 at 3:38
  • Change the code like this: void UdpSend(const char * message, const char * ipaddress, int port){ Serial.println("Send message: "); Udp.beginPacket((uint8_t *)ipaddress, port); Udp.write(message); Udp.endPacket(); } Error: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' in **Udp.write(message);** – wieb Dec 23 '18 at 3:49
  • void UdpSend(const char * message, const char * ipaddress, int port){ Serial.println("Send message: "); Udp.beginPacket((uint8_t *)ipaddress, port); Udp.write((uint8_t *)message); Udp.endPacket(); } Error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'uint8_t {aka unsigned char}' in Udp.write((uint8_t *)message); – wieb Dec 23 '18 at 4:00
  • Please help.... – wieb Dec 23 '18 at 4:00
  • hmm ... ok, I probably didn't look at the code properly – Jaromanda X Dec 23 '18 at 4:13
2

In ESP32 Arduino package the WiFiUdp.h doesn't pull in all Print class write functions. As consequence the WiFiUdp class doesn't know write(const char *str).

Use Udp.print(message); if message is a zero-terminated char array

or Udp.write(message, size); if message is a byte array

  • Wild guess that it's esp32. Props to you if you're right!!! – Jaromanda X Dec 23 '18 at 9:14
  • Juraj guess is correct, I am using ESP32 – wieb Dec 23 '18 at 9:44
  • Thanks a lot Juraj, your solution works perfectly. – wieb Dec 23 '18 at 9:44
  • @JaromandaX, it was not so wild. there are not so many WiFiUdp.h (OP revealed it in comment) – Juraj Dec 23 '18 at 12:25
  • I'm still impressed – Jaromanda X Dec 23 '18 at 12:26
2

Not sure why you're using uint8_t at all

The Udp.beginPacket function signature is

int WiFiUDP::beginPacket(const char *host, uint16_t port)

No hint of uint8_t there

and .write is either

WiFiUDP::write(uint8_t byte)
WiFiUDP::write(const uint8_t *buffer, size_t size)
WiFiUDP::write(const char *str)
WiFiUDP::write(const char *buffer, size_t size)

So, your other attempt to use write((uint8_t *)) is also wrong

Try this:

void loop()
{
  UdpSend("Test", "192.168.0.240", 4210);
}

void UdpSend(const char* message, const char * ipaddress, int port){
      Serial.println("Send message: ");
      Udp.beginPacket(ipaddress, port);
      Udp.write(message);
      Udp.endPacket();
}
  • Sorry, I am just a newbie, still don't know how and learning to do it in proper way. void UdpSend(const char* message, const char * ipaddress, int port){ Serial.println("Send message: "); Udp.beginPacket(ipaddress, port); Udp.write(message); Udp.endPacket(); } Error: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' in Udp.write(message); – wieb Dec 23 '18 at 4:31
  • which line is the error referring to - the code I posted works – Jaromanda X Dec 23 '18 at 4:35
  • The error referring to Udp.write(message); line. Error: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive] – wieb Dec 23 '18 at 4:38
  • you're doing something else wrong, since Udp.write can take a single const char * argument – Jaromanda X Dec 23 '18 at 4:42
  • Change in Loop function: UdpSend("T", "192.168.0.240", 4210); Also error in Udp.write(message); Error message: invalid conversion from 'const char*' to 'uint8_t {aka unsigned char}' [-fpermissive] – wieb Dec 23 '18 at 4:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.