Thanks for your HTTPS Guide. I have followed it and written a code to connect my XDK110 with AWS IOT Core. 

I have defined the certificates and their lengths, (CA root, private and public).

/* constant definitions ***************************************************** */
#define HOST_NAME "ac7j26n72nlys.iot.us-west-2.amazonaws.com"
#define CA_FILE_NAME "ca.der"
#define PVT_FILE_NAME "9877620cec-private.pem.key"
#define PUB_FILE_NAME "9877620cec-public.pem.key"


/* local variables ********************************************************** */

/* global variables ********************************************************* */
unsigned char digicert_root_crt[] = {
 // Place your hex values here.
		 0x2D,
};
int digicert_root_crt_len = 1758;

unsigned char digicert_pvt_crt[] = {
		, 0x0A,

};

int digicert_pvt_crt_len = 1679;


unsigned char digicert_pub_crt[] = {
		 0x0A,

};
int digicert_pub_crt_len = 451;

 

 

 

I am also flashing the certificates.

void flashCertificate() {
 // For the purpose of readability this code has no error handling.
 // The simplelink API provides return codes of the type _i32 that can be
 // checked for the value SL_RET_CODE_OK
 // The datetime is required for certificate validation:
 SlDateTime_t dateTime;
 dateTime.sl_tm_day = (_u32)01;
 dateTime.sl_tm_mon = (_u32)01;
 dateTime.sl_tm_year = (_u32)2050;
 dateTime.sl_tm_hour = (_u32)0;
 dateTime.sl_tm_min = (_u32)0;
 dateTime.sl_tm_sec = (_u32)0;
 sl_DevSet(
 SL_DEVICE_GENERAL_CONFIGURATION,
 SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME,
 sizeof(SlDateTime_t),
 (_u8 *)(&dateTime)
 );
 // If a file with the same name already exists, call this first:
 // sl_FsDel((_u8*) CA_FILE_NAME, 0)
 // The file handle should not be 0 after a file was successfully created:
 _i32 fileHandle = 0;
 sl_FsOpen(
 (_u8*) CA_FILE_NAME,
 FS_MODE_OPEN_CREATE(
 1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
 ),
 NULL,
 &fileHandle
 );

and connecting to the secure server

void connectServerSecure(void){
 // For the purpose of readability this code has no error handling.
 // The simplelink API provides return codes of the type _i32 that can be
 // checked for the value SL_RET_CODE_OK
 // Getting the IP address of HOST_NAME:
 Ip_Address_T destAddr = 0;
 PAL_getIpaddress((uint8_t*) HOST_NAME, &destAddr);
 // Creating a Socket (socketHandle ≦ 0 indicates an error):
 _i16 socketHandle = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, SL_SEC_SOCKET);
 // Adding the certificate to the socket:
 sl_SetSockOpt(
 socketHandle,
 SL_SOL_SOCKET,
 SL_SO_SECURE_FILES_CA_FILE_NAME,
 CA_FILE_NAME,
 strlen(CA_FILE_NAME)
 );
 // Configuration the connection settings (IP, Port, etc.):
 SlSockAddrIn_t addr;
 addr.sin_family = SL_AF_INET;
 addr.sin_port = sl_Htons(443);
 addr.sin_addr.s_addr = destAddr;
 // Connecting:
 sl_Connect(socketHandle, ( SlSockAddr_t *)&addr, sizeof(SlSockAddrIn_t));
 // Implementation Placeholder
 // Do your request, etc. here
   sendGetRequest(socketHandle, HOST_NAME, "/");
 // Closing:
 sl_Close(socketHandle);
}

This is my sendGetRequest function which I called in connectServerSecure

