Converting str to const char

So I am currently trying to send a temperature value (a string) over mqtt, but the Arduino IDE keeps complaining about "invalid conversion from ‘int’ to ‘const char*’ [-fpermissive] and I can’t figure out how to convert my str value to a char. Can anybody help me?

This is the last part of my code, I am strugling with (the last part is what is messing me up):

/----------------Read data--------------/

byte temperature = 0;
byte humidity = 0;
if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
return;
}

for (int i = 0; i < 40; i++) {
if (i > 0 && ((i + 1) % 4) == 0) {
}
}

/---------------Send data---------------/
client.publish(outTopic, (int)temperature); [This is where the error orccurs]

}

Does anyone know a easy way to convert a str to a const char?

Where is this error occurring in the program? Please post everything relevant, the program and the errors. Likely you need itoa() but we can't tell.

It’s happening on the last line

The line with: client.publish(outTopic, (int)temperature);

Arthos:
So I am currently trying to send a temperature value (a string)

byte temperature = 0;

Doesn't look like a string to me.

So I am currently trying to send a temperature value (a string) over mqtt, but the Arduino IDE keeps complaining about "invalid conversion from 'int' to 'const char*' [-fpermissive] and I can't figure out how to convert my str value to a char. Can anybody help me?

Your "str value" isn't a str(ing) value but a simple integer.

You can convert the integer to a a C string using the ita function.

Doesn't want a String either. I think it wants a char. In which case itoa(temperature, char_temp, 10) where char_temp is char char_temp[4].

Yeah sorry, meant int not string. My bad

Are you sure 'dht11.read()' takes a pointer to a byte? If it's expecting a pointer to an int, it will write beyond the byte's memory and cause undefined and unexpected behavior.

Hmm, I am still having some trouble figuring out how to use the example (have read the documentation).

I am trying to do:

client.publish(outTopic, itoa(temperature, something, something

After temperature it needs a char* and a new int? How do I set this up, I can find any examples.

client.publish(outTopic, itoa(temperature, something, base ) ) won't work. The return of itoa is not the char.

try

itoa(temperature, something, base );
client.publish(outTopic, something );

char* itoa ( int val, char * s, int radix )

The itoa() function returns the pointer passed as s.

So I am trying to do it, but I am not quite sure what to declare something and base as?

I have tried declaring something(I am calling it temp) a string, a int and a char but neither works. I get a Invalid conversion error for all.

itoa(temperature, temp,base);

You can declare base per the function call (have you tried googling your new instruction or reading DKWatson's reply?) or leave it as 10 as was originally posted.

I'm doubting you are getting the same error. Which error do you have now?

Have you looked up (googling, read or otherwise) the parameters required by client.publish()? I don't know what they are as I don't know what it is related to since only a code snippet was provided.