MQTT on Wemos ESP8266 sending multiple terms

I am trying to send a topic and an analog input across MQtt, but all it ever sends is the 2nd term(analog input) . I think that there is something wrong with my String Payload statement, but I don't know what.

Here is the code:
String ButtonReading()

….

if(analogRead(analogInPin) < 475)
{
pana = (52 - (analogRead(analogInPin)/9));
// From: https://randomnerdtutorials.com/esp32-mqtt-publish-subscribe-arduino-ide/
char ptempString[8];
dtostrf(pana, 1, 2, ptempString);
String payload = ("Pright", ptempString);
Button_State = PRESSED;
delay(500);
return payload;

returns to:

client.loop();
Serial.println("Read buttons");
String payload = ButtonReading();

At this point I print the payload, but it only ever displays the value from ptempstring and not the Pright as I want.

Can anyone advise?

I don't know the answer to your question but please can you answer one for me and the other mods?

The forum has recently implemented a warning in the event that someone posts code that is not in code tags, as some of yours is not. Did you get the warning? Did you choose to ignore it? What actually happened?

Thanks,

1 Like

The code snippet does not do much. Post the whole code.

Do you mean String payload = ("Pright" + String( ptempString ) );
The behaviour of the C++ comma ',' operator almost defies description.

I got the warning, and used the code tags for the main bit of the code, but not the second bit. I'm learning!

1 Like

Thank You. That does it. I added a space in the quotes for "Pright " to seperate the two terms in the received string. Much appreciated.

Over now to the MQTT subscriber on teh Raspberry Pi and back to Python.