void sendGetRequest(_i16 socketHandle, char* host, char* path)
{
 char outBuf[1024];
 char inBuf[1024];
 _i16 bytesSent = 0;
 _i16 bytesReceived = 0;
 sprintf(
 outBuf,
 "GET https://%s%s HTTP/1.1\r\nHost: %s\r\n\r\n", host, path, host
 );
 printf("HTTP request:\r\n");
 printf("\r\n======\r\n");
 printf("%s", outBuf);
 printf("\r\n======\r\n");
 bytesSent = sl_Send(
 socketHandle, (const void *) outBuf, strlen(outBuf), 0
 );
 if( bytesSent <= 0 ) {
 printf("sl_Send failed: %i\r\n", bytesSent);
 return;
 }
 printf("HTTP response:\r\n");
 printf("\r\n======\r\n");
 int linesPrinted = 0;
do
{
 bytesReceived = sl_Recv(socketHandle, inBuf, 1024, 0);
 int lastStart = 0;
 int pos = 0;

 while (linesPrinted < 10 && pos < bytesReceived)
  { if (inBuf[pos] == '\n') {
	 printf("%.*s", pos - lastStart - 1, inBuf + lastStart);
	 printf("\r\n");
	 lastStart = pos;
	 linesPrinted++;}
   pos++;
   }

 } while(bytesReceived > 0);

if (linesPrinted == 10) {
 printf("...\r\n");
 }
 printf("\r\n======\r\n");
}

This is the appInitSystem function

void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);
    networkSetup();
    flashCertificate();
    // Use this before connecting:
    SlSockSecureMethod secMethod;
    secMethod.secureMethod = SL_SO_SEC_METHOD_SSLv3_TLSV1_2;
    connectServerSecure();
}

 

 

Can you please help me in figuring out what am I doing wrong while sending a get request to AWS IOT?

0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
5/23/18 12:15 PM as a reply to Sajid Baloch.
Hello Sajid,

first, I would like to welcome you to the XDK-Community.

I have a few pointers that may help you:

First of all, I do not see code for writing the certificates to the simplelink chip's flash memory. Thus, I cannot verify if you are doing that correctly. One thing you have to watch out for is that if the certificate is longer than 1024 bytes, it cannot be written all at once into the simplelink chip's flash memory. For certificates longer than 1024 bytes you need to loop the writing in flashCertificate() until all bytes are written.

Secondly, since you have multiple keys, you actually need to set the private key, the certificate and the Root CA for the socket using sl_SetSockOpt() . But, in your function connectServerSecure() you only set the Root CA. You can basically copy the function call of sl_SetSockOpt() you already have. The relevant enums here are:
 
  • SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME
  • SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME
  • SL_SO_SECURE_FILES_CA_FILE_NAME - you already have the call for this one

Finally, the key files you downloaded from AWS are encoded as PEM , but the simplelink chip only accepts DER encoded files. You would have to convert them first. This site for SSL conversion may prove helpful in that regard.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
5/23/18 1:20 PM as a reply to Alexander Sawtschuk.

First of all,

How can I loop the writing in flashCertificate() until all bytes are written?

 

Secondly,

I have set the public and private keys like this

 sl_SetSockOpt(
  socketHandle,
  SL_SOL_SOCKET,
  SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,
  PRIVATE_FILE_NAME,
  strlen(PRIVATE_FILE_NAME)
  );
 
 
 sl_SetSockOpt(
  socketHandle,
  SL_SOL_SOCKET,
  SL_SO_SECURE_CERTIFICATE_FILE_NAME,
  PUBLIC_FILE_NAME,
  strlen(PUBLIC_FILE_NAME)
  );

But getting an error on 

SL_SO_SECURE_CERTIFICATE_FILE_NAME

that this could not be resolved.

These are my definitions of certificates:

#define CA_FILE_NAME "ca.der"
#define PRIVATE_FILE_NAME "9877620cec-private.pem.key"
#define PUBLIC_FILE_NAME "9877620cec-public.pem.key"
 

 

 

 

Finally, while converting the private and public keys, I am getting this error.

 "There was a problem converting that certificate. It may be corrupt or it may be in a different format than the one you selected. You can try using a different format or running the OpenSSL commands on your own machine. The private key also may not match the certificate that you uploaded. Go back "

 

I think it's due to thekey file which doesn't have Begin Certificate in it. Because I also tried it in cmd using openssl command and this was the error:

 " unable to load certificate
9712:error:0906D06C:PEM routines:PEM_read_bio:no start line:crypto\pem\pem_lib.c:691:Expecting: TRUSTED CERTIFICATE "

 

0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
5/24/18 11:37 AM as a reply to Sajid Baloch.
Hello Sajid,

regarding the looped writing, I have posted code for that in this thread here before, in my second last post there.
 
