TJirsch wrote on September 23, 2019:
Hi,
I am trying to move code connecting to a thing shadow on a greengrass host from the old “AGENT” Apis to the V4 C SDK Ones under the current master branch.
I have a working Greengrass Host (V1.93) and Discovery, Thing and IoT Setup.
I have validated:
- The Greengrass Demo code (old style APIs) is working with the GG host and the Things certificates.
- My Code connects to the cloud IoT Endpoint
- The Discovery finds the correct Greengrass Connection info (192.168.86.36:8883)
- My old code uses the same APIs as the Greengrass demo and also works
When calling the function below with uConnectToGreenGrass = true (Discovery done ok with correct info in pxHostAdrData) I get a Network Error from IotMqtt_Connect. The error occurs somewhere in FreeRTOS_connect in FreeRTOS_Sockets.c.
I think I am setting up everything ok, could you provide some help where to look or provide a greengrass demo that uses the current APIs ?
void vShadowConnect(GGD_HostAddressData_t *pxHostAdrData, uint8_t uConnectToGreenGrass)
{
uint8_t nRetries = 0;
IotMqttError_t xReturn = IOT_MQTT_STATUS_PENDING;
IotMqttNetworkInfo_t networkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER;
IotMqttConnectInfo_t connectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
IotNetworkServerInfo_t iotSrvInfo;
IotNetworkCredentials_t iotCreds = AWS_IOT_NETWORK_CREDENTIALS_AFR_INITIALIZER;
iotCreds.pClientCert = keyCLIENT_CERTIFICATE_PEM;
iotCreds.clientCertSize = sizeof(keyCLIENT_CERTIFICATE_PEM);
iotCreds.pPrivateKey = keyCLIENT_PRIVATE_KEY_PEM;
iotCreds.privateKeySize = sizeof(keyCLIENT_PRIVATE_KEY_PEM);
if(uConnectToGreenGrass)
{
iotSrvInfo.pHostName = pxHostAdrData->pcHostAddress;
iotSrvInfo.port = pxHostAdrData->usPort;
iotCreds.pRootCa = pxHostAdrData->pcCertificate;
iotCreds.rootCaSize = strlen(pxHostAdrData->pcCertificate);
ESP_LOGI(TAG, "%s rootca cert
%s",__FUNCTION__,iotCreds.pRootCa );
}
else
{
iotSrvInfo.pHostName = clientcredentialMQTT_BROKER_ENDPOINT;
iotSrvInfo.port = clientcredentialMQTT_BROKER_PORT;
iotCreds.pRootCa = NULL;
iotCreds.rootCaSize = 0;
}
ESP_LOGI(TAG, "%s Shadow connecting to %s endpoint %s:%d",__FUNCTION__,
(uConnectToGreenGrass ? "Greengrass":"IoT Cloud"),
iotSrvInfo.pHostName, iotSrvInfo.port);
ESP_LOGI(TAG, "%s client cert
%s",__FUNCTION__,iotCreds.pClientCert);
networkInfo.createNetworkConnection = true;
networkInfo.u.setup.pNetworkServerInfo = &iotSrvInfo;
networkInfo.u.setup.pNetworkCredentialInfo = &iotCreds;
networkInfo.pNetworkInterface = IOT_NETWORK_INTERFACE_AFR;
connectInfo.awsIotMqttMode = true;
connectInfo.cleanSession = true;
connectInfo.keepAliveSeconds = 50;
connectInfo.pClientIdentifier = clientcredentialIOT_THING_NAME;
connectInfo.clientIdentifierLength = ( uint16_t ) strlen(clientcredentialIOT_THING_NAME);
xReturn = IotMqtt_Connect( &networkInfo,&connectInfo,20000,&xMQTTShadow);
Edited by: TJirsch on Sep 23, 2019 1:23 AM
Discovery was successfull, 192.168.86.36:8883 is the greengrass host.
What stands out is the eCONNECT_SYN: flags 0012 expected, not 0010 line.
Any hints ?
I turned DEBUG Logs on in iot_config.h and FreeRTOSIPConfig.h this gets me the following:
FreeRTOS_connect: 24324 to c0a85624ip:8883
Socket 24324 -> c0a85624ip:8883 State eCLOSED->eCONNECT_SYN
prvSocketSetMSS: 1420 bytes for c0a85624ip:8883
prvWinScaleFactor: uxRxWinSize 1 MSS 1420 Factor 0
Connect[c0a85624ip:8883]: next timeout 1: 3000 ms
eCONNECT_SYN: flags 0012 expected, not 0010
Socket 24324 -> c0a85624ip:8883 State eCONNECT_SYN->eCLOSE_WAIT
[ERROR][NET][25870] Failed to establish new connection.
FreeRTOS_closesocket[24324 to c0a85624ip:8883]: buffers 60 socks 0
[ERROR][MQTT][25870] Failed to establish new MQTT connection, error NETWORK ERROR.
I (26083) [SHADOW ]: vShadowConnect espLogger01 shadow MQTT connect to 192.168.86.36:8883 try#1 NETWORK ERROR
Edited by: TJirsch on Sep 23, 2019 3:20 AM
Edited by: TJirsch on Sep 23, 2019 3:25 AM