espduino icon indicating copy to clipboard operation
espduino copied to clipboard

mqtt.publish from the call back void mqttData(void* response) gives unpredictable result

Open nirajbhatt7 opened this issue 9 years ago • 0 comments

Usually the following code hangs. Has anyone done this successfully? it is a stripped out code so there might be some mistake but presenting here for understanding.

void mqttData(void* response)
{
    RESPONSE res(response);

    String topic = res.popString(); 
    String data = res.popString();
    //Serial.println(topic + "::" + data);
    parseData(data);

}   


void parseData(String payload) {
    //Parse the payload and prepare a response



    String topicString = "/ResponseTopic";
    char topic[topicString.length() + 1];
    topicString.toCharArray(topic, topicString.length() + 1);

    char char_array[payload.length() + 1];
    payload.toCharArray(char_array, payload.length() + 1);

    const char * c = topicString.c_str();
    mqtt.publish(c, char_array);
}

nirajbhatt7 avatar Feb 13 '16 22:02 nirajbhatt7