_u32 remainingLength = length;
while(remainingLength > 0)
{
     remainingLength -= sl_FsWrite(
       fileHandle,
       length - remainingLength,
       data+(length - remainingLength),
       remainingLength > 1024 ? 1024 : remainingLength // equal to max(remainingLength, 1024)
 );
}

In this code, the parameter data is the array of the certificate, the parameter length is the length of the array and fileHandle is the reference to the file that is opened beforehand. I hope this helps.

The private and the public key are being set correctly currently, but, I assume that you should not use the public key for SL_SO_SECURE_CERTIFICATE_FILE_NAME . Instead, you should have received a download link for a file called 9877620cec-certificate.pem.crt . Try to use that, instead of the public key.

This is also why the public key can not be converted using ssl. It simply is not a certificate.

On a side-note, I would recommend that you check the return code of sl_Connect() when you run the code later. This way, you will know why it fails if it does fail. And you should edit your initial post and hide the certificate bytes, at least partially.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
+1 (1 Vote)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
5/28/18 11:37 AM as a reply to Alexander Sawtschuk.

I have tried using your code for the loop but got error that parameter data and length can't be resolved. 

If data is the array of the certificate then I have 3 arrays for 3 certificates.

unsigned char digicert_root_crt[]

unsigned char digicert_pvt_crt[]

unsigned char digicert_pub_crt[]

 

I'll try the certificate and let you know.

 

I want to edit my initial post to change the hex values but ther eis no option to edit the post.

0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
5/28/18 1:22 PM as a reply to Sajid Baloch.
/* system header files */
#include <stdio.h>
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

/* own header files */
#include "https.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"
#include "BCDS_WlanConnect.h"
#include "BCDS_NetworkConfig.h"
#include "PAL_initialize_ih.h"
#include "PAL_socketMonitor_ih.h"
#include <simplelink.h>

/* constant definitions ***************************************************** */
#define HOST_NAME "ac7j26n72nlys.iot.us-west-2.amazonaws.com"
#define CA_FILE_NAME "ca.der"
#define PRIVATE_FILE_NAME "9877620cec-private.pem.key"
#define CERTIFICATE_FILE_NAME "9877620cec-certificate.der"


/* local variables ********************************************************** */

/* global variables ********************************************************* */
unsigned char digicert_root_crt[] = {
 // Place your hex values here.
		//hex values are hidden intentionaly
};
int digicert_root_crt_len = 1758;

unsigned char digicert_pvt_crt[] = {
		//hex values are hidden intentionaly

};

int digicert_pvt_crt_len = 1679;


unsigned char digicert_pub_crt[] = {
		//hex values are hidden intentionaly
};
int digicert_pub_crt_len = 451;
/* inline functions ********************************************************* */

/* local functions ********************************************************** */

void flashCertificate() {

 SlDateTime_t dateTime;
 dateTime.sl_tm_day = (_u32)01;
 dateTime.sl_tm_mon = (_u32)01;
 dateTime.sl_tm_year = (_u32)2050;
 dateTime.sl_tm_hour = (_u32)0;
 dateTime.sl_tm_min = (_u32)0;
 dateTime.sl_tm_sec = (_u32)0;
 sl_DevSet(
 SL_DEVICE_GENERAL_CONFIGURATION,
 SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME,
 sizeof(SlDateTime_t),
 (_u8 *)(&dateTime)
 );

 _i32 fileHandle = 0;
 sl_FsOpen(
 (_u8*) CA_FILE_NAME,
 FS_MODE_OPEN_CREATE( 1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ ),
 NULL,
 &fileHandle );

 _u32 remainingLength = 1758;
 while(remainingLength > 0)
 {
      remainingLength -= sl_FsWrite(
        fileHandle,
        1758 - remainingLength,
		digicert_root_crt+(1758 - remainingLength),
        remainingLength > 1024 ? 1024 : remainingLength // equal to max(remainingLength, 1024)
  );
 }

 sl_FsClose(fileHandle, NULL, NULL, 0);




  sl_FsOpen(
  (_u8*) PRIVATE_FILE_NAME,
  FS_MODE_OPEN_CREATE( 1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ ),
  NULL,
  &fileHandle );

remainingLength = 1679;
  while(remainingLength > 0)
  {
       remainingLength -= sl_FsWrite(
         fileHandle,
         1679 - remainingLength,
		 digicert_pvt_crt+(1679 - remainingLength),
         remainingLength > 1024 ? 1024 : remainingLength // equal to max(remainingLength, 1024)
   );
  }

  sl_FsClose(fileHandle, NULL, NULL, 0);



   sl_FsOpen(
   (_u8*) CERTIFICATE_FILE_NAME,
   FS_MODE_OPEN_CREATE( 1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ ),
   NULL,
   &fileHandle );


}

