knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.82k stars 1.47k forks source link

Error when publish mqtt #921

Open mshaz opened 2 years ago

mshaz commented 2 years ago

Hi I m a newbie in coding, I have an error when trying to publish mqtt. Please help.

The initial serial code without client.publish works fine and the output is like below;

0 1 1 1 0 0 0 0 0

My code:

void loop() { byte n = SUART.available(); if (n != 0) { char x = SUART.read(); Serial.print(x); client.publish(mqtt_topic,x);

}

}

error message:
exit status 1 invalid conversion from 'char' to 'const char*' [-fpermissive]

Tiepolino commented 2 years ago

Hi mshaz,

You can 'typecast' your char into a const char* like this:

client.publish(mqtt_topic,x); ->> client.publish(mqtt_topic, (const char*) x);

Hope this helps you.

Tiepolino