tuanpmt / espduino

ESP8266 network client (mqtt, restful) for Arduino
http://tuanpm.net/post/espduino
MIT License
382 stars 122 forks source link

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

Open nirajbhatt7 opened 8 years ago

nirajbhatt7 commented 8 years ago

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);
}