Search code examples
google-cloud-platformiotgoogle-cloud-pubsubesp32

ESP32 to GCP IOT Core connection failing


I want my data to move from iot device (esp32) to gcp iot core to cloud pub/sub. The issue is when I pull a message from pub/sub subscription the message body field displays "device-esp32-connected" rather than the actual json message that esp32 had sent.

My json file's structure is like:

{
    "Key1":"Value1",
    "Key2":"Value1",
    "Key3":"Value1",
    "List1": [
        {
            "key1":"value1",
            "key2":"value2",
            "key3":"value3"
        },
        {
            "key1":"value1",
            "key2":"value2",
            "key3":"value3"
        }
    ]
}

My actual json has a lot more fields in the "list1" list. It works if I decrease the number of fields but I cannot decrease the number of fields for my project.


Solution

  • This error occurred due to the embedded code in esp32. The memory size I was setting for the message was less than the actual size of the message. Once I increased the allocated size the process started to work properly. I changed this:

    mqttClient = new MQTTClient(512);
    

    to

    mqttClient = new MQTTClient(6000);