// Call this function after flashCertificate() in appInitSystem()
void sendGetRequest(_i16 socketHandle, char* host, char* path)
{
 char outBuf[1024];
 char inBuf[1024];
 _i16 bytesSent = 0;
 _i16 bytesReceived = 0;
 sprintf(
 outBuf,
 "GET https://%s%s HTTP/1.1\r\nHost: %s\r\n\r\n", host, path, host
 );
 printf("HTTP request:\r\n");
 printf("\r\n======\r\n");
 printf("%s", outBuf);
 printf("\r\n======\r\n");
 bytesSent = sl_Send(
 socketHandle, (const void *) outBuf, strlen(outBuf), 0
 );
 if( bytesSent <= 0 ) {
 printf("sl_Send failed: %i\r\n", bytesSent);
 return;
 }
 printf("HTTP response:\r\n");
 printf("\r\n======\r\n");
 int linesPrinted = 0;
do
{
 bytesReceived = sl_Recv(socketHandle, inBuf, 1024, 0);
 int lastStart = 0;
 int pos = 0;

 while (linesPrinted < 10 && pos < bytesReceived)
  { if (inBuf[pos] == '\n') {
	 printf("%.*s", pos - lastStart - 1, inBuf + lastStart);
	 printf("\r\n");
	 lastStart = pos;
	 linesPrinted++;}
   pos++;
   }

 } while(bytesReceived > 0);

if (linesPrinted == 10) {
 printf("...\r\n");
 }
 printf("\r\n======\r\n");
}


void connectServerSecure(void){
 // For the purpose of readability this code has no error handling.
 // The simplelink API provides return codes of the type _i32 that can be
 // checked for the value SL_RET_CODE_OK
 // Getting the IP address of HOST_NAME:
 Ip_Address_T destAddr = 0;
 PAL_getIpaddress((uint8_t*) HOST_NAME, &destAddr);
 // Creating a Socket (socketHandle ≦ 0 indicates an error):
 _i16 socketHandle = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, SL_SEC_SOCKET);
 // Adding the certificate to the socket:
 sl_SetSockOpt(
 socketHandle,
 SL_SOL_SOCKET,
 SL_SO_SECURE_FILES_CA_FILE_NAME,
 CA_FILE_NAME,
 strlen(CA_FILE_NAME)
 );


 sl_SetSockOpt(
  socketHandle,
  SL_SOL_SOCKET,
  SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,
  PRIVATE_FILE_NAME,
  strlen(PRIVATE_FILE_NAME)
  );


 sl_SetSockOpt(
  socketHandle,
  SL_SOL_SOCKET,
  SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,
  CERTIFICATE_FILE_NAME,
  strlen(CERTIFICATE_FILE_NAME)
  );
 // Configuration the connection settings (IP, Port, etc.):
 SlSockAddrIn_t addr;
 addr.sin_family = SL_AF_INET;
 addr.sin_port = sl_Htons(443);
 addr.sin_addr.s_addr = destAddr;
 // Connecting:
 sl_Connect(socketHandle, ( SlSockAddr_t *)&addr, sizeof(SlSockAddrIn_t));
 // Implementation Placeholder
 // Do your request, etc. here
   sendGetRequest(socketHandle, HOST_NAME, "/");
 // Closing:
 sl_Close(socketHandle);
}


/*
void sendGetRequest(_i16 socketHandle, char* host, char* path)
{
 char outBuf[1024];
 char inBuf[1024];
 sprintf(outBuf,"GET https://%s%s HTTP/1.1\r\nHost: %s\r\n\r\n", host, path, host);
 sl_Send(socketHandle, (const void *) outBuf, strlen(outBuf), 0);
 sl_Recv(socketHandle, inBuf, 1024, 0);
 printf("%s\r\n", inBuf);
}

*/




/* global functions ********************************************************* */

/**
 * @brief This is a template function where the user can write his custom application.
 *
 */


