Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

[General] <Green Grass Discovery Demo> #3453

Open
jitendrazala opened this issue Feb 12, 2022 · 8 comments
Open

[General] <Green Grass Discovery Demo> #3453

jitendrazala opened this issue Feb 12, 2022 · 8 comments

Comments

@jitendrazala
Copy link

Hello Folks,

I have been trying to get green grass discovery demo working on ESP32-WROVER hardware but couldn't not get any resource of green grass device v2.

Hardwares Used:

  1. Raspberry Pi3 [RPi]
  2. ESP32-WROVER

Steps I followed to setup GGC on RPi:

  1. Setup Raspberry Pi with Raspbian buster and installed Java
  2. Created a user on AWS IAM console with policies i.e.

IAMFullAccess
AmazonS3FullAccess
AWSGreengrassFullAccess
AWSIoTFullAccess

  1. Downloaded AWS Secret Key and AWS Access Key of user
  2. Exported AWS Secret Key and AWS Access Key in RPi
  3. Setup green grass core device in RPi [https://docs.aws.amazon.com/greengrass/v2/developerguide/getting-started.html]
  4. Downloaded green grass installer, run it and successfully installed Nucleus as system service in RPi
  5. Checked and verified by command : sudo /greengrass/v2/bin/greengrass-cli component list
    and it was showing aws.greengrass.cli component's status as Running
  6. Then added a new component for publish and subscribe to AWS IoT core by creating recipes and artifacts. Component was deployed and successfully running. I could publish and subscribe to AWS IoT core.

Steps I followed to setup GGC Discovery Demo on ESP32:

  1. Setup python and python-pip on windows PC
  2. Downloaded AWS CLI and installed on windows PC
  3. Configured AWS user configuration using command : aws configure and configured AWS Access Key, AWS Secret Key, Region and default data format [json].
  4. Cloned amazon-freertos
    git clone https://github.com/aws/amazon-freertos.git --recurse-submodules
    cd amazon-freertos
    git fetch --all –tags
  5. Installed ESP-IDF dependencies : amazon-freertos/vendors/espressif/esp-idf & run:
    install.bat
  6. Setup ESP-IDF environment: amazon-freertos/vendors/espressif/esp-idf & run:
    export.bat
  7. Setup AWS configuration i.e. Things name, Wi-Fi SSID and Password in configure.json from amazon-freertos/tools/aws_config_quick_start path
  8. Run : python SetupAWS.py setup to setup thing and AWS credentials
  9. Run: python SetupAWS.py update_creds to update AWS credentials
  10. Replaced CONFIG_CORE_MQTT_MUTUAL_AUTH_DEMO_ENABLED with the CONFIG_GREENGRASS_DISCOVERY_DEMO_ENABLED in vendors/espressif/boards/esp32/aws_demos/config_files/aws_demo_config.h
  11. In amazon-freertos root directory: built demo using below command
    **idf.py -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 build**
    12 .Flashed and monitored firmware using idf.py -p COM3 flash monitor

But not getting green grass device information 😕 Don't know what was the mistake !
Attaching logs of ESP32 monitoring.

Can anyone point me about the possible issue/s and probably solution !?

Thanks.
Jitendra

Hard resetting via RTS pin...
Executing action: monitor
Running idf_monitor in directory c:\amazon-freertos
Executing "C:\Users\Jitendra\.espressif\python_env\idf4.2_py3.8_env\Scripts\python.exe C:\amazon-freertos\vendors\espressif\esp-idf\tools/idf_monitor.py -p COM5 -b 115200 --toolchain-prefix xtensa-esp32-elf- c:\amazon-freertos\build\aws_demos -m 'C:\Users\Jitendra\.espressif\python_env\idf4.2_py3.8_env\Scripts\python.exe' 'C:\amazon-freertos\vendors\espressif\esp-idf\tools\idf.py' '-p' 'COM5'"...
--- WARNING: GDB cannot open serial ports accessed as COMx
--- Using \\.\COM5 instead...
C:\amazon-freertos\vendors\espressif\esp-idf\tools/idf_monitor.py:474: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  if StrictVersion(serial.VERSION) < StrictVersion('3.3.0'):
--- idf_monitor on \\.\COM5 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7488
load:0x40078000,len:13724
load:0x40080400,len:4584
0x40080400: _init at ??:?

entry 0x400806f4
I (26) boot: ESP-IDF v4.2.2-273-g9e3992ead 2nd stage bootloader
I (27) boot: compile time 17:47:09
I (27) boot: chip revision: 1
I (31) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (38) boot.esp32: SPI Speed      : 40MHz
I (42) boot.esp32: SPI Mode       : DIO
I (47) boot.esp32: SPI Flash Size : 4MB
I (51) boot: Enabling RNG early entropy source...
I (57) boot: Partition Table:
I (60) boot: ## Label            Usage          Type ST Offset   Length
I (68) boot:  0 nvs              WiFi data        01 02 00010000 00006000
I (75) boot:  1 otadata          OTA data         01 00 00016000 00002000
I (83) boot:  2 phy_init         RF data          01 01 00018000 00001000
I (90) boot:  3 ota_0            OTA app          00 10 00020000 00177000
I (98) boot:  4 ota_1            OTA app          00 11 001a0000 00177000
I (105) boot:  5 storage          WiFi data        01 02 00317000 00010000
I (113) boot: End of partition table
I (117) boot: ota rollback check done
I (121) boot_comm: chip revision: 1, min. application chip revision: 0
I (128) esp_image: segment 0: paddr=0x00020020 vaddr=0x3f400020 size=0x28528 (165160) map
I (200) esp_image: segment 1: paddr=0x00048550 vaddr=0x3ffbdb60 size=0x03994 ( 14740) load
I (207) esp_image: segment 2: paddr=0x0004beec vaddr=0x40080000 size=0x0412c ( 16684) load
0x40080000: _WindowOverflow4 at c:\amazon-freertos\build/../freertos_kernel/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vectors.S:1860

I (214) esp_image: segment 3: paddr=0x00050020 vaddr=0x400d0020 size=0xa8cf0 (691440) map
0x400d0020: _stext at ??:?

I (479) esp_image: segment 4: paddr=0x000f8d18 vaddr=0x4008412c size=0x18b70 (101232) load
0x4008412c: coex_core_release at ??:?

I (539) boot: Loaded app from partition at offset 0x20000
I (539) boot: Disabling RNG early entropy source...
I (540) cpu_start: Pro cpu up.
I (543) cpu_start: Application information:
I (548) cpu_start: Project name:     amazon-freertos
I (554) cpu_start: App version:      1
I (558) cpu_start: Compile time:     Feb  3 2022 17:46:30
I (564) cpu_start: ELF file SHA256:  79aa8361c3c5bbb5...
I (570) cpu_start: ESP-IDF:          v4.2.2-273-g9e3992ead
I (576) cpu_start: Single core mode
I (581) heap_init: Initializing. RAM available for dynamic allocation:
I (588) heap_init: At 3FF80000 len 00002000 (8 KiB): RTCRAM
I (594) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (600) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (606) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (612) heap_init: At 3FFCAD38 len 000152C8 (84 KiB): DRAM
I (619) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM
I (625) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (631) heap_init: At 4009CC9C len 00003364 (12 KiB): IRAM
I (637) cpu_start: Pro cpu start user code
I (655) spi_flash: detected chip: generic
I (656) spi_flash: flash io0 0 [main] Initializing lwIP TCP stack

I (676) PKCS11: Initializing NVS partition: "storage"
E (686) PKCS11: failed nvs get file size 4354 0
1 9 [main] Write certificate...

2 22 [iot_thread] [INFO ][DEMO][220] ---------STARTING DEMO---------


I (886) BTDM_INIT: BT controller compile version [bfbbe1e]
3 22 [iot_thread] [INFO ][INIT][220] SDK successfully initialized.

I (896) system_api: Base MAC address is not set
I (896) system_api: read default base MAC address from EFUSE
I (906) phy_init: phy_version 4660,0162888,Dec 23 2020
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=187 adv_itvl_max=375
I (1306) wifi:wifi driver task: 3ffd9374, prio:23, stack:6656, core=0
I (1306) wifi:wifi firmware version: df5b09d
I (1306) wifi:wifi certification version: v7.0
I (1306) wifi:config NVS flash: enabled
I (1306) wifi:config nano formating: disabled
I (1316) wifi:Init data frame dynamic rx buffer num: 32
I (1316) wifi:Init management frame dynamic rx buffer num: 32
I (1326) wifi:Init management short buffer num: 32
I (1326) wifi:Init dynamic tx buffer num: 32
I (1336) wifi:Init static rx buffer size: 1600
I (1336) wifi:Init static rx buffer num: 10
I (1336) wifi:Init dynamic rx buffer num: 32
I (1346) wifi_init: rx ba win: 6
I (1346) wifi_init: tcpip mbox: 32
I (1356) wifi_init: udp mbox: 6
I (1356) wifi_init: tcp mbox: 6
I (1356) wifi_init: tcp tx win: 5744
I (1366) wifi_init: tcp rx win: 5744
I (1366) wifi_init: tcp mss: 1440
I (1376) wifi_init: WiFi IRAM OP enabled
I (1376) wifi_init: WiFi RX IRAM OP enabled
I (1386) phy_init: phy_version 4660,0162888,Dec 23 2020
I (1396) wifi:mode : sta (24:0a:c4:44:92:8c)
I (1396) WIFI: WIFI_EVENT_STA_START
I (2656) wifi:new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1
I (3136) wifi:state: init -> auth (b0)
I (3156) wifi:state: auth -> assoc (0)
I (3156) wifi:state: assoc -> run (10)
I (3206) wifi:connected with Jitendra, aid = 4, channel 6, BW20, bssid = 86:4e:3e:ab:db:52
I (3206) wifi:security: WPA2-PSK, phy: bgn, rssi: -41
I (3206) wifi:pm start, type: 1

I (3216) WIFI: WIFI_EVENT_STA_CONNECTED
I (3266) wifi:AP's beacon interval = 102400 us, DTIM period = 2
I (4166) esp_netif_handlers: sta ip: 192.168.136.84, mask: 255.255.255.0, gw: 192.168.136.65
I (4166) WIFI: SYSTEM_EVENT_STA_GOT_IP
4 350 [sys_evt] [INFO ][DEMO][3500] Connected to WiFi access point, ip address: 255.255.255.0.

5 350 [iot_thread] [INFO ][DEMO][3500] Successfully initialized the demo. Network type for the demo: 1

6 350 [iot_thread] [aws_greengrass_discovery_demo.c:533] [INFO] [Greengrass_Discovery_Demo] Attempting automated selection of Greengrass device


E (4886) PKCS11: failed nvs get file size 4354 0
7 773 [iot_thread] JSON file retrieval completed

8 773 [iot_thread] About to close socket.

9 773 [iot_thread] Socket closed.

10 773 [iot_thread] Stack high watermark for discovery helper task: 7912.

11 773 [iot_thread] JSON parsing: Couldn't find certificate

12 773 [iot_thread] [aws_greengrass_discovery_demo.c:606] [ERROR] [Greengrass_Discovery_Demo] Auto-connect: Failed to retrieve Greengrass address and certificate.

13 773 [iot_thread] [INFO ][DEMO][7730] memory_metrics::freertos_heap::before::bytes::215244

14 773 [iot_thread] [INFO ][DEMO][7730] memory_metrics::freertos_heap::after::bytes::81876

15 774 [iot_thread] [INFO ][DEMO][7730] memory_metrics::demo_task_stack::before::bytes::11992

16 774 [iot_thread] [INFO ][DEMO][7740] memory_metrics::demo_task_stack::after::bytes::7112

I (9406) wifi:state: run -> init (0)
I (9406) wifi:pm stop, total sleep time: 3744775 us / 6192357 us

I (9406) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (9406) WIFI: WIFI_EVENT_STA_DISCONNECTED: 63
17 874 [iot_thread] [ERROR][DEMO][8740] Error running demo.

E (9416) wifi_init: Wi-Fi not stop
I (9426) WIFI: WIFI_EVENT_STA_STOP
I (9426) wifi:flush txq
I (9426) wifi:stop sw txq
I (9436) wifi:lmac stop hw txq
I (9436) wifi:Deinit lldesc rx mblock:10
GAP procedure initiated: stop advertising.
GAP procedure initiated: stop advertising.
18 879 [iot_thread] [INFO ][INIT][8790] SDK cleanup done.

19 879 [iot_thread] [INFO ][DEMO][8790] -------DEMO FINISHED-------
@archigup
Copy link
Member

Hi, we're looking into this issue and will get back to you, thanks!

@jitendrazala
Copy link
Author

That would be really helpful.
Thanks.

@archigup
Copy link
Member

archigup commented Feb 16, 2022

Hi, did you enable cloud discovery for the Greengrass core? If not, see Connect V1 Greengrass Devices and Interact with local IoT devices.

Let me know if this does not solve your issue.

@jitendrazala
Copy link
Author

Hi,

I already enabled cloud discovery for the greengrass core.
Though I did some debugging and came to know that device getting greengrass core information but somehow it was not able to connect to that.
It always failed in GGD_SecureConnect_Connect function in aws_helper_secure_connect.c file specifically in SOCKETS_Connect in GGD_SecureConnect_Connect function.

`BaseType_t GGD_SecureConnect_Connect( const GGD_HostAddressData_t * pxHostAddressData,
                                      Socket_t * pxSocket,
                                      uint32_t ulReceiveTimeOut,
                                      uint32_t ulSendTimeOut )
{
    const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( ulReceiveTimeOut );
    const TickType_t xSendTimeOut = pdMS_TO_TICKS( ulSendTimeOut );
    SocketsSockaddr_t xServerAddress;
    size_t xURLLength;
    BaseType_t xIsIPAddress;
    BaseType_t xStatus;
    int32_t returnCode;

    configASSERT( pxHostAddressData != NULL );
    configASSERT( pxSocket != NULL );

    /* Calculate the length of the supplied URL. */
    xURLLength = strlen( pxHostAddressData->pcHostAddress );

    /* Ensure that the length of the specified URL is
     * within the permitted limits. */
    if( xURLLength <= ( size_t ) securesocketsMAX_DNS_NAME_LENGTH )
    {
        printf("1111");
        /* Create the socket. */
        *pxSocket = SOCKETS_Socket( SOCKETS_AF_INET,
                                    SOCKETS_SOCK_STREAM,
                                    SOCKETS_IPPROTO_TCP );

        if( *pxSocket == SOCKETS_INVALID_SOCKET )
        {
            xStatus = pdFAIL;
            printf("2222");
        }
        else
        {
            xStatus = pdPASS;
            printf("3333");
        }

        if( xStatus == pdPASS )
        {
            printf("4444");    
            if( prvIsIPaddress( pxHostAddressData->pcHostAddress ) == ( uint32_t ) 0 )
            {
                xIsIPAddress = pdFALSE;
                printf("5555");
            }
            else
            {
                xIsIPAddress = pdTRUE;
                printf("6666");
            }

            xServerAddress.ucLength = sizeof( SocketsSockaddr_t );
            xServerAddress.usPort = SOCKETS_htons( pxHostAddressData->usPort );
            xServerAddress.ulAddress =
                SOCKETS_GetHostByName( pxHostAddressData->pcHostAddress );

            if( xServerAddress.ulAddress == 0u )
            {
                ggdconfigPRINT( "ERROR! Failed to resolve host address: ServerHost=%.*s",
                                xURLLength, pxHostAddressData->pcHostAddress );
            }

            xServerAddress.ucSocketDomain = SOCKETS_AF_INET;

            /* Set send timeout for the socket. */
            ( void ) SOCKETS_SetSockOpt( *pxSocket,
                                         0,
                                         SOCKETS_SO_SNDTIMEO,
                                         &xSendTimeOut,
                                         sizeof( xSendTimeOut ) );

            /* Set receive timeout for the socket. */
            ( void ) SOCKETS_SetSockOpt( *pxSocket,
                                         0,
                                         SOCKETS_SO_RCVTIMEO,
                                         &xReceiveTimeOut,
                                         sizeof( xReceiveTimeOut ) );

            /* Set secure connection. */
            ( void ) SOCKETS_SetSockOpt( *pxSocket,
                                         0,
                                         SOCKETS_SO_REQUIRE_TLS,
                                         NULL,
                                         ( size_t ) 0 );

            if( pxHostAddressData->pcCertificate != NULL )
            {
                /* Override TLS trust store with server certificate. */
                returnCode = SOCKETS_SetSockOpt( *pxSocket,
                                                 0,
                                                 SOCKETS_SO_TRUSTED_SERVER_CERTIFICATE,
                                                 pxHostAddressData->pcCertificate,
                                                 ( size_t ) pxHostAddressData->ulCertificateSize );

                if( returnCode != SOCKETS_ERROR_NONE )
                {
                    ggdconfigPRINT( "ERROR! Failure in SOCKET_SetSockOpt call for overriding TLS trust store: "
                                    "ReturnCode=%d\r\n", returnCode );
                    xStatus = pdFAIL;
                    printf("7777");
                }
            }

            if( xIsIPAddress == pdFALSE )
            {
                printf("8888");
                /* Enable use of SNI in TLS. */
                returnCode = SOCKETS_SetSockOpt( *pxSocket,
                                                 0,
                                                 SOCKETS_SO_SERVER_NAME_INDICATION,
                                                 pxHostAddressData->pcHostAddress,
                                                 ( size_t ) 1 + xURLLength );

                if( returnCode != SOCKETS_ERROR_NONE )
                {
                    ggdconfigPRINT( "ERROR! Failure in SOCKET_SetSockOpt call for enabling TLS SNI: "
                                    "ServerHost=%.*s, ReturnCode=%d\r\n",
                                    xURLLength, pxHostAddressData->pcHostAddress, returnCode );
                    xStatus = pdFAIL;
                    printf("9999");
                }
            }

      
            /* Establish the TCP connection. */
            if( pdPASS == xStatus )
            {
                printf("1010");
                returnCode = SOCKETS_Connect( *pxSocket,
                                              &xServerAddress,
                                              ( uint32_t ) sizeof( xServerAddress ) );

                 /***It always failed here***/
                if( returnCode != SOCKETS_ERROR_NONE )
                {
                    ggdconfigPRINT( "ERROR! SOCKETS_Connect call failed: ServerAddress=%lu, Port=%u, ReturnCode=%d\r\n",
                                    xServerAddress.ulAddress, xServerAddress.usPort, returnCode );
                    GGD_SecureConnect_Disconnect( pxSocket );
                    xStatus = pdFAIL;
                }
            }
        }
    }
    else
    {
        ggdconfigPRINT( "Malformed URL\r\n" );
        xStatus = pdFAIL;
    }

    return xStatus;
}`

@archigup
Copy link
Member

archigup commented Feb 18, 2022

Hmm, from the logs posted in the initial post, it looks like its getting past that and failing in GGD_GetIPandCertificateFromJSON after not finding the certificate key in prvGGDGetCertificate. Is that still the case? Would you be able to provide the JSON file retrieved by the application if so?

@jitendrazala
Copy link
Author

Yes. Sure.
Please find attachment.
response

@archigup
Copy link
Member

Looking at that screenshot, the SOCKETS_Connect call is getting the correct ip/port from the json document, so the issue is likely with the Greengrass certificate. What is the error if the section with the /* Override TLS trust store with server certificate. */ comment is commented out? If that is done and the SOCKETS_Connect return code is one of the TLS ones then we can narrow the issue down to the certificate.

@aggarg
Copy link
Member

aggarg commented Mar 14, 2022

Are you still facing this issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants