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:
if(analogRead(analogInPin) < 475)
pana = (52 - (analogRead(analogInPin)/9));
// From: https://randomnerdtutorials.com/esp32-mqtt-publish-subscribe-arduino-ide/
dtostrf(pana, 1, 2, ptempString);
String payload = ("Pright", ptempString);
Button_State = PRESSED;
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
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!
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.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.