void networkSetup(void){
 WlanConnect_SSID_T connectSSID = (WlanConnect_SSID_T) "OnePlus 5T";
 WlanConnect_PassPhrase_T connectPassPhrase = (WlanConnect_PassPhrase_T)
"password123";
 WlanConnect_Init();
 NetworkConfig_SetIpDhcp(0);
 WlanConnect_WPA(connectSSID, connectPassPhrase, NULL);
 PAL_initialize();
 PAL_socketMonitorInit();
}

void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);
    networkSetup();
    flashCertificate();
    // Use this before connecting:
    SlSockSecureMethod secMethod;
    secMethod.secureMethod = SL_SO_SEC_METHOD_SSLv3_TLSV1_2;
    connectServerSecure();
}

This is the edited code. There is no error now. But still sending is failed with a value of -1. 

Stack overflow occurs.

 INFO | Connecting to XDK device 'XDK Device 1' in port 'COM7'...
 INFO | Connection to port 'COM7' established
 INFO | XDK DEVICE 1: HTTP request:
 INFO | XDK DEVICE 1: ======
 INFO | XDK DEVICE 1: GET https://ac7j26n72nlys.iot.us-west-2.amazonaws.com/ HTTP/1.1
 INFO | XDK DEVICE 1: Host: ac7j26n72nlys.iot.us-west-2.amazonaws.com
 INFO | XDK DEVICE 1: ======
 INFO | XDK DEVICE 1: sl_Send failed: -1
 INFO | XDK DEVICE 1: ----- STACK OVERFLOW -----Task Name:MainCmdPr-----Current Task Handle:0x20002ef0

Can you please figure out what am I doing wrong now?

 

0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
5/28/18 4:41 PM as a reply to Sajid Baloch.
Hello Sajid,

regarding the editting option for your post, I have added a screenshot illustrating what to look for. The editting button is marked red.

As for your code, of course I can try to analyze your code, but I may not find all the issues. Nonetheless, I have found the following points that I would advise you to go over:

Your code is currently mixing functionality for flashing the certificates onto the simplelink chip's flash memory and the sending logic.

I would recommend that you create a new project where you only focus on flashing the certificates correctly. You can flash that project onto the XDK and let it write the certificate files, and then run the project that does the sending. This will work since the flash memory of the simplelink is persistent. This will also help to go easy on the memory usage, and overall, it will be much more readable.

Then I noticed in flashCertificate() that you are flashing the root CA and the private key correctly, but the third file is just opened, but never written to. Thus, you are seemingly missing one certificate. In general, I would also recommend to delete files with filenames you are not intending to use anymore.

Additionally, you do not set the socket security option during connectServerSecure() . The following code will tell the simplelink chip to use TLS for that socket:

 
SlSockSecureMethod secMethod;
secMethod.secureMethod = SL_SO_SEC_METHOD_SSLv3_TLSV1_2;
sl_SetSockOpt(
    socketHandle,
    SL_SOL_SOCKET,
    SL_SO_SECMETHOD,
    (_u8 *)&secMethod,
    sizeof(secMethod)
);


On another note, you receive a stack overflow at the end of your console log. This is because there is not enough memory to allocate variables. I would recommend to either reduce the size of outBuf to at most 512 bytes (since you do not need nearly that much) or to increase the stack size of the App CmdProcessor_T, which you can do in your main header file. For this, change the macro TASK_STACK_SIZE_MAIN_CMD_PROCESSOR to a value higher than 700.

Finally, I would suggest to check the return value of sl_Connect() . This will be a positive value if connection was sucessfull and a negative value on failure. For negative values, the reason for a concrete connection failure is specified in socket.h

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
5/30/18 11:38 AM as a reply to Alexander Sawtschuk.
I would recommend that you create a new project where you only focus on flashing the certificates correctly. You can flash that project onto the XDK and let it write the certificate files, and then run the project that does the sending.

Can I flash more than one code in the xdk? If yes, then how can I do it? For flashing a new one, don't I have to remove the old one?

=================================================================================================================================

 

 

Then I noticed in flashCertificate() that you are flashing the root CA and the private key correctly, but the third file is just opened, but never written to. Thus, you are seemingly missing one certificate. 

I have done it like this. is it correct now?

