# Problem with greengrass discovery on esp32 wrover kit v3

**URL:** <https://forums.freertos.org/t/problem-with-greengrass-discovery-on-esp32-wrover-kit-v3/8957>\
**Category:** AWS\
**Created:** [October 11, 2019, 9:25pm UTC](https://forums.freertos.org/t/problem-with-greengrass-discovery-on-esp32-wrover-kit-v3/8957 "2019-10-11T21:25:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 11, 2019, 9:25pm UTC](https://forums.freertos.org/t/problem-with-greengrass-discovery-on-esp32-wrover-kit-v3/8957/1 "2019-10-11T21:25:47Z")

</div>

**[salkaleidoscope](https://forums.aws.amazon.com/profile.jspa?userID=494442)** wrote on October 11, 2019:

Hi, I have been trying to build a project off of the greengrass discovery demo on a esp32 wrover devkit v3. In my project I plan to use a ring buffer and some peripherals including GPIOs, UART, and SPI. The demo works fine right out of the box, but when I started adding my own setup code for either UART, SPI, or creating a ring buffer, the demo fails. I have tried increasing the stack size of the greengrass demo to something much larger like 80,000 bytes and that still didn’t help. Does anyone know what kind of complication initializing a ringbuffer or UART, SPI, and their respective configuration structs could create? Whats also interesting is even if my code to setup a ringbuffer is AFTER the greengrass discovery demo function it still causes the greengrass discovery to fail. Here are the logs when the failure happens and also the code I added to the function vStartGreenGrassDiscoveryTask():

```auto

I (2678) WIFI: SYSTEM_EVENT_STA_CONNECTED
3 828 [IP-task] vDHCPProcess: offer a000058ip
I (8728) event: sta ip: 10.0.0.88, mask: 255.255.255.0, gw: 10.0.0.1
I (8728) WIFI: SYSTEM_EVENT_STA_GOT_IP
4 838 [IP-task] vDHCPProcess: offer a000058ip
5 839 [iot_thread] [INFO][DEMO][8390] Successfully initialized the demo. Network type for the demo: 1
6 839 [iot_thread] Attempting automated selection of Greengrass device
7 1038 [iot_thread] ERROR: Handshake failed with error code -16
8 1038 [iot_thread] About to close socket.
9 1039 [iot_thread] Socket closed.
10 1039 [iot_thread] Stack high watermark for discovery helper task: 5488.
11 1039 [iot_thread] JSON request could not connect to end point
12 1039 [iot_thread] Auto-connect: Failed to retrieve Greengrass address and certificate.
13 1039 [iot_thread] ----Demo finished----
---------------------------------------------------------------------------------------

RingbufHandle_t ring_buffer;

int vStartGreenGrassDiscoveryTask(bool awsIotMqttMode,
                                  const char *pIdentifier,
                                  void *pNetworkServerInfo,
                                  void *pNetworkCredentialInfo,
                                  const IotNetworkInterface_t *pNetworkInterface)
{
    /* Unused parameters */
    (void)awsIotMqttMode;
    (void)pIdentifier;
    (void)pNetworkServerInfo;
    (void)pNetworkCredentialInfo;
    (void)pNetworkInterface;

    prvDiscoverGreenGrassCore(NULL);

    ring_buffer = xRingbufferCreate(RING_BUFFER_SIZE, RINGBUF_TYPE_ALLOWSPLIT);
    configASSERT(ring_buffer);

    return 0;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 14, 2019, 11:43pm UTC](https://forums.freertos.org/t/problem-with-greengrass-discovery-on-esp32-wrover-kit-v3/8957/2 "2019-10-14T23:43:13Z")

</div>

**[SarenaAtAws](https://forums.aws.amazon.com/profile.jspa?userID=437622)** wrote on October 14, 2019:

Yes you are right because xHostAddressData references directly strings stored in pcJSONFile. Thanks for catching that.

Is there anything you need? Is it sufficient enough that you can lower some memory usage?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 14, 2019, 10:27pm UTC](https://forums.freertos.org/t/problem-with-greengrass-discovery-on-esp32-wrover-kit-v3/8957/3 "2019-10-14T22:27:22Z")

</div>

**[salkaleidoscope](https://forums.aws.amazon.com/profile.jspa?userID=494442)** wrote on October 14, 2019:

Thank you very much for the insight! I had some large statically allocated global variables that I had brought in from other code. Once I made them a lot smaller my code to initialize peripherals and ring buffer worked.

Although in the code you posted, I believe that the vPortFree() needs to be after the call to prvSendMessageToGGC() because I think xHostAddressData is using memory that gets freed otherwise.I was getting errors like this:

```auto

13 1448 [iot_thread] [ERROR][NET][14480] Failed to resolve ��EXX٦�?Į�?.
14 1448 [iot_thread] [ERROR][MQTT][14480] Failed to establish new MQTT connection, error NETWORK ERROR. 15 1448 [iot_thread] ERROR: Could not connect to the Broker.
16 1448 [iot_thread] failed to connect to MQTT Agent
17 1448 [iot_thread] Heap low watermark: 9140. Stack high watermark: 5084.

```

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 15, 2019, 9:28pm UTC](https://forums.freertos.org/t/problem-with-greengrass-discovery-on-esp32-wrover-kit-v3/8957/4 "2019-10-15T21:28:15Z")

</div>

**[salkaleidoscope](https://forums.aws.amazon.com/profile.jspa?userID=494442)** wrote on October 15, 2019:

I have a follow up question, do you need to use the demo routine to use greengrass discovery functions? For example, now the project works if I add my setup code in the vStartGreengrassDiscoveryTask() function but I am trying to just use an initialization function for all my setup and tasks from app\_main() and then connect to the greengrass core. In the initialization function, I first initialize the wifi in station mode with my network credentials and then start greengrass discovery but eventually prvMQTTConnect() fails with the logs below. I already traced the NETWORK\_ERROR back to pdFREERTOS\_ERRNO\_ETIMEDOUT in FreeRTOS\_Connect().

```auto

5 1392 [main] About to close socket.
6 1397 [main] Socket closed.
7 1397 [main] Stack high watermark for discovery helper task: 5324.
8 1397 [main] Greengrass device discovered.
9 1397 [main] Establishing MQTT communication to Greengrass...
10 1398 [main] Connecting to Host Adrress: 10.0.0.50, Port: 8883
I (14319) prvSendMessageToGGC: Free Heap Size: 92284

11 1899 [main] [ERROR][NET][18990] Failed to establish new connection.
12 1899 [main] [ERROR][MQTT][18990] Failed to establish new MQTT connection, error NETWORK ERROR.
13 1899 [main] ERROR: Could not connect to the Broker.
14 1899 [main] failed to connect to MQTT Agent
15 1900 [main] Heap low watermark: 30284. Stack high watermark: 5324.
16 1901 [main] ----Demo finished----

```

So I’m wondering if there is anything in the \_initialize() function in iot\_demo\_freertos.c or the rest of the AWS demo framework that I need to do for the greengrass discovery to succeed. I even changed the task stack size for the main\_task to democonfigGREENGRASS\_DISCOVERY\_TASK\_STACK\_SIZE but that didn’t help.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 21, 2019, 8:54pm UTC](https://forums.freertos.org/t/problem-with-greengrass-discovery-on-esp32-wrover-kit-v3/8957/5 "2019-10-21T20:54:07Z")

</div>

**[SarenaAtAws](https://forums.aws.amazon.com/profile.jspa?userID=437622)** wrote on October 21, 2019:

Hello,

Could you please turn on the FreeRTOS+TCP stack logging in _vendors\espressif\boards\esp32\aws\_demos\config\_files\FreeRTOSIPConfig.h_ by setting ipconfigHAS\_DEBUG\_PRINTF to 1.:

```auto

#define ipconfigHAS_DEBUG_PRINTF 1

```

Then run again to see any issues in the the TCP/IP stack that may cause a timeout.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 25, 2019, 3:17pm UTC](https://forums.freertos.org/t/problem-with-greengrass-discovery-on-esp32-wrover-kit-v3/8957/6 "2019-10-25T15:17:08Z")

</div>

**[salkaleidoscope](https://forums.aws.amazon.com/profile.jspa?userID=494442)** wrote on October 25, 2019:

So it looks like the combination of two things fixed this issue, all I had was this a wifi initialization function before that connected to the AP in station mode with my credentials. But then I added IoTSdk\_Init() before that. At that point I noticed that if I debug and pause the ESP32 when it is stuck in prvMQTTConnect() that it was stuck in function vApplicationStackOverflowHook. So then I increased the task stack size of the app\_main() to the same stack size as democonfigGREENGRASS\_DISCOVERY\_TASK\_STACK\_SIZE and then the ggd demo was able to complete.
