aws / amazon-freertos

DEPRECATED - See README.md
https://aws.amazon.com/freertos/
MIT License
2.54k stars 1.1k forks source link

Problem with generating connect packet using "_IotMqtt_SerializeConnect" #1870

Closed Abz23 closed 4 years ago

Abz23 commented 4 years ago

Hi, I am currently using the NRF52840 DK and trying to connect, Pub and Sub to AWS iot. I am using an external modem with an AT interface. The modem has 4G LTE capabilities with an IP stack. I have successfully developed an AT driver which can communicate with the modem. I can send an AT command to open a transparent connection with AWS broker. However, I am now struggling to generate a connect packet using "_IotMqtt_SerializeConnect" function. My aim is to generate a connect packet and as then send it using AT command to connect to AWS.

I have made sure to include the cA PEM broker certificate and the public and private client certificates as I am trying to establish a secure SSL connection with the broker. I also included the broker endpoint and port number and several other connection profile details as shown below in my code.
Currently I am getting a hard system error with id = 0x00004002. Below is a snippet of my code. I relied heavily on FreeRtos example code.

Many thanks in advance

CODE :

static const struct IotNetworkServerInfo xMQTTBrokerInfo = { .pHostName = clientcredentialMQTT_BROKER_ENDPOINT, .port = clientcredentialMQTT_BROKER_PORT };

static struct IotNetworkCredentials xNetworkSecurityCredentials = { / Optional TLS extensions. For this demo, they are disabled. / .pAlpnProtos = NULL, .maxFragmentLength = 0,

/ SNI is enabled by default. / .disableSni = false,

/* Provide the certificate for validating the server. Only required for

while(1){ printf("DISCONNEECTED"); }

} static IotMqttNetworkInfo_t xNetworkInfo = { /* No connection to the MQTT broker has been established yet and we want to

define mqttexampleCLIENT_IDENTIFIER "nrf52840"

static const IotMqttConnectInfo_t xConnectInfo = { / Set this flag to true if connecting to the AWS IoT MQTT broker. / .awsIotMqttMode = true,

/* Start with a clean session i.e. direct the MQTT broker to discard any

// xResult = IotMqtt_GetConnectPacketSize( &xConnectInfo, // &xRemainingLength, // &xPacketSize );

/* Make sure the packet size is less than static buffer size. */
//configASSERT( xResult == IOT_MQTT_SUCCESS );
//configASSERT( xPacketSize < mqttexampleSHARED_BUFFER_SIZE );

/* Serialize MQTT connect packet into the provided buffer. */
xResult = _IotMqtt_SerializeConnect( &xConnectInfo,
                                         ConnectPacket,
                                         xPacketSize );

configASSERT( xResult == IOT_MQTT_SUCCESS );

// for( ;; ) // { // // Task code goes here. // // // At some point we want to end the real time kernel processing // // so call ... //vTaskEndScheduler (); // } }

void MQTT_CONNECT( void ) { // Create at least one task before starting the kernel. // xTaskCreate( vMQTTTask, "MQTT_TASK", 4500, NULL, 1, NULL );

 // Start the real time kernel with preemption.
// vTaskStartScheduler ();

 // Will not get here unless a task calls vTaskEndScheduler ()
     //vTaskEndScheduler ();

}

int main( void ) { /* Perform any hardware initialization that does not require the RTOS to be

dan4thewin commented 4 years ago

@Abz23 , can you step through the code in a debugger and determine what line of code corresponds to the 0x4002 error?