Skip to content

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

Description

@nirajbhatt7

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions