# How to fix an invalid user-defined conversion error?

**URL:** <https://forum.arduino.cc/t/how-to-fix-an-invalid-user-defined-conversion-error/635658>\
**Category:** 3rd Party Boards\
**Created:** [February 8, 2020, 9:36pm UTC](https://forum.arduino.cc/t/how-to-fix-an-invalid-user-defined-conversion-error/635658 "2020-02-08T21:36:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cepums2018](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@cepums2018](https://forum.arduino.cc/u/cepums2018)\
**Post date:** [February 8, 2020, 9:36pm UTC](https://forum.arduino.cc/t/how-to-fix-an-invalid-user-defined-conversion-error/635658/1 "2020-02-08T21:36:13Z")

</div>

I am working on setting up simple MQTT communication using ESP32 as a client with Arduino IDE. I am getting an invalid user-defined conversion error in client.subscribe part of the code (line 20), and I don't know what's wrong.

Error message:

```cpp
invalid user-defined conversion from 'onConnectionEstablished()::<lambda(const String&, const String&)>' to 'uint8_t {aka unsigned char}' [-fpermissive]

```

My full code:

```cpp
#include <WiFi.h>
#include <PubSubClient.h>

const char* ssid = "ssid";
const char* password = "password";
const char* mqttServer = "192.168.X.X";
const int mqttPort = 1883;

WiFiClient espClient;
PubSubClient client(espClient);
 
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
}

void onConnectionEstablished() {
  client.subscribe("mytopic/test_one", [](const String & topic, const String & payload) {
    Serial.println(topic + ": " + payload);
  });

  client.publish("mytopic/test_two", "This is a message from the client");  
}

void loop() {
  client.loop();
}

```

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [February 10, 2020, 3:21pm UTC](https://forum.arduino.cc/t/how-to-fix-an-invalid-user-defined-conversion-error/635658/2 "2020-02-10T15:21:51Z")

</div>

Is this code based on something you found somewhere on the Internet? It sort of looks like you are trying to use a hybrid of client.subscribe() and client.setCallback(), but even then you're missing the length parameter in your lambda function.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 5:19pm UTC](https://forum.arduino.cc/t/how-to-fix-an-invalid-user-defined-conversion-error/635658/3 "2021-05-06T17:19:14Z")

</div>

Closed on May 6, 2021, 5:19pm UTC


