So you want to publish the value of responss, not the value of 2 variables ?
If so, then take note of what I said in reply #18, ie
A more logical flow would seem be to read the user input and if there is something to publish then go ahead and publish it having tested that the client is connected and to reconnect if it isn’t
I am referring to responss last two values. Attached is the image of Serial Monitor and in this image, you clearly see that responss gives 6 values in which AF, FC, FE, 40 is input and 15, D2 is sensor output. . I want to publish 15, D2 on MQTTBox. Please help me in this regard
Write a function that publishes responss so that you can call it when you need it, then in the loop that does the 6 reads call it when you read the 5th and 6th values
As I have said before, only publishing the value in the reconnect() function is the wrong thing to do
char dataArray[10]; //an array to put data in
//char dataArray1[10];
sprintf(dataArray, "%d", responss - 1); //turn the data into a C string
//sprintf(dataArray1, "%d", responss);
client.publish("Topic", dataArray); //publish the data
publishes the value of responss. Take it out of reconnect() and put it in its own function
reads 6 values from Serial (badly). You want to publish the fifth and sixth values so when when you have read either of them into responss call your new function
If/when you get that working we can talk about making your code more robust
printing x gives 6,5,4,3,2,1. Actually I applied this while loop and gives x=6 because controller gives too many raw values after reading the sensor data. So purpose of int x =6; is to specify the values which I needed
Add this function to your sketch
while (x > 0)
{
responss = Serial.read(); //Serial.print("output =");
Serial.println(responss, HEX);
delay(500);
x--;
}
Call it after you read the fifth and sixth values
Does it print the correct values ?
You have previously established that you know the value of x when you read either of these two values so, when x is one of the two trigger values call the new output() function
It was my mistake. Actually I made random guess because x=6 and x=--; is delimiter and after seeing the Serial mointor I said its 1 and 2. Please help me