peterm7
November 26, 2021, 11:51am
1
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?
As many of you are aware, use of code blocks when posting code or tool output to the forum is very important. The reason is that random parts of the text are often recognized by the forum software as markup, resulting in it being rendered oddly or incorrectly.
It is common for new forum users to miss this requirement, which results in helpers spending time on boring administrative efforts instead of the sharing of knowledge we come here for. Previous efforts to mitigate the problem through docu…
Thanks,
1 Like
The code snippet does not do much. Post the whole code.
6v6gt
November 26, 2021, 4:49pm
4
Do you mean String payload = ("Pright" + String( ptempString ) );
The behaviour of the C++ comma ',' operator almost defies description.
peterm7
November 27, 2021, 9:08am
5
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
peterm7
November 27, 2021, 9:28am
6
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.
system
Closed
May 26, 2022, 9:29am
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.