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.
IotMqttError_t xResult;
size_t xRemainingLength;
size_t * xPacketSize;
// IotMqttPacketInfo_t xIncomingPacket;
BaseType_t xStatus;
uint8_t * ConnectPacket;
/ Set the context to pass into the disconnect callback function. /
xNetworkInfo.disconnectCallback.pCallbackContext = ( void ) xTaskGetCurrentTaskHandle();
IotMqttConnection_t mqttConnection = IOT_MQTT_CONNECTION_INITIALIZER;
/* Establish the connection to the MQTT broker - It is a blocking call and
will return only when connection is complete or a timeout occurs. The
network and connection structures are declared and initialised at the top
of this file. /
// xResult = IotMqtt_Connect( &( xNetworkInfo ),
// &( xConnectInfo ),
// 6000,
// &( mqttConnection ) );
//
//
// configASSERT( xResult == IOT_MQTT_SUCCESS );
// SOCKETS_Socket(); // create a socket - function found in iot_secure_sockets.h
/ Get size requirement for the connect packet */
/* 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
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
demos using TLS. */ .pRootCa = mqttBROKER_CERTIFICATE_PEM, .rootCaSize = sizeof( mqttBROKER_CERTIFICATE_PEM ),
/* Strong mutual authentication to authenticate both the broker and
while(1){ printf("DISCONNEECTED"); }
} static IotMqttNetworkInfo_t xNetworkInfo = { /* No connection to the MQTT broker has been established yet and we want to
establish a new connection. */ .createNetworkConnection = true, .u.setup.pNetworkServerInfo = &( xMQTTBrokerInfo ),
/* Set the TLS credentials for the new MQTT connection. This member is NULL
for the plain text MQTT demo. */ .u.setup.pNetworkCredentialInfo = &xNetworkSecurityCredentials,
/ Use FreeRTOS+TCP network interface. / .pNetworkInterface = AWSIOT_NETWORK_TYPE_TCP_IP,
/* Setup the callback which is called when the MQTT connection is
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
gets disconnected. */ .cleanSession = true,
/* Since we are starting with a clean session, there are no previous
subscriptions to be restored. */ .pPreviousSubscriptions = NULL, .previousSubscriptionCount = 0,
/* We do not want to publish Last Will and Testament (LWT) message if the
client gets disconnected. */ .pWillInfo = NULL,
/ Send an MQTT PING request every minute to keep the connection open if there is no other MQTT traffic. / .keepAliveSeconds = 1000,
/* The client identifier is used to uniquely identify this MQTT client to
unique, such as a device serial number. */ .pClientIdentifier = mqttexampleCLIENT_IDENTIFIER, .clientIdentifierLength = ( uint16_t ) sizeof( mqttexampleCLIENT_IDENTIFIER ) - 1,
/* This example does not authenticate the client and therefore username and
password fields are not used. */ .pUserName = NULL, .userNameLength = 0, .pPassword = NULL, .passwordLength = 0 };
//void vMQTTTask( void * pvParameters ) void vMQTTTask() {
IotMqttError_t xResult; size_t xRemainingLength; size_t * xPacketSize; // IotMqttPacketInfo_t xIncomingPacket; BaseType_t xStatus; uint8_t * ConnectPacket; / Set the context to pass into the disconnect callback function. / xNetworkInfo.disconnectCallback.pCallbackContext = ( void ) xTaskGetCurrentTaskHandle(); IotMqttConnection_t mqttConnection = IOT_MQTT_CONNECTION_INITIALIZER; /* Establish the connection to the MQTT broker - It is a blocking call and
// // configASSERT( xResult == IOT_MQTT_SUCCESS ); // SOCKETS_Socket(); // create a socket - function found in iot_secure_sockets.h / Get size requirement for the connect packet */
// xResult = IotMqtt_GetConnectPacketSize( &xConnectInfo, // &xRemainingLength, // &xPacketSize );
// 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 );
}
int main( void ) { /* Perform any hardware initialization that does not require the RTOS to be
running. */ prvMiscInitialization();
xLoggingTaskInitialize( mainLOGGING_TASK_STACK_SIZE, tskIDLE_PRIORITY, mainLOGGING_MESSAGE_QUEUE_LENGTH );
nrf_sdh_freertos_init( NULL, NULL ); ret_code_t xErrCode = pm_init();
printf("\nSTART main\n");
init_serial();
init_modem(); //MQTT_CONNECT(); vMQTTTask(); printf("\nEND");
//vTaskStartScheduler(); return 0; }