sl_FsWrite(fileHandle,0, digicert_pub_crt,1024);

 

 

===========================================================================================

 

I would recommend to either reduce the size of outBuf to at most 512 bytes (since you do not need nearly that much) or to increase the stack size of the App CmdProcessor_T, which you can do in your main header file. For this, change the macro TASK_STACK_SIZE_MAIN_CMD_PROCESSOR to a value higher than 700.

I have reduced the outBuf to 512 and increased the value of TASK_STACK_SIZE_MAIN_CMD_PROCESSOR to 1024.

Still I am getting this error..

 INFO | XDK DEVICE 1:  Jumping to application
 INFO | Port 'COM7' has been disconnected
 INFO | Connecting to XDK device 'XDK Device 1' in port 'COM7'...
 INFO | Connection to port 'COM7' established
 INFO | XDK DEVICE 1: HTTP request:
 INFO | XDK DEVICE 1: ======
 INFO | XDK DEVICE 1: GET https://ac7j26n72nlys.iot.us-west-2.amazonaws.com/ HTTP/1.1
 INFO | XDK DEVICE 1: Host: ac7j26n72nlys.iot.us-west-2.amazonaws.com
 INFO | XDK DEVICE 1: ======
 INFO | XDK DEVICE 1: sl_Send failed: -1
0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
5/30/18 3:39 PM as a reply to Sajid Baloch.
Hello Sajid,

it is not possible to flash two applications simultaneously. What I meant was that you could take all the code that is responsible for flashing the certificates onto the simplelink chip and put it in a separate project.

That way, you can have one project that completely focuses on writing the certificates into the simplelink chip's memory correctly, and one project that completely focuses on sending messages correctly.

This is possible because the certificates will persist, even after flashing a new application onto the XDK. This way, you can run the application that writes the certificates and afterwards, you flash the application that is responsible for sending and still use the certificates that you flashed beforehand.

Debugging will be easier as well, since you can focus on one functionality per application. But of course, this is just a recommendation.

Regarding the missing sl_FsWrite() call, I recommend that you use the actual length of the certificate, instead of 1024. Otherwise, the function will write 1024 bytes as the certificate, where the last bytes are from outside the actual array.

As for the console log excerpt, there is no stack overflow now, at least. But please do not forget to check the return code of sl_connect() , this is the most important return code to check, since it determines if all further operations on that socket will have meaningful effects.

Finally, I do not know if you did everything else correctly now, since you did not post the updated code. Would it be possible for you to upload your project(s) on github (or any other platform for sharing code), so that I can inspect the updated code?

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
6/4/18 10:28 AM as a reply to Alexander Sawtschuk.
0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
6/4/18 1:29 PM as a reply to Sajid Baloch.
Hello Sajid,

I have taken a quick look at your code on github, and other than the fact that you did not yet fix the last write operation and that you do not check the return code of sl_Connect() yet, nearly everything seems proper.

One thing that I did not look out for yet is the fact that you open the files on the simplelink chip's filesystem with FS_MODE_OPEN_CREATE( 1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ ) .

The first input of that macro is defined as maxSizeInBytes . I propose that you set this to 2*1024 instead of just 1024 for your files.

After that, if the certificates are DER encoded, it should work.

Kind regards,
Alex
0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
7/9/18 9:48 PM as a reply to Alexander Sawtschuk.

Hi! Alexander.

I was looking precisely that! All the explanation was perfect, thanks!

 

I tried flashing a certificate with 1220 bytes, the code you wrote did not give me any compilation error, but the socket connection was always unsuccessful until I made a tiny modification on the code.  This code worked on my program (XDK Workbench v.3.1.1 for Windows x64):

 

_u32 remainingLength = length;
while(remainingLength > 0)
{
         remainingLength -= (_u32) sl_FsWrite
        (
           fileHandle,
           length - remainingLength,
           data+(length - remainingLength),
           remainingLength > 1024 ? 1024 : remainingLength // equal to max(remainingLength, 1024)
         );
}

 

 

0 (0 Votes)
RE: XDK HTTPS request problem to AWS IOT Core
Answer
7/10/18 9:00 PM as a reply to Rolando Gonzalez.
Hello Rolando,

Thank you for reaching out regarding Alex code snippet and for providing the adapted solution for his source code.

I assume that it will help many other users too.

Please feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)