MQTT-PAHO and AWS IoT
Antwort
02.08.17 10:01

Thanks for your great latest MQTT Paho Demo with the broker link of broker.hivemq.com example. The demo file explain very well on how to get the XDK110 connected to the broker with topic of DK110/<MQTT_CLIENT_ID>/Data/Stream. I can receive the sensor data with every one second interval.

However, when I used my AWS IoT broker link and port 8883 the XDK cannot work well even cannot get connected to the AWS IoT broker server. I think it is because of AWS IoT has addition security credential keys. There are three keys must be attached in the XDK firmware; privkey.pem, cert.pem and aws-iot-rootCA.crt. Please see the following example:

https://www.hackster.io/mariocannistra/python-and-paho-for-mqtt-with-aws-iot-921e41

Nevertheless, I want to setup an IoT system by following your great MQTT Paho Demo example with AWS IoT broker. How do I attach the credential keys from AWS? Otherwise I cannot get connected.

Please advise me in step by step manner in order for me to get the sensor data from my AWS IoT broker.

Thanks.

Michael.

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
02.08.17 14:54 als Antwort auf Michael Ng.

Hello Michael,

adding certificates to your connection will require a bit of work. I will give you a rough outline on what to do, and where to find further information on this.

In your MQTT Paho demo project, there are two files in source/paho/XDK called mqttXDK.c and mqttXDK.h. They define the interaction between the actual MQTT Protocol files provided by Eclipse Paho (in source/paho) and the simplelink API, responsible for sending and receiving the actual messages.

You will notice, that the mqttXDK.c defines a function called TLSConnectNetwork() (as a secure pendant to ConnectNetwork()). It has some additional inputs, which you will have to provide. Those are the certificates (stored in a variable of type SlSockSecureFiles_t), the security method, the cipher, and char called server_verify (0 should be used for this).

The function ConnectNetwork() is used in mqttPahoClient.c to connect to the broker. You have to replace this function with TLSConnectNetwork() and define the new inputs.

All relevant information regarding the certificates, the security method and the cipher, can be found in the header-file socket.h, which is located in your project at SDK/xdk110/Libraries/WiFi/TI/simplelink/include/socket.h.

The security method and the cipher can be chosen from predefined values inside socket.h. Regarding the certificates, I believe you have to flash them to the XDK's memory first, and then insert the filenames inside the certificates array. The array is a field of the SlSockSecureFiles_t. The order of files is also defined as:

typedef enum
{
  SL_BSD_SECURED_PRIVATE_KEY_IDX = 0,
  SL_BSD_SECURED_CERTIFICATE_IDX,
  SL_BSD_SECURED_CA_IDX,
  SL_BSD_SECURED_DH_IDX
} slBsd_secureSocketFilesIndex_e;

If you are wondering how to flash data to the XDK's memory, take a look at the HTTPS guide at xdk.io/guides. It has a section that explains how to flash a certificate.

I have not tried this out myself, yet, so I cannot guarantee that it will work out exactly like this, but it should be the correct direction.

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

Kind regards,
Franjo

+1 (1 Stimme)
RE: MQTT-PAHO and AWS IoT
Antwort
03.08.17 07:07 als Antwort auf Franjo Stjepandic.

Dear Franjo,

Thanks for your immediate reply. I am very appreciate it. Also thanks for your very informative details.

However, after dig more information from the HTTPS guide at xdk.io/guides I still cannot get the things done. Perhaps the HTTPS guide is not a good guide because it does not explain clearly and not a complete guide too. Perhaps this guide needs to be revised again otherwise the users will get lost.

Anyway, like I have mentioned earlier that if I have three certificates:
1. aws-iot-rootCA.crt (similar to digicert root certificate in the HTTPS guide)
2. cert.pem 
3. privkey.pem

Do these three certificates need to be converted into Hex format files and saved it into ,der?

Are there necessary to flash these three certificates into SD Card memory or in the project folder?

There are three related files; mqttXDK.c, mqttPahoClient.c and socket.h as you mentioned earlier. which one needs to be configured to include the certificate names?

Can you make some changes in these files to include these three certificates (or only one) for me to test? Let us try to configure them together and see whether it will be worked.

For the AWS IoT configuration. I actually followed the example in the following link:

https://www.thorntech.com/2016/09/aws-iot-to-send-text-message-notifications/

Thanks.

Michael.

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
03.08.17 13:27 als Antwort auf Michael Ng.

Hello Michael,

while the HTTPS guide may be confusing for MQTT, it is appropriate for HTTPS. In any case, I will try to further elaborate what to do, in a tutorial-like manner.

--- Changes to mqttPahoClient.c ---

First, add the include for "socket.h" at the top of the implementation file, to the other includes. (#include "socket.h"). This will enable us to access the constant definitions and types from socket.h.

Create a global variable of type SlSockSecureFiles_t, called certificates.

Inside the function clientInit(), add the line flashCertificates(); before ConnectNetwork(...);. Inside flashCertificates(), the certificates will be flashed onto the XDK.

the next change will be from ConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT); to TLSConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT, certificates, SL_SO_SEC_METHOD_TLSV1_2, NULL, 0);. As I mentioned before, TLSConnectNetwork() is the secure pendant to ConnectNetwork(). The variable certificates will hold the certificates. The next input SL_SO_SEC_METHOD_TLSV1_2 security method, which I derived from the tutorial you mentioned in your last post. The next input field, which is currently set to NULL, is the cipher. I don't know which to use, but I think inserting NULL will be alright (as I mentioned before, I didn't try it out myself yet, details are up to you essentially).

--- flashCertificates() ---

Inside mqttPahoClient.c, create a function called flashCertificates(). It should have the return-type void and accept no inputs.

This function will essentially flash your certificates to the memory. The same procedure as with the certificate in the HTTPS guide. For every certificate file, extract the hexadecimal values with a tool of your liking (as seen in HTTPS guide) and make the appropriate defines at the top of mqttPahoClient.c. For example:

#define PRIV_FILE_NAME "privkey.der"
unsigned char PRIV_KEY [] = { //Place your Hex Values here }
int PRIV_KEY_LEN = // the appropriate length of they key (the number of hex values)

The file-extension .der should be appropriate for all three certificates. See https://support.ssl.com/Knowledgebase/Article/View/19/0/der-vs-crt-vs-cer-vs-pem-certificates-and-how-to-convert-them for more information on file-extensions for certificates.

The function itself will do approximately the same as the one from the HTTPS guide, so you can copy everything up to (and including) _i32 fileHandle = 0;

Now, for each key, add the following code inside the function (with the privkey as an example):

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

// If the file is longer than 1024 bytes, you need to loop the writing.
// "length" contains the length of the certificate
// "writtenLength" contains the amount of actually written bytes.
_i32 writtenLen = sl_FsWrite(fileHandle, 0, PRIV_KEY, PRIV_KEY_LEN);

sl_FsClose(fileHandle, NULL, NULL, 0);

fileHandle = 0;

This will flash the certificates to memory, one after another. As a last step, we fill the variable certificates with the filenames like this:

certificates.secureFiles[0] = "appropriate filename";

replace appropriate filename with the correct filename. secureFiles is an array with 4 fields. The first field (index 0) should be the privkey. index 1 is cert and index 2 is aws-iot-rootCA. (you can see the order in my last post). Just in case, leave index 3 empty, or fill it with NULL or just "" (empty string).


I think this is all you have to do. Try it out and tell me of your progress. If any detail is missing, feel free to ask again.

Kind regards,
Franjo

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
07.08.17 09:17 als Antwort auf Franjo Stjepandic.

Hi Franjo,

I have done the mqttPahoClient.c according to your tutorial liked guide. Anyway, can you verify it?

I have written it accordingly.

/*************** Step 1 ***************/
/*************** Step 2 ***************/
/*************** Step 3 ***************/
/*************** Step 4 ***************/
/*************** Step 5 ***************/
/*************** Step 6 ***************/
/*************** Step 7 ***************/
/*************** Step 8 ***************/

Please help me to verify it before I try to run the project.

By the way, I do not need to flash the three certificate files into the XDK110 right?

Thanks.

Michael.

 

/******************************************************************************
**    COPYRIGHT (c) 2016        Bosch Connected Devices and Solutions GmbH
**
**    The use of this software is subject to the XDK SDK EULA
**
*******************************************************************************
**
**    OBJECT NAME:    mqttClient.c
**
**    DESCRIPTION:    Source Code for the MQTT Paho Client
**
**    PURPOSE:        Initializes the Paho Client and sets up subscriptions,
**                    starts the task to pubish and receive data,
**                    initializes the timer to stream data,
**                    defines the callback function for subscibed topics
**
**    AUTHOR(S):        Bosch Connected Devices and Solutions GmbH (BCDS)
**
**    Revision History:
**
**    Date             Name        Company      Description
**  2016.Apr         crk        BCDS         Initial Release
**
*******************************************************************************/

/* system header files */
#include <stdint.h>

/* own header files */
#include "mqttPahoClient.h"
#include "mqttConfig.h"
#include "mqttSensor.h"

/*************** Step 1 ***************/
#include "socket.h"            // AdeMike

/* additional interface header files */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "PTD_portDriver_ph.h"
#include "PTD_portDriver_ih.h"
#include "WDG_watchdog_ih.h"

/* paho header files */
#include "MQTTConnect.h"

/* constant definitions ***************************************************** */

/*************** Step 6 ***************/
#define PRIV_FILE_NAME "privkey.der"    // AdeMike
unsigned char PRIV_KEY [] = {
        0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50,
        0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A,
        0x4D, 0x49, 0x49, 0x45, 0x6F, 0x77, 0x49, 0x42, 0x41, 0x41, 0x4B, 0x43, 0x41, 0x51, 0x45, 0x41,
        0x70, 0x39, 0x59, 0x4E, 0x72, 0x5A, 0x67, 0x51, 0x64, 0x67, 0x68, 0x72, 0x48, 0x70, 0x70, 0x54,
        0x30, 0x4A, 0x6D, 0x75, 0x74, 0x52, 0x61, 0x6C, 0x41, 0x4C, 0x2B, 0x35, 0x35, 0x6D, 0x7A, 0x61,
        0x5A, 0x79, 0x79, 0x52, 0x79, 0x43, 0x58, 0x42, 0x6B, 0x41, 0x57, 0x72, 0x5A, 0x76, 0x61, 0x49,
        0x0A, 0x55, 0x54, 0x65, 0x58, 0x61, 0x6D, 0x32, 0x51, 0x6F, 0x69, 0x4D, 0x4D, 0x50, 0x71, 0x38,
        0x4E, 0x7A, 0x63, 0x2F, 0x6D, 0x6F, 0x45, 0x44, 0x46, 0x77, 0x68, 0x6C, 0x43, 0x6B, 0x50, 0x30,
        0x74, 0x4B, 0x42, 0x61, 0x70, 0x6E, 0x6F, 0x52, 0x2B, 0x63, 0x44, 0x36, 0x52, 0x2F, 0x77, 0x61,
        0x78, 0x76, 0x2F, 0x65, 0x59, 0x55, 0x77, 0x54, 0x65, 0x55, 0x53, 0x70, 0x5A, 0x2B, 0x32, 0x7A,
        0x55, 0x0A, 0x56, 0x58, 0x6C, 0x49, 0x5A, 0x6B, 0x51, 0x33, 0x77, 0x75, 0x79, 0x51, 0x48, 0x55,
        0x54, 0x56, 0x30, 0x2F, 0x6A, 0x4D, 0x30, 0x47, 0x42, 0x45, 0x69, 0x2B, 0x48, 0x57, 0x4E, 0x34,
        0x6F, 0x4D, 0x69, 0x50, 0x43, 0x67, 0x59, 0x49, 0x31, 0x36, 0x78, 0x74, 0x55, 0x33, 0x4C, 0x64,
        0x49, 0x58, 0x66, 0x32, 0x37, 0x4C, 0x52, 0x49, 0x66, 0x4B, 0x64, 0x4C, 0x2B, 0x45, 0x33, 0x2B,
        0x49, 0x77, 0x0A, 0x35, 0x48, 0x37, 0x59, 0x51, 0x37, 0x55, 0x41, 0x49, 0x73, 0x61, 0x78, 0x75,
        0x4D, 0x41, 0x61, 0x6B, 0x55, 0x6B, 0x53, 0x49, 0x49, 0x72, 0x48, 0x34, 0x53, 0x53, 0x41, 0x4B,
        0x66, 0x2B, 0x75, 0x51, 0x6F, 0x34, 0x75, 0x42, 0x62, 0x39, 0x31, 0x46, 0x6F, 0x68, 0x55, 0x4E,
        0x37, 0x51, 0x56, 0x59, 0x4A, 0x38, 0x4E, 0x7A, 0x66, 0x79, 0x31, 0x76, 0x44, 0x33, 0x45, 0x38,
        0x33, 0x7A, 0x35, 0x0A, 0x2B, 0x44, 0x2B, 0x68, 0x36, 0x74, 0x4A, 0x6D, 0x46, 0x51, 0x6B, 0x5A,
        0x50, 0x2B, 0x33, 0x67, 0x6F, 0x66, 0x48, 0x69, 0x6F, 0x68, 0x57, 0x73, 0x6B, 0x42, 0x67, 0x6E,
        0x76, 0x4C, 0x33, 0x50, 0x66, 0x79, 0x6E, 0x58, 0x67, 0x46, 0x6A, 0x71, 0x36, 0x66, 0x47, 0x52,
        0x5A, 0x2B, 0x69, 0x6D, 0x6A, 0x43, 0x37, 0x47, 0x51, 0x72, 0x47, 0x4E, 0x55, 0x42, 0x2B, 0x46,
        0x6E, 0x6D, 0x58, 0x36, 0x0A, 0x35, 0x45, 0x57, 0x78, 0x41, 0x57, 0x6B, 0x68, 0x6C, 0x53, 0x75,
        0x79, 0x4E, 0x2B, 0x39, 0x46, 0x4A, 0x73, 0x62, 0x38, 0x48, 0x47, 0x50, 0x62, 0x38, 0x53, 0x53,
        0x41, 0x56, 0x50, 0x73, 0x75, 0x51, 0x4D, 0x57, 0x54, 0x72, 0x77, 0x49, 0x44, 0x41, 0x51, 0x41,
        0x42, 0x41, 0x6F, 0x49, 0x42, 0x41, 0x47, 0x42, 0x69, 0x30, 0x4B, 0x59, 0x69, 0x44, 0x30, 0x6F,
        0x4A, 0x32, 0x61, 0x4C, 0x51, 0x0A, 0x6C, 0x46, 0x50, 0x57, 0x2F, 0x6E, 0x74, 0x6E, 0x44, 0x73,
        0x6D, 0x59, 0x55, 0x65, 0x57, 0x67, 0x47, 0x2B, 0x6C, 0x6D, 0x73, 0x69, 0x34, 0x55, 0x61, 0x4D,
        0x34, 0x53, 0x51, 0x33, 0x59, 0x31, 0x48, 0x4F, 0x49, 0x76, 0x6E, 0x39, 0x68, 0x79, 0x4A, 0x62,
        0x37, 0x48, 0x69, 0x2B, 0x2B, 0x76, 0x7A, 0x71, 0x69, 0x6B, 0x76, 0x64, 0x6A, 0x49, 0x65, 0x67,
        0x6E, 0x58, 0x51, 0x65, 0x42, 0x4D, 0x0A, 0x56, 0x5A, 0x4F, 0x52, 0x4F, 0x45, 0x59, 0x64, 0x35,
        0x78, 0x4D, 0x46, 0x44, 0x41, 0x6B, 0x2B, 0x79, 0x66, 0x50, 0x70, 0x2B, 0x47, 0x4F, 0x74, 0x42,
        0x78, 0x50, 0x72, 0x30, 0x35, 0x4E, 0x4E, 0x30, 0x37, 0x39, 0x6D, 0x6B, 0x49, 0x71, 0x53, 0x6F,
        0x4D, 0x64, 0x6A, 0x33, 0x66, 0x76, 0x42, 0x48, 0x56, 0x2F, 0x48, 0x6F, 0x62, 0x41, 0x46, 0x71,
        0x54, 0x67, 0x41, 0x4D, 0x57, 0x72, 0x68, 0x0A, 0x38, 0x41, 0x4C, 0x77, 0x31, 0x64, 0x6D, 0x39,
        0x52, 0x6F, 0x5A, 0x4C, 0x79, 0x6F, 0x32, 0x59, 0x2B, 0x76, 0x2B, 0x6E, 0x48, 0x44, 0x73, 0x32,
        0x46, 0x4C, 0x48, 0x6F, 0x6E, 0x32, 0x55, 0x46, 0x39, 0x56, 0x37, 0x37, 0x36, 0x39, 0x71, 0x4E,
        0x79, 0x79, 0x36, 0x6C, 0x41, 0x2F, 0x6F, 0x66, 0x78, 0x52, 0x53, 0x4A, 0x4C, 0x6C, 0x74, 0x42,
        0x72, 0x71, 0x7A, 0x2B, 0x47, 0x36, 0x35, 0x65, 0x0A, 0x47, 0x67, 0x45, 0x4E, 0x61, 0x75, 0x4B,
        0x35, 0x68, 0x70, 0x65, 0x30, 0x48, 0x37, 0x67, 0x57, 0x2B, 0x2F, 0x38, 0x6D, 0x59, 0x39, 0x51,
        0x37, 0x5A, 0x46, 0x61, 0x63, 0x62, 0x73, 0x73, 0x72, 0x4F, 0x55, 0x76, 0x42, 0x48, 0x7A, 0x52,
        0x42, 0x72, 0x53, 0x62, 0x4C, 0x4D, 0x31, 0x70, 0x6C, 0x35, 0x4F, 0x78, 0x70, 0x70, 0x30, 0x79,
        0x41, 0x79, 0x76, 0x54, 0x59, 0x79, 0x66, 0x42, 0x58, 0x0A, 0x53, 0x6D, 0x50, 0x6D, 0x36, 0x53,
        0x75, 0x56, 0x4F, 0x56, 0x71, 0x55, 0x65, 0x6F, 0x32, 0x63, 0x61, 0x38, 0x45, 0x48, 0x37, 0x72,
        0x4D, 0x37, 0x2B, 0x79, 0x72, 0x33, 0x67, 0x61, 0x4A, 0x41, 0x2B, 0x39, 0x78, 0x55, 0x50, 0x75,
        0x66, 0x58, 0x70, 0x77, 0x48, 0x70, 0x62, 0x4A, 0x41, 0x45, 0x30, 0x6E, 0x6E, 0x76, 0x4A, 0x59,
        0x51, 0x37, 0x30, 0x36, 0x57, 0x2B, 0x63, 0x73, 0x7A, 0x6E, 0x0A, 0x44, 0x54, 0x4E, 0x6A, 0x63,
        0x59, 0x45, 0x43, 0x67, 0x59, 0x45, 0x41, 0x36, 0x54, 0x49, 0x53, 0x4E, 0x6C, 0x39, 0x65, 0x78,
        0x36, 0x75, 0x5A, 0x69, 0x30, 0x69, 0x77, 0x4E, 0x57, 0x56, 0x46, 0x51, 0x79, 0x4E, 0x64, 0x57,
        0x6C, 0x69, 0x49, 0x76, 0x47, 0x47, 0x5A, 0x64, 0x5A, 0x45, 0x6C, 0x6B, 0x73, 0x77, 0x36, 0x6C,
        0x4C, 0x49, 0x33, 0x34, 0x4F, 0x75, 0x4A, 0x33, 0x65, 0x69, 0x74, 0x0A, 0x4C, 0x6C, 0x78, 0x6E,
        0x53, 0x65, 0x58, 0x70, 0x49, 0x6E, 0x56, 0x52, 0x4D, 0x69, 0x2B, 0x66, 0x69, 0x51, 0x39, 0x35,
        0x67, 0x77, 0x74, 0x70, 0x37, 0x2B, 0x37, 0x41, 0x34, 0x6F, 0x47, 0x41, 0x58, 0x6B, 0x30, 0x53,
        0x4E, 0x66, 0x47, 0x31, 0x46, 0x49, 0x43, 0x72, 0x6B, 0x43, 0x74, 0x59, 0x78, 0x38, 0x68, 0x42,
        0x65, 0x36, 0x62, 0x2F, 0x6C, 0x49, 0x48, 0x47, 0x66, 0x52, 0x50, 0x5A, 0x0A, 0x6E, 0x76, 0x78,
        0x6B, 0x38, 0x51, 0x73, 0x33, 0x69, 0x50, 0x74, 0x64, 0x4E, 0x50, 0x31, 0x48, 0x45, 0x76, 0x2F,
        0x4F, 0x46, 0x4E, 0x72, 0x4D, 0x74, 0x4B, 0x56, 0x62, 0x32, 0x2B, 0x61, 0x6E, 0x6F, 0x43, 0x53,
        0x66, 0x6A, 0x66, 0x32, 0x69, 0x70, 0x56, 0x42, 0x76, 0x44, 0x78, 0x4E, 0x4F, 0x6A, 0x62, 0x46,
        0x4D, 0x51, 0x2B, 0x38, 0x43, 0x67, 0x59, 0x45, 0x41, 0x75, 0x44, 0x2B, 0x2B, 0x0A, 0x4E, 0x61,
        0x59, 0x4C, 0x52, 0x35, 0x48, 0x74, 0x51, 0x71, 0x4E, 0x4E, 0x2F, 0x62, 0x57, 0x56, 0x6A, 0x51,
        0x57, 0x77, 0x48, 0x55, 0x4C, 0x73, 0x59, 0x61, 0x2B, 0x75, 0x57, 0x68, 0x4B, 0x31, 0x51, 0x4B,
        0x50, 0x51, 0x63, 0x6C, 0x75, 0x53, 0x78, 0x33, 0x71, 0x7A, 0x47, 0x68, 0x68, 0x53, 0x62, 0x43,
        0x4A, 0x4A, 0x4F, 0x63, 0x56, 0x67, 0x2F, 0x78, 0x73, 0x79, 0x59, 0x4B, 0x70, 0x6D, 0x0A, 0x48,
        0x52, 0x56, 0x31, 0x67, 0x58, 0x67, 0x68, 0x54, 0x46, 0x4A, 0x73, 0x61, 0x59, 0x42, 0x79, 0x71,
        0x32, 0x52, 0x62, 0x68, 0x2B, 0x50, 0x63, 0x45, 0x6A, 0x42, 0x34, 0x47, 0x69, 0x6C, 0x32, 0x47,
        0x51, 0x52, 0x5A, 0x34, 0x58, 0x43, 0x75, 0x44, 0x37, 0x65, 0x4B, 0x4D, 0x66, 0x4D, 0x63, 0x30,
        0x6A, 0x5A, 0x43, 0x47, 0x72, 0x79, 0x6F, 0x69, 0x36, 0x42, 0x62, 0x54, 0x64, 0x7A, 0x58, 0x0A,
        0x34, 0x57, 0x62, 0x42, 0x58, 0x45, 0x66, 0x36, 0x47, 0x65, 0x63, 0x30, 0x59, 0x70, 0x32, 0x57,
        0x4F, 0x72, 0x6D, 0x52, 0x54, 0x64, 0x37, 0x42, 0x44, 0x51, 0x74, 0x63, 0x55, 0x49, 0x4B, 0x63,
        0x76, 0x6F, 0x61, 0x34, 0x37, 0x45, 0x45, 0x43, 0x67, 0x59, 0x45, 0x41, 0x6B, 0x62, 0x2B, 0x69,
        0x31, 0x47, 0x72, 0x39, 0x4D, 0x53, 0x7A, 0x57, 0x64, 0x64, 0x43, 0x44, 0x6D, 0x59, 0x76, 0x6E,
        0x0A, 0x49, 0x31, 0x51, 0x36, 0x4A, 0x35, 0x71, 0x49, 0x4D, 0x37, 0x32, 0x49, 0x6A, 0x59, 0x75,
        0x66, 0x67, 0x55, 0x57, 0x32, 0x49, 0x33, 0x50, 0x55, 0x4B, 0x76, 0x62, 0x73, 0x48, 0x30, 0x38,
        0x71, 0x31, 0x6E, 0x77, 0x59, 0x62, 0x6E, 0x36, 0x4E, 0x48, 0x4F, 0x56, 0x59, 0x54, 0x31, 0x61,
        0x6D, 0x6A, 0x71, 0x4B, 0x6D, 0x58, 0x72, 0x70, 0x47, 0x68, 0x78, 0x69, 0x68, 0x59, 0x37, 0x42,
        0x76, 0x0A, 0x44, 0x41, 0x46, 0x39, 0x72, 0x55, 0x75, 0x5A, 0x30, 0x75, 0x75, 0x73, 0x7A, 0x78,
        0x6E, 0x59, 0x6A, 0x6C, 0x31, 0x69, 0x57, 0x43, 0x65, 0x44, 0x50, 0x45, 0x31, 0x30, 0x51, 0x6E,
        0x36, 0x69, 0x6D, 0x4A, 0x54, 0x46, 0x66, 0x6B, 0x5A, 0x31, 0x65, 0x6C, 0x38, 0x6F, 0x33, 0x56,
        0x4B, 0x6B, 0x46, 0x6F, 0x4C, 0x64, 0x53, 0x66, 0x6D, 0x4B, 0x30, 0x69, 0x6B, 0x37, 0x35, 0x5A,
        0x41, 0x66, 0x0A, 0x47, 0x70, 0x39, 0x70, 0x50, 0x66, 0x54, 0x56, 0x73, 0x42, 0x38, 0x36, 0x6D,
        0x71, 0x43, 0x46, 0x69, 0x31, 0x66, 0x53, 0x41, 0x2B, 0x38, 0x43, 0x67, 0x59, 0x41, 0x59, 0x36,
        0x73, 0x33, 0x76, 0x64, 0x58, 0x41, 0x72, 0x45, 0x71, 0x6F, 0x53, 0x6A, 0x41, 0x45, 0x39, 0x49,
        0x58, 0x53, 0x44, 0x4B, 0x4E, 0x54, 0x44, 0x63, 0x45, 0x79, 0x46, 0x66, 0x58, 0x76, 0x48, 0x78,
        0x4B, 0x58, 0x73, 0x0A, 0x67, 0x76, 0x72, 0x71, 0x72, 0x45, 0x57, 0x79, 0x59, 0x6E, 0x36, 0x63,
        0x4E, 0x64, 0x50, 0x58, 0x75, 0x64, 0x39, 0x4C, 0x52, 0x38, 0x30, 0x78, 0x55, 0x74, 0x31, 0x43,
        0x51, 0x32, 0x6B, 0x68, 0x33, 0x38, 0x67, 0x50, 0x5A, 0x55, 0x36, 0x6A, 0x67, 0x72, 0x59, 0x55,
        0x6F, 0x6F, 0x46, 0x66, 0x65, 0x6D, 0x67, 0x43, 0x66, 0x61, 0x64, 0x43, 0x63, 0x6E, 0x6D, 0x62,
        0x6D, 0x43, 0x58, 0x58, 0x0A, 0x68, 0x6B, 0x59, 0x64, 0x66, 0x64, 0x36, 0x63, 0x55, 0x34, 0x63,
        0x46, 0x38, 0x45, 0x6E, 0x69, 0x68, 0x2B, 0x48, 0x79, 0x75, 0x62, 0x62, 0x56, 0x67, 0x79, 0x38,
        0x31, 0x33, 0x58, 0x72, 0x34, 0x69, 0x61, 0x76, 0x32, 0x72, 0x65, 0x6B, 0x39, 0x33, 0x59, 0x32,
        0x78, 0x46, 0x48, 0x79, 0x2F, 0x6E, 0x6C, 0x37, 0x76, 0x4F, 0x41, 0x50, 0x46, 0x6E, 0x74, 0x61,
        0x79, 0x4D, 0x4B, 0x66, 0x41, 0x0A, 0x41, 0x48, 0x6F, 0x37, 0x77, 0x51, 0x4B, 0x42, 0x67, 0x42,
        0x31, 0x74, 0x75, 0x30, 0x63, 0x7A, 0x48, 0x75, 0x4F, 0x50, 0x35, 0x72, 0x7A, 0x31, 0x48, 0x54,
        0x4F, 0x6C, 0x6E, 0x36, 0x31, 0x57, 0x2F, 0x2B, 0x5A, 0x39, 0x59, 0x2F, 0x2B, 0x65, 0x6F, 0x70,
        0x79, 0x70, 0x53, 0x41, 0x4E, 0x57, 0x79, 0x6D, 0x59, 0x4C, 0x2B, 0x42, 0x58, 0x69, 0x6E, 0x6D,
        0x56, 0x38, 0x76, 0x41, 0x35, 0x54, 0x0A, 0x48, 0x31, 0x55, 0x75, 0x49, 0x78, 0x35, 0x41, 0x50,
        0x42, 0x6F, 0x41, 0x65, 0x68, 0x49, 0x35, 0x70, 0x35, 0x61, 0x4F, 0x4A, 0x2F, 0x59, 0x63, 0x41,
        0x61, 0x78, 0x55, 0x30, 0x4A, 0x44, 0x38, 0x37, 0x58, 0x6A, 0x37, 0x6E, 0x57, 0x48, 0x70, 0x56,
        0x50, 0x64, 0x4F, 0x59, 0x45, 0x66, 0x59, 0x6E, 0x79, 0x76, 0x67, 0x58, 0x6E, 0x41, 0x63, 0x67,
        0x4F, 0x63, 0x6D, 0x4F, 0x45, 0x4A, 0x74, 0x0A, 0x69, 0x32, 0x56, 0x6D, 0x2B, 0x6B, 0x4A, 0x52,
        0x65, 0x63, 0x44, 0x79, 0x4E, 0x49, 0x50, 0x45, 0x77, 0x61, 0x4F, 0x62, 0x79, 0x4F, 0x6C, 0x67,
        0x63, 0x5A, 0x6D, 0x6C, 0x52, 0x62, 0x6C, 0x72, 0x4F, 0x47, 0x77, 0x59, 0x73, 0x62, 0x70, 0x6B,
        0x55, 0x7A, 0x74, 0x74, 0x4E, 0x57, 0x78, 0x58, 0x43, 0x61, 0x49, 0x6C, 0x0A, 0x2D, 0x2D, 0x2D,
        0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54,
        0x45, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A
};
int PRIV_KEY_LEN = 1675;

#define PRIV_FILE_NAME "cert.der"    // AdeMike
unsigned char PRIV_KEY [] = {
        0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
        0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A, 0x4D, 0x49, 0x49, 0x44,
        0x57, 0x54, 0x43, 0x43, 0x41, 0x6B, 0x47, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x55,
        0x42, 0x56, 0x39, 0x2B, 0x48, 0x31, 0x35, 0x64, 0x67, 0x64, 0x59, 0x30, 0x34, 0x57, 0x37, 0x31,
        0x55, 0x54, 0x4D, 0x7A, 0x54, 0x6F, 0x74, 0x4E, 0x2B, 0x45, 0x41, 0x77, 0x44, 0x51, 0x59, 0x4A,
        0x4B, 0x6F, 0x5A, 0x49, 0x68, 0x76, 0x63, 0x4E, 0x41, 0x51, 0x45, 0x4C, 0x0A, 0x42, 0x51, 0x41,
        0x77, 0x54, 0x54, 0x46, 0x4C, 0x4D, 0x45, 0x6B, 0x47, 0x41, 0x31, 0x55, 0x45, 0x43, 0x77, 0x78,
        0x43, 0x51, 0x57, 0x31, 0x68, 0x65, 0x6D, 0x39, 0x75, 0x49, 0x46, 0x64, 0x6C, 0x59, 0x69, 0x42,
        0x54, 0x5A, 0x58, 0x4A, 0x32, 0x61, 0x57, 0x4E, 0x6C, 0x63, 0x79, 0x42, 0x50, 0x50, 0x55, 0x46,
        0x74, 0x59, 0x58, 0x70, 0x76, 0x62, 0x69, 0x35, 0x6A, 0x62, 0x32, 0x30, 0x67, 0x0A, 0x53, 0x57,
        0x35, 0x6A, 0x4C, 0x69, 0x42, 0x4D, 0x50, 0x56, 0x4E, 0x6C, 0x59, 0x58, 0x52, 0x30, 0x62, 0x47,
        0x55, 0x67, 0x55, 0x31, 0x51, 0x39, 0x56, 0x32, 0x46, 0x7A, 0x61, 0x47, 0x6C, 0x75, 0x5A, 0x33,
        0x52, 0x76, 0x62, 0x69, 0x42, 0x44, 0x50, 0x56, 0x56, 0x54, 0x4D, 0x42, 0x34, 0x58, 0x44, 0x54,
        0x45, 0x33, 0x4D, 0x44, 0x67, 0x77, 0x4D, 0x6A, 0x41, 0x35, 0x4D, 0x44, 0x41, 0x30, 0x0A, 0x4D,
        0x6C, 0x6F, 0x58, 0x44, 0x54, 0x51, 0x35, 0x4D, 0x54, 0x49, 0x7A, 0x4D, 0x54, 0x49, 0x7A, 0x4E,
        0x54, 0x6B, 0x31, 0x4F, 0x56, 0x6F, 0x77, 0x48, 0x6A, 0x45, 0x63, 0x4D, 0x42, 0x6F, 0x47, 0x41,
        0x31, 0x55, 0x45, 0x41, 0x77, 0x77, 0x54, 0x51, 0x56, 0x64, 0x54, 0x49, 0x45, 0x6C, 0x76, 0x56,
        0x43, 0x42, 0x44, 0x5A, 0x58, 0x4A, 0x30, 0x61, 0x57, 0x5A, 0x70, 0x59, 0x32, 0x46, 0x30, 0x0A,
        0x5A, 0x54, 0x43, 0x43, 0x41, 0x53, 0x49, 0x77, 0x44, 0x51, 0x59, 0x4A, 0x4B, 0x6F, 0x5A, 0x49,
        0x68, 0x76, 0x63, 0x4E, 0x41, 0x51, 0x45, 0x42, 0x42, 0x51, 0x41, 0x44, 0x67, 0x67, 0x45, 0x50,
        0x41, 0x44, 0x43, 0x43, 0x41, 0x51, 0x6F, 0x43, 0x67, 0x67, 0x45, 0x42, 0x41, 0x4B, 0x66, 0x57,
        0x44, 0x61, 0x32, 0x59, 0x45, 0x48, 0x59, 0x49, 0x61, 0x78, 0x36, 0x61, 0x55, 0x39, 0x43, 0x5A,
        0x0A, 0x72, 0x72, 0x55, 0x57, 0x70, 0x51, 0x43, 0x2F, 0x75, 0x65, 0x5A, 0x73, 0x32, 0x6D, 0x63,
        0x73, 0x6B, 0x63, 0x67, 0x6C, 0x77, 0x5A, 0x41, 0x46, 0x71, 0x32, 0x62, 0x32, 0x69, 0x46, 0x45,
        0x33, 0x6C, 0x32, 0x70, 0x74, 0x6B, 0x4B, 0x49, 0x6A, 0x44, 0x44, 0x36, 0x76, 0x44, 0x63, 0x33,
        0x50, 0x35, 0x71, 0x42, 0x41, 0x78, 0x63, 0x49, 0x5A, 0x51, 0x70, 0x44, 0x39, 0x4C, 0x53, 0x67,
        0x57, 0x0A, 0x71, 0x5A, 0x36, 0x45, 0x66, 0x6E, 0x41, 0x2B, 0x6B, 0x66, 0x38, 0x47, 0x73, 0x62,
        0x2F, 0x33, 0x6D, 0x46, 0x4D, 0x45, 0x33, 0x6C, 0x45, 0x71, 0x57, 0x66, 0x74, 0x73, 0x31, 0x46,
        0x56, 0x35, 0x53, 0x47, 0x5A, 0x45, 0x4E, 0x38, 0x4C, 0x73, 0x6B, 0x42, 0x31, 0x45, 0x31, 0x64,
        0x50, 0x34, 0x7A, 0x4E, 0x42, 0x67, 0x52, 0x49, 0x76, 0x68, 0x31, 0x6A, 0x65, 0x4B, 0x44, 0x49,
        0x6A, 0x77, 0x0A, 0x6F, 0x47, 0x43, 0x4E, 0x65, 0x73, 0x62, 0x56, 0x4E, 0x79, 0x33, 0x53, 0x46,
        0x33, 0x39, 0x75, 0x79, 0x30, 0x53, 0x48, 0x79, 0x6E, 0x53, 0x2F, 0x68, 0x4E, 0x2F, 0x69, 0x4D,
        0x4F, 0x52, 0x2B, 0x32, 0x45, 0x4F, 0x31, 0x41, 0x43, 0x4C, 0x47, 0x73, 0x62, 0x6A, 0x41, 0x47,
        0x70, 0x46, 0x4A, 0x45, 0x69, 0x43, 0x4B, 0x78, 0x2B, 0x45, 0x6B, 0x67, 0x43, 0x6E, 0x2F, 0x72,
        0x6B, 0x4B, 0x4F, 0x0A, 0x4C, 0x67, 0x57, 0x2F, 0x64, 0x52, 0x61, 0x49, 0x56, 0x44, 0x65, 0x30,
        0x46, 0x57, 0x43, 0x66, 0x44, 0x63, 0x33, 0x38, 0x74, 0x62, 0x77, 0x39, 0x78, 0x50, 0x4E, 0x38,
        0x2B, 0x66, 0x67, 0x2F, 0x6F, 0x65, 0x72, 0x53, 0x5A, 0x68, 0x55, 0x4A, 0x47, 0x54, 0x2F, 0x74,
        0x34, 0x4B, 0x48, 0x78, 0x34, 0x71, 0x49, 0x56, 0x72, 0x4A, 0x41, 0x59, 0x4A, 0x37, 0x79, 0x39,
        0x7A, 0x33, 0x38, 0x70, 0x0A, 0x31, 0x34, 0x42, 0x59, 0x36, 0x75, 0x6E, 0x78, 0x6B, 0x57, 0x66,
        0x6F, 0x70, 0x6F, 0x77, 0x75, 0x78, 0x6B, 0x4B, 0x78, 0x6A, 0x56, 0x41, 0x66, 0x68, 0x5A, 0x35,
        0x6C, 0x2B, 0x75, 0x52, 0x46, 0x73, 0x51, 0x46, 0x70, 0x49, 0x5A, 0x55, 0x72, 0x73, 0x6A, 0x66,
        0x76, 0x52, 0x53, 0x62, 0x47, 0x2F, 0x42, 0x78, 0x6A, 0x32, 0x2F, 0x45, 0x6B, 0x67, 0x46, 0x54,
        0x37, 0x4C, 0x6B, 0x44, 0x46, 0x0A, 0x6B, 0x36, 0x38, 0x43, 0x41, 0x77, 0x45, 0x41, 0x41, 0x61,
        0x4E, 0x67, 0x4D, 0x46, 0x34, 0x77, 0x48, 0x77, 0x59, 0x44, 0x56, 0x52, 0x30, 0x6A, 0x42, 0x42,
        0x67, 0x77, 0x46, 0x6F, 0x41, 0x55, 0x38, 0x75, 0x5A, 0x6A, 0x4F, 0x4D, 0x79, 0x6A, 0x39, 0x46,
        0x35, 0x59, 0x6F, 0x51, 0x30, 0x6C, 0x34, 0x70, 0x71, 0x6A, 0x62, 0x59, 0x76, 0x33, 0x43, 0x64,
        0x6B, 0x77, 0x48, 0x51, 0x59, 0x44, 0x0A, 0x56, 0x52, 0x30, 0x4F, 0x42, 0x42, 0x59, 0x45, 0x46,
        0x46, 0x65, 0x38, 0x68, 0x4E, 0x53, 0x65, 0x32, 0x47, 0x62, 0x67, 0x39, 0x32, 0x48, 0x57, 0x58,
        0x78, 0x49, 0x67, 0x59, 0x62, 0x71, 0x74, 0x70, 0x53, 0x4F, 0x42, 0x4D, 0x41, 0x77, 0x47, 0x41,
        0x31, 0x55, 0x64, 0x45, 0x77, 0x45, 0x42, 0x2F, 0x77, 0x51, 0x43, 0x4D, 0x41, 0x41, 0x77, 0x44,
        0x67, 0x59, 0x44, 0x56, 0x52, 0x30, 0x50, 0x0A, 0x41, 0x51, 0x48, 0x2F, 0x42, 0x41, 0x51, 0x44,
        0x41, 0x67, 0x65, 0x41, 0x4D, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33,
        0x44, 0x51, 0x45, 0x42, 0x43, 0x77, 0x55, 0x41, 0x41, 0x34, 0x49, 0x42, 0x41, 0x51, 0x42, 0x57,
        0x62, 0x46, 0x57, 0x74, 0x73, 0x79, 0x61, 0x61, 0x45, 0x37, 0x4D, 0x75, 0x30, 0x38, 0x67, 0x36,
        0x75, 0x50, 0x75, 0x4B, 0x66, 0x6D, 0x33, 0x63, 0x0A, 0x65, 0x5A, 0x51, 0x57, 0x2B, 0x59, 0x50,
        0x71, 0x47, 0x4E, 0x66, 0x64, 0x6E, 0x42, 0x59, 0x72, 0x34, 0x2F, 0x30, 0x6C, 0x55, 0x43, 0x2B,
        0x62, 0x44, 0x6F, 0x72, 0x66, 0x7A, 0x75, 0x2B, 0x74, 0x74, 0x5A, 0x59, 0x6E, 0x44, 0x33, 0x6E,
        0x42, 0x49, 0x69, 0x56, 0x70, 0x62, 0x4A, 0x36, 0x48, 0x64, 0x70, 0x46, 0x6E, 0x6A, 0x34, 0x4B,
        0x53, 0x51, 0x2B, 0x54, 0x67, 0x59, 0x7A, 0x2B, 0x41, 0x0A, 0x35, 0x7A, 0x58, 0x30, 0x6C, 0x75,
        0x56, 0x4D, 0x44, 0x67, 0x6B, 0x49, 0x41, 0x66, 0x2F, 0x52, 0x35, 0x5A, 0x47, 0x51, 0x77, 0x53,
        0x4C, 0x74, 0x34, 0x50, 0x4F, 0x65, 0x38, 0x62, 0x52, 0x5A, 0x69, 0x32, 0x6A, 0x76, 0x48, 0x30,
        0x4C, 0x6D, 0x48, 0x43, 0x46, 0x38, 0x32, 0x6F, 0x2B, 0x4F, 0x35, 0x6F, 0x69, 0x6A, 0x64, 0x6E,
        0x63, 0x6A, 0x5A, 0x6C, 0x4C, 0x45, 0x74, 0x62, 0x63, 0x39, 0x0A, 0x4A, 0x70, 0x49, 0x74, 0x30,
        0x57, 0x61, 0x68, 0x64, 0x51, 0x66, 0x47, 0x65, 0x50, 0x69, 0x74, 0x39, 0x33, 0x58, 0x51, 0x65,
        0x6A, 0x6C, 0x68, 0x56, 0x44, 0x54, 0x4B, 0x36, 0x59, 0x36, 0x66, 0x68, 0x35, 0x37, 0x69, 0x2B,
        0x41, 0x58, 0x6B, 0x6E, 0x37, 0x4E, 0x36, 0x4C, 0x73, 0x6E, 0x49, 0x52, 0x65, 0x36, 0x6C, 0x50,
        0x4C, 0x77, 0x46, 0x68, 0x6F, 0x5A, 0x71, 0x66, 0x57, 0x4F, 0x46, 0x0A, 0x78, 0x7A, 0x7A, 0x4B,
        0x5A, 0x44, 0x65, 0x38, 0x6D, 0x4C, 0x63, 0x71, 0x64, 0x49, 0x36, 0x5A, 0x45, 0x70, 0x36, 0x4D,
        0x41, 0x2B, 0x46, 0x73, 0x74, 0x56, 0x4E, 0x4F, 0x7A, 0x2B, 0x59, 0x4E, 0x54, 0x64, 0x7A, 0x51,
        0x31, 0x36, 0x62, 0x77, 0x56, 0x76, 0x37, 0x68, 0x6F, 0x53, 0x56, 0x32, 0x57, 0x66, 0x33, 0x6B,
        0x36, 0x32, 0x4E, 0x46, 0x7A, 0x58, 0x73, 0x63, 0x35, 0x35, 0x6E, 0x47, 0x0A, 0x35, 0x6F, 0x57,
        0x31, 0x46, 0x76, 0x6B, 0x53, 0x41, 0x75, 0x67, 0x35, 0x42, 0x73, 0x74, 0x2B, 0x50, 0x38, 0x45,
        0x6A, 0x70, 0x36, 0x65, 0x41, 0x50, 0x77, 0x78, 0x47, 0x4B, 0x32, 0x42, 0x37, 0x43, 0x72, 0x72,
        0x35, 0x5A, 0x47, 0x53, 0x67, 0x6E, 0x5A, 0x41, 0x6C, 0x56, 0x74, 0x4E, 0x73, 0x67, 0x74, 0x49,
        0x55, 0x49, 0x37, 0x6D, 0x38, 0x72, 0x58, 0x2B, 0x33, 0x0A, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45,
        0x4E, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D,
        0x2D, 0x2D, 0x2D, 0x0A
};
int PRIV_KEY_LEN = 1220;

#define PRIV_FILE_NAME "aws-iot-rootCA.der"    // AdeMike
unsigned char PRIV_KEY [] = {
        0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
        0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0D, 0x0A, 0x4D, 0x49, 0x49,
        0x45, 0x30, 0x7A, 0x43, 0x43, 0x41, 0x37, 0x75, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49,
        0x51, 0x47, 0x4E, 0x72, 0x52, 0x6E, 0x69, 0x5A, 0x39, 0x36, 0x4C, 0x74, 0x4B, 0x49, 0x56, 0x6A,
        0x4E, 0x7A, 0x47, 0x73, 0x37, 0x53, 0x6A, 0x41, 0x4E, 0x42, 0x67, 0x6B, 0x71, 0x68, 0x6B, 0x69,
        0x47, 0x39, 0x77, 0x30, 0x42, 0x41, 0x51, 0x55, 0x46, 0x41, 0x44, 0x43, 0x42, 0x0D, 0x0A, 0x79,
        0x6A, 0x45, 0x4C, 0x4D, 0x41, 0x6B, 0x47, 0x41, 0x31, 0x55, 0x45, 0x42, 0x68, 0x4D, 0x43, 0x56,
        0x56, 0x4D, 0x78, 0x46, 0x7A, 0x41, 0x56, 0x42, 0x67, 0x4E, 0x56, 0x42, 0x41, 0x6F, 0x54, 0x44,
        0x6C, 0x5A, 0x6C, 0x63, 0x6D, 0x6C, 0x54, 0x61, 0x57, 0x64, 0x75, 0x4C, 0x43, 0x42, 0x4A, 0x62,
        0x6D, 0x4D, 0x75, 0x4D, 0x52, 0x38, 0x77, 0x48, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4C, 0x0D,
        0x0A, 0x45, 0x78, 0x5A, 0x57, 0x5A, 0x58, 0x4A, 0x70, 0x55, 0x32, 0x6C, 0x6E, 0x62, 0x69, 0x42,
        0x55, 0x63, 0x6E, 0x56, 0x7A, 0x64, 0x43, 0x42, 0x4F, 0x5A, 0x58, 0x52, 0x33, 0x62, 0x33, 0x4A,
        0x72, 0x4D, 0x54, 0x6F, 0x77, 0x4F, 0x41, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4C, 0x45, 0x7A, 0x45,
        0x6F, 0x59, 0x79, 0x6B, 0x67, 0x4D, 0x6A, 0x41, 0x77, 0x4E, 0x69, 0x42, 0x57, 0x5A, 0x58, 0x4A,
        0x70, 0x0D, 0x0A, 0x55, 0x32, 0x6C, 0x6E, 0x62, 0x69, 0x77, 0x67, 0x53, 0x57, 0x35, 0x6A, 0x4C,
        0x69, 0x41, 0x74, 0x49, 0x45, 0x5A, 0x76, 0x63, 0x69, 0x42, 0x68, 0x64, 0x58, 0x52, 0x6F, 0x62,
        0x33, 0x4A, 0x70, 0x65, 0x6D, 0x56, 0x6B, 0x49, 0x48, 0x56, 0x7A, 0x5A, 0x53, 0x42, 0x76, 0x62,
        0x6D, 0x78, 0x35, 0x4D, 0x55, 0x55, 0x77, 0x51, 0x77, 0x59, 0x44, 0x56, 0x51, 0x51, 0x44, 0x45,
        0x7A, 0x78, 0x57, 0x0D, 0x0A, 0x5A, 0x58, 0x4A, 0x70, 0x55, 0x32, 0x6C, 0x6E, 0x62, 0x69, 0x42,
        0x44, 0x62, 0x47, 0x46, 0x7A, 0x63, 0x79, 0x41, 0x7A, 0x49, 0x46, 0x42, 0x31, 0x59, 0x6D, 0x78,
        0x70, 0x59, 0x79, 0x42, 0x51, 0x63, 0x6D, 0x6C, 0x74, 0x59, 0x58, 0x4A, 0x35, 0x49, 0x45, 0x4E,
        0x6C, 0x63, 0x6E, 0x52, 0x70, 0x5A, 0x6D, 0x6C, 0x6A, 0x59, 0x58, 0x52, 0x70, 0x62, 0x32, 0x34,
        0x67, 0x51, 0x58, 0x56, 0x30, 0x0D, 0x0A, 0x61, 0x47, 0x39, 0x79, 0x61, 0x58, 0x52, 0x35, 0x49,
        0x43, 0x30, 0x67, 0x52, 0x7A, 0x55, 0x77, 0x48, 0x68, 0x63, 0x4E, 0x4D, 0x44, 0x59, 0x78, 0x4D,
        0x54, 0x41, 0x34, 0x4D, 0x44, 0x41, 0x77, 0x4D, 0x44, 0x41, 0x77, 0x57, 0x68, 0x63, 0x4E, 0x4D,
        0x7A, 0x59, 0x77, 0x4E, 0x7A, 0x45, 0x32, 0x4D, 0x6A, 0x4D, 0x31, 0x4F, 0x54, 0x55, 0x35, 0x57,
        0x6A, 0x43, 0x42, 0x79, 0x6A, 0x45, 0x4C, 0x0D, 0x0A, 0x4D, 0x41, 0x6B, 0x47, 0x41, 0x31, 0x55,
        0x45, 0x42, 0x68, 0x4D, 0x43, 0x56, 0x56, 0x4D, 0x78, 0x46, 0x7A, 0x41, 0x56, 0x42, 0x67, 0x4E,
        0x56, 0x42, 0x41, 0x6F, 0x54, 0x44, 0x6C, 0x5A, 0x6C, 0x63, 0x6D, 0x6C, 0x54, 0x61, 0x57, 0x64,
        0x75, 0x4C, 0x43, 0x42, 0x4A, 0x62, 0x6D, 0x4D, 0x75, 0x4D, 0x52, 0x38, 0x77, 0x48, 0x51, 0x59,
        0x44, 0x56, 0x51, 0x51, 0x4C, 0x45, 0x78, 0x5A, 0x57, 0x0D, 0x0A, 0x5A, 0x58, 0x4A, 0x70, 0x55,
        0x32, 0x6C, 0x6E, 0x62, 0x69, 0x42, 0x55, 0x63, 0x6E, 0x56, 0x7A, 0x64, 0x43, 0x42, 0x4F, 0x5A,
        0x58, 0x52, 0x33, 0x62, 0x33, 0x4A, 0x72, 0x4D, 0x54, 0x6F, 0x77, 0x4F, 0x41, 0x59, 0x44, 0x56,
        0x51, 0x51, 0x4C, 0x45, 0x7A, 0x45, 0x6F, 0x59, 0x79, 0x6B, 0x67, 0x4D, 0x6A, 0x41, 0x77, 0x4E,
        0x69, 0x42, 0x57, 0x5A, 0x58, 0x4A, 0x70, 0x55, 0x32, 0x6C, 0x6E, 0x0D, 0x0A, 0x62, 0x69, 0x77,
        0x67, 0x53, 0x57, 0x35, 0x6A, 0x4C, 0x69, 0x41, 0x74, 0x49, 0x45, 0x5A, 0x76, 0x63, 0x69, 0x42,
        0x68, 0x64, 0x58, 0x52, 0x6F, 0x62, 0x33, 0x4A, 0x70, 0x65, 0x6D, 0x56, 0x6B, 0x49, 0x48, 0x56,
        0x7A, 0x5A, 0x53, 0x42, 0x76, 0x62, 0x6D, 0x78, 0x35, 0x4D, 0x55, 0x55, 0x77, 0x51, 0x77, 0x59,
        0x44, 0x56, 0x51, 0x51, 0x44, 0x45, 0x7A, 0x78, 0x57, 0x5A, 0x58, 0x4A, 0x70, 0x0D, 0x0A, 0x55,
        0x32, 0x6C, 0x6E, 0x62, 0x69, 0x42, 0x44, 0x62, 0x47, 0x46, 0x7A, 0x63, 0x79, 0x41, 0x7A, 0x49,
        0x46, 0x42, 0x31, 0x59, 0x6D, 0x78, 0x70, 0x59, 0x79, 0x42, 0x51, 0x63, 0x6D, 0x6C, 0x74, 0x59,
        0x58, 0x4A, 0x35, 0x49, 0x45, 0x4E, 0x6C, 0x63, 0x6E, 0x52, 0x70, 0x5A, 0x6D, 0x6C, 0x6A, 0x59,
        0x58, 0x52, 0x70, 0x62, 0x32, 0x34, 0x67, 0x51, 0x58, 0x56, 0x30, 0x61, 0x47, 0x39, 0x79, 0x0D,
        0x0A, 0x61, 0x58, 0x52, 0x35, 0x49, 0x43, 0x30, 0x67, 0x52, 0x7A, 0x55, 0x77, 0x67, 0x67, 0x45,
        0x69, 0x4D, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45,
        0x42, 0x41, 0x51, 0x55, 0x41, 0x41, 0x34, 0x49, 0x42, 0x44, 0x77, 0x41, 0x77, 0x67, 0x67, 0x45,
        0x4B, 0x41, 0x6F, 0x49, 0x42, 0x41, 0x51, 0x43, 0x76, 0x4A, 0x41, 0x67, 0x49, 0x4B, 0x58, 0x6F,
        0x31, 0x0D, 0x0A, 0x6E, 0x6D, 0x41, 0x4D, 0x71, 0x75, 0x64, 0x4C, 0x4F, 0x30, 0x37, 0x63, 0x66,
        0x4C, 0x77, 0x38, 0x52, 0x52, 0x79, 0x37, 0x4B, 0x2B, 0x44, 0x2B, 0x4B, 0x51, 0x4C, 0x35, 0x56,
        0x77, 0x69, 0x6A, 0x5A, 0x49, 0x55, 0x56, 0x4A, 0x2F, 0x58, 0x78, 0x72, 0x63, 0x67, 0x78, 0x69,
        0x56, 0x30, 0x69, 0x36, 0x43, 0x71, 0x71, 0x70, 0x6B, 0x4B, 0x7A, 0x6A, 0x2F, 0x69, 0x35, 0x56,
        0x62, 0x65, 0x78, 0x0D, 0x0A, 0x74, 0x30, 0x75, 0x7A, 0x2F, 0x6F, 0x39, 0x2B, 0x42, 0x31, 0x66,
        0x73, 0x37, 0x30, 0x50, 0x62, 0x5A, 0x6D, 0x49, 0x56, 0x59, 0x63, 0x39, 0x67, 0x44, 0x61, 0x54,
        0x59, 0x33, 0x76, 0x6A, 0x67, 0x77, 0x32, 0x49, 0x49, 0x50, 0x56, 0x51, 0x54, 0x36, 0x30, 0x6E,
        0x4B, 0x57, 0x56, 0x53, 0x46, 0x4A, 0x75, 0x55, 0x72, 0x6A, 0x78, 0x75, 0x66, 0x36, 0x2F, 0x57,
        0x68, 0x6B, 0x63, 0x49, 0x7A, 0x0D, 0x0A, 0x53, 0x64, 0x68, 0x44, 0x59, 0x32, 0x70, 0x53, 0x53,
        0x39, 0x4B, 0x50, 0x36, 0x48, 0x42, 0x52, 0x54, 0x64, 0x47, 0x4A, 0x61, 0x58, 0x76, 0x48, 0x63,
        0x50, 0x61, 0x7A, 0x33, 0x42, 0x4A, 0x30, 0x32, 0x33, 0x74, 0x64, 0x53, 0x31, 0x62, 0x54, 0x6C,
        0x72, 0x38, 0x56, 0x64, 0x36, 0x47, 0x77, 0x39, 0x4B, 0x49, 0x6C, 0x38, 0x71, 0x38, 0x63, 0x6B,
        0x6D, 0x63, 0x59, 0x35, 0x66, 0x51, 0x47, 0x0D, 0x0A, 0x42, 0x4F, 0x2B, 0x51, 0x75, 0x65, 0x51,
        0x41, 0x35, 0x4E, 0x30, 0x36, 0x74, 0x52, 0x6E, 0x2F, 0x41, 0x72, 0x72, 0x30, 0x50, 0x4F, 0x37,
        0x67, 0x69, 0x2B, 0x73, 0x33, 0x69, 0x2B, 0x7A, 0x30, 0x31, 0x36, 0x7A, 0x79, 0x39, 0x76, 0x41,
        0x39, 0x72, 0x39, 0x31, 0x31, 0x6B, 0x54, 0x4D, 0x5A, 0x48, 0x52, 0x78, 0x41, 0x79, 0x33, 0x51,
        0x6B, 0x47, 0x53, 0x47, 0x54, 0x32, 0x52, 0x54, 0x2B, 0x0D, 0x0A, 0x72, 0x43, 0x70, 0x53, 0x78,
        0x34, 0x2F, 0x56, 0x42, 0x45, 0x6E, 0x6B, 0x6A, 0x57, 0x4E, 0x48, 0x69, 0x44, 0x78, 0x70, 0x67,
        0x38, 0x76, 0x2B, 0x52, 0x37, 0x30, 0x72, 0x66, 0x6B, 0x2F, 0x46, 0x6C, 0x61, 0x34, 0x4F, 0x6E,
        0x64, 0x54, 0x52, 0x51, 0x38, 0x42, 0x6E, 0x63, 0x2B, 0x4D, 0x55, 0x43, 0x48, 0x37, 0x6C, 0x50,
        0x35, 0x39, 0x7A, 0x75, 0x44, 0x4D, 0x4B, 0x7A, 0x31, 0x30, 0x2F, 0x0D, 0x0A, 0x4E, 0x49, 0x65,
        0x57, 0x69, 0x75, 0x35, 0x54, 0x36, 0x43, 0x55, 0x56, 0x41, 0x67, 0x4D, 0x42, 0x41, 0x41, 0x47,
        0x6A, 0x67, 0x62, 0x49, 0x77, 0x67, 0x61, 0x38, 0x77, 0x44, 0x77, 0x59, 0x44, 0x56, 0x52, 0x30,
        0x54, 0x41, 0x51, 0x48, 0x2F, 0x42, 0x41, 0x55, 0x77, 0x41, 0x77, 0x45, 0x42, 0x2F, 0x7A, 0x41,
        0x4F, 0x42, 0x67, 0x4E, 0x56, 0x48, 0x51, 0x38, 0x42, 0x41, 0x66, 0x38, 0x45, 0x0D, 0x0A, 0x42,
        0x41, 0x4D, 0x43, 0x41, 0x51, 0x59, 0x77, 0x62, 0x51, 0x59, 0x49, 0x4B, 0x77, 0x59, 0x42, 0x42,
        0x51, 0x55, 0x48, 0x41, 0x51, 0x77, 0x45, 0x59, 0x54, 0x42, 0x66, 0x6F, 0x56, 0x32, 0x67, 0x57,
        0x7A, 0x42, 0x5A, 0x4D, 0x46, 0x63, 0x77, 0x56, 0x52, 0x59, 0x4A, 0x61, 0x57, 0x31, 0x68, 0x5A,
        0x32, 0x55, 0x76, 0x5A, 0x32, 0x6C, 0x6D, 0x4D, 0x43, 0x45, 0x77, 0x48, 0x7A, 0x41, 0x48, 0x0D,
        0x0A, 0x42, 0x67, 0x55, 0x72, 0x44, 0x67, 0x4D, 0x43, 0x47, 0x67, 0x51, 0x55, 0x6A, 0x2B, 0x58,
        0x54, 0x47, 0x6F, 0x61, 0x73, 0x6A, 0x59, 0x35, 0x72, 0x77, 0x38, 0x2B, 0x41, 0x61, 0x74, 0x52,
        0x49, 0x47, 0x43, 0x78, 0x37, 0x47, 0x53, 0x34, 0x77, 0x4A, 0x52, 0x59, 0x6A, 0x61, 0x48, 0x52,
        0x30, 0x63, 0x44, 0x6F, 0x76, 0x4C, 0x32, 0x78, 0x76, 0x5A, 0x32, 0x38, 0x75, 0x64, 0x6D, 0x56,
        0x79, 0x0D, 0x0A, 0x61, 0x58, 0x4E, 0x70, 0x5A, 0x32, 0x34, 0x75, 0x59, 0x32, 0x39, 0x74, 0x4C,
        0x33, 0x5A, 0x7A, 0x62, 0x47, 0x39, 0x6E, 0x62, 0x79, 0x35, 0x6E, 0x61, 0x57, 0x59, 0x77, 0x48,
        0x51, 0x59, 0x44, 0x56, 0x52, 0x30, 0x4F, 0x42, 0x42, 0x59, 0x45, 0x46, 0x48, 0x2F, 0x54, 0x5A,
        0x61, 0x66, 0x43, 0x33, 0x65, 0x79, 0x37, 0x38, 0x44, 0x41, 0x4A, 0x38, 0x30, 0x4D, 0x35, 0x2B,
        0x67, 0x4B, 0x76, 0x0D, 0x0A, 0x4D, 0x7A, 0x45, 0x7A, 0x4D, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71,
        0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45, 0x42, 0x42, 0x51, 0x55, 0x41, 0x41, 0x34, 0x49,
        0x42, 0x41, 0x51, 0x43, 0x54, 0x4A, 0x45, 0x6F, 0x77, 0x58, 0x32, 0x4C, 0x50, 0x32, 0x42, 0x71,
        0x59, 0x4C, 0x7A, 0x33, 0x71, 0x33, 0x4A, 0x6B, 0x74, 0x76, 0x58, 0x66, 0x32, 0x70, 0x58, 0x6B,
        0x69, 0x4F, 0x4F, 0x7A, 0x45, 0x0D, 0x0A, 0x70, 0x36, 0x42, 0x34, 0x45, 0x71, 0x31, 0x69, 0x44,
        0x6B, 0x56, 0x77, 0x5A, 0x4D, 0x58, 0x6E, 0x6C, 0x32, 0x59, 0x74, 0x6D, 0x41, 0x6C, 0x2B, 0x58,
        0x36, 0x2F, 0x57, 0x7A, 0x43, 0x68, 0x6C, 0x38, 0x67, 0x47, 0x71, 0x43, 0x42, 0x70, 0x48, 0x33,
        0x76, 0x6E, 0x35, 0x66, 0x4A, 0x4A, 0x61, 0x43, 0x47, 0x6B, 0x67, 0x44, 0x64, 0x6B, 0x2B, 0x62,
        0x57, 0x34, 0x38, 0x44, 0x57, 0x37, 0x59, 0x0D, 0x0A, 0x35, 0x67, 0x61, 0x52, 0x51, 0x42, 0x69,
        0x35, 0x2B, 0x4D, 0x48, 0x74, 0x33, 0x39, 0x74, 0x42, 0x71, 0x75, 0x43, 0x57, 0x49, 0x4D, 0x6E,
        0x4E, 0x5A, 0x42, 0x55, 0x34, 0x67, 0x63, 0x6D, 0x55, 0x37, 0x71, 0x4B, 0x45, 0x4B, 0x51, 0x73,
        0x54, 0x62, 0x34, 0x37, 0x62, 0x44, 0x4E, 0x30, 0x6C, 0x41, 0x74, 0x75, 0x6B, 0x69, 0x78, 0x6C,
        0x45, 0x30, 0x6B, 0x46, 0x36, 0x42, 0x57, 0x6C, 0x4B, 0x0D, 0x0A, 0x57, 0x45, 0x39, 0x67, 0x79,
        0x6E, 0x36, 0x43, 0x61, 0x67, 0x73, 0x43, 0x71, 0x69, 0x55, 0x58, 0x4F, 0x62, 0x58, 0x62, 0x66,
        0x2B, 0x65, 0x45, 0x5A, 0x53, 0x71, 0x56, 0x69, 0x72, 0x32, 0x47, 0x33, 0x6C, 0x36, 0x42, 0x46,
        0x6F, 0x4D, 0x74, 0x45, 0x4D, 0x7A, 0x65, 0x2F, 0x61, 0x69, 0x43, 0x4B, 0x6D, 0x30, 0x6F, 0x48,
        0x77, 0x30, 0x4C, 0x78, 0x4F, 0x58, 0x6E, 0x47, 0x69, 0x59, 0x5A, 0x0D, 0x0A, 0x34, 0x66, 0x51,
        0x52, 0x62, 0x78, 0x43, 0x31, 0x6C, 0x66, 0x7A, 0x6E, 0x51, 0x67, 0x55, 0x79, 0x32, 0x38, 0x36,
        0x64, 0x55, 0x56, 0x34, 0x6F, 0x74, 0x70, 0x36, 0x46, 0x30, 0x31, 0x76, 0x76, 0x70, 0x58, 0x31,
        0x46, 0x51, 0x48, 0x4B, 0x4F, 0x74, 0x77, 0x35, 0x72, 0x44, 0x67, 0x62, 0x37, 0x4D, 0x7A, 0x56,
        0x49, 0x63, 0x62, 0x69, 0x64, 0x4A, 0x34, 0x76, 0x45, 0x5A, 0x56, 0x38, 0x4E, 0x0D, 0x0A, 0x68,
        0x6E, 0x61, 0x63, 0x52, 0x48, 0x72, 0x32, 0x6C, 0x56, 0x7A, 0x32, 0x58, 0x54, 0x49, 0x49, 0x4D,
        0x36, 0x52, 0x55, 0x74, 0x68, 0x67, 0x2F, 0x61, 0x46, 0x7A, 0x79, 0x51, 0x6B, 0x71, 0x46, 0x4F,
        0x46, 0x53, 0x44, 0x58, 0x39, 0x48, 0x6F, 0x4C, 0x50, 0x4B, 0x73, 0x45, 0x64, 0x61, 0x6F, 0x37,
        0x57, 0x4E, 0x71, 0x0D, 0x0A, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x43, 0x45,
        0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D
};
int PRIV_KEY_LEN = 1758;

/* local variables ********************************************************** */
// Buffers
static unsigned char buf[CLIENT_BUFF_SIZE];
static unsigned char readbuf[CLIENT_BUFF_SIZE];

// Client Task/Timer Variables
static xTimerHandle     clientStreamTimerHandle      = POINTER_NULL;  // timer handle for data stream
static xTaskHandle      clientTaskHandler            = POINTER_NULL;  // task handle for MQTT Client
static uint8_t clientDataGetFlag = NUMBER_UINT8_ZERO;
static uint32_t clientMessageId = 0;

// Subscribe topics variables
char clientTopicRed[CLIENT_BUFF_SIZE];
char clientTopicOrange[CLIENT_BUFF_SIZE];
char clientTopicYellow[CLIENT_BUFF_SIZE];
char clientTopicDataGet[CLIENT_BUFF_SIZE];
char clientTopicDataStream[CLIENT_BUFF_SIZE];
const char *clientTopicRed_ptr = TOPIC_LED_RED;
const char *clientTopicOrange_ptr = TOPIC_LED_ORANGE;
const char *clientTopicYellow_ptr = TOPIC_LED_YELLOW;
const char *clientTopicDataGet_ptr = TOPIC_DATA_GET;
const char *clientTopicDataStream_ptr = TOPIC_DATA_STREAM;

/* global variables ********************************************************* */

/*************** Step 2 ***************/
/* Create a global variable of type SlSockSecureFiles_t, called certificates. */
SISockSecureFiles_t certificates;    // AdeMike

// Network and Client Configuration
Network n;
Client c;

/* inline functions ********************************************************* */

/* local functions ********************************************************** */
static void clientRecv(MessageData* md);
static void clientTask(void *pvParameters);

/**
 * @brief callback function for subriptions
 *        toggles LEDS or sets read data flag
 *
 * @param[in] md - received message from the MQTT Broker
 *
 * @return NONE
 */
static void clientRecv(MessageData* md)
{
    /* Initialize Variables */
    MQTTMessage* message = md->message;

    if((strncmp(md->topicName->lenstring.data, clientTopicRed_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
        PTD_pinOutToggle(PTD_PORT_LED_RED, PTD_PIN_LED_RED);
    }
    else if((strncmp(md->topicName->lenstring.data, clientTopicOrange_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
        PTD_pinOutToggle(PTD_PORT_LED_ORANGE, PTD_PIN_LED_ORANGE);
    }
    else if((strncmp(md->topicName->lenstring.data, clientTopicYellow_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
        PTD_pinOutToggle(PTD_PORT_LED_YELLOW, PTD_PIN_LED_YELLOW);
    }
    else if((strncmp(md->topicName->lenstring.data, clientTopicDataGet_ptr, md->topicName->lenstring.len) == 0)) {
        /* Immediately Stream the Sensor Data */
        clientDataGetFlag = (uint8_t) ENABLED;
    }

    printf("Subscribed Topic, %.*s, Message Received: %.*s\r\n", md->topicName->lenstring.len, md->topicName->lenstring.data,
                                                               (int)message->payloadlen, (char*)message->payload);
}

/**
 * @brief publish sensor data, get sensor data, or
 *        yield mqtt client to check subscriptions
 *
 * @param[in] pvParameters UNUSED/PASSED THROUGH
 *
 * @return NONE
 */
static void clientTask(void *pvParameters)
{
    /* Initialize Variables */
    MQTTMessage msg;

    /* Forever Loop Necessary for freeRTOS Task */
    for(;;)
    {
        WDG_feedingWatchdog();
        /* Publish Live Data Stream */
        if(sensorStreamBuffer.length > NUMBER_UINT32_ZERO)
        {
            msg.id = clientMessageId++;
            msg.qos = 0;
            msg.payload = sensorStreamBuffer.data;
            msg.payloadlen = sensorStreamBuffer.length;
            MQTTPublish(&c, clientTopicDataStream_ptr, &msg);

            memset(sensorStreamBuffer.data, 0x00, SENSOR_DATA_BUF_SIZE);
            sensorStreamBuffer.length = NUMBER_UINT32_ZERO;
        }
        else if(clientDataGetFlag) {
            sensorStreamData(pvParameters);
            clientDataGetFlag = DISABLED;
        }
        else {
            MQTTYield(&c, CLIENT_YIELD_TIMEOUT);
        }
    }
}

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

/**
 * @brief starts the data streaming timer
 *
 * @return NONE
 */
void clientStartTimer(void)
{
    /* Start the timers */
    xTimerStart(clientStreamTimerHandle, UINT32_MAX);
    return;
}
/**
 * @brief stops the data streaming timer
 *
 * @return NONE
 */
void clientStopTimer(void)
{
    /* Stop the timers */
    xTimerStop(clientStreamTimerHandle, UINT32_MAX);
    return;
}

/**
 * @brief Initializes the MQTT Paho Client, set up subscriptions and initializes the timers and tasks
 *
 * @return NONE
 */
void clientInit(void)
{
    /* Initialize Variables */
    int rc = 0;
    NewNetwork(&n);

    /*************** Step 3 ***************/
    flashCertificates();        // AdeMike
    // ConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT);

    /*************** Step 4 ***************/
    TLSConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT, certificates, SL_SO_SEC_METHOD_TLSV1_2, NULL, 0);    // AdeMike
    MQTTClient(&c, &n, 1000, buf, CLIENT_BUFF_SIZE, readbuf, CLIENT_BUFF_SIZE);

    // AdeMike from HTTPS

    /*************** Step 5 ***************/
    // Flash the Certificate BEFORE attempting to connect.
    // I.e. call this function in appInitSystem() before connectServerSecure from
    // Code 8
    void flashCertificate(char *fileName, _u8* data, _u32 length) {
        // 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)12;
        dateTime.sl_tm_mon =   (_u32)3;
        dateTime.sl_tm_year =  (_u32)2017;
        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;

        // AdeMike Keys
        /*************** Step 7 ***************/
        sl_FsOpen(
            (_u8*) PRIV_FILE_NAME,
            FS_MODE_OPEN_CREATE(
                1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
            ),
            NULL,
            &fileHandle
        );
     // If the file is longer than 1024 bytes, you need to loop the writing.
     // "length" contains the length of the certificate
     // "writtenLength" contains the amount of actually written bytes.
     _i32 writtenLen = sl_FsWrite(fileHandle, 0, PRIV_KEY, PRIV_KEY_LEN);
     sl_FsClose(fileHandle, NULL, NULL, 0);
     fileHandle = 0;

     /*************** Step 8 ***************/
     certificates.secureFiles[0] = "privkey";  // mapping private key
     certificates.secureFiles[1] = "cert";  // mapping certificate
     certificates.secureFiles[2] = "aws-iot-rootCA"; // mapping CA
     certificates.secureFiles[3] = "";  // mapping certificate

    }

    /* Configure the MQTT Connection Data */
    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.willFlag = 0;
    data.MQTTVersion = 3;
    data.clientID.cstring = MQTT_CLIENT_ID;
    data.keepAliveInterval = 100;
    data.cleansession = 1;

    printf("Connecting to %s %d\r\n", MQTT_BROKER_NAME, MQTT_PORT);

    /* Connect to the MQTT Broker */
    rc = MQTTConnect(&c, &data);

    /* Set Subscribe Topic Strings */
    memset(clientTopicRed, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicRed, TOPIC_LED_RED, (const char*) MQTT_CLIENT_ID);
    clientTopicRed_ptr = (char*) clientTopicRed;

    memset(clientTopicOrange, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicOrange, TOPIC_LED_ORANGE, (const char*) MQTT_CLIENT_ID);
    clientTopicOrange_ptr = (char*) clientTopicOrange;

    memset(clientTopicYellow, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicYellow, TOPIC_LED_YELLOW, (const char*) MQTT_CLIENT_ID);
    clientTopicYellow_ptr = (char*) clientTopicYellow;

    memset(clientTopicDataGet, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicDataGet, TOPIC_DATA_GET, (const char*) MQTT_CLIENT_ID);
    clientTopicDataGet_ptr = (char*) clientTopicDataGet;

    memset(clientTopicDataStream, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicDataStream, TOPIC_DATA_STREAM, (const char*) MQTT_CLIENT_ID);
    clientTopicDataStream_ptr = (char*) clientTopicDataStream;

    /* Subscribe to the Topics (set callback functions) */
    rc = MQTTSubscribe(&c, clientTopicRed_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicOrange_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicYellow_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicDataGet_ptr, QOS0, clientRecv);

    /* Create Live Data Stream Timer */
    clientStreamTimerHandle = xTimerCreate(
            (const char * const) "Data Stream",
            STREAM_RATE,
            TIMER_AUTORELOAD_ON,
            NULL,
            sensorStreamData);

    /* Create MQTT Client Task */
    rc = xTaskCreate(clientTask, (const char * const) "Mqtt Client App",
                            CLIENT_TASK_STACK_SIZE, NULL, CLIENT_TASK_PRIORITY, &clientTaskHandler);

    /* Error Occured Exit App */
    if(rc < 0)
    {
        clientDeinit();
    }

    return;
}

/**
 * @brief Disconnect from the MQTT Client
 *
 * @return NONE
 */
void clientDeinit(void)
{
    MQTTDisconnect(&c);
    n.disconnect(&n);
}
 

 

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
07.08.17 13:30 als Antwort auf Michael Ng.

Hello Michael,


there are some issues with the code in its current state.


---- Regarding Step 2: ----


Your certificates variable has the type SISockSecureFiles_t with a capital I in SI. This should be a lower-case L, as in SlSockSecureFiles_t.


---- Regarding Step 4: ----


Change the input certificates to &certificates and change the input NULL to SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256.


The result should be:

TLSConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT, &certificates, SL_SO_SEC_METHOD_TLSV1_2, SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256, 0);


---- Regarding Step 5: ----


Change the functions signature from

void flashCertificate(char *fileName, _u8* data, _u32 length)

to just

void flashCertificate()


and place the function definition outside of and above the function clientInit().

---- Regarding Step 6: ----

You should not use the same names for the variables of every certificate. Currently, you have the prefix PRIV for all your variables. Rename them according to what they refer to:

#define PRIV_FILE_NAME "privkey.der"
unsigned char PRIV_KEY [] = { // the priv key hex values };
int PRIV_KEY_LEN = 1675;

#define CERT_FILE_NAME "cert.der"
unsigned char CERT_KEY [] = { // the cert key hex values };
int CERT_KEY_LEN = 1220;

#define CA_FILE_NAME "aws-iot-rootCA.der"
unsigned char CA_KEY [] = { // the ca key hex values };
int CA_KEY_LEN = 1758;


---- Regarding Step 7: ----


sl_FsOpen(), sl_FsWrite() and sl_FsClose() should be done for each of your certificates.

/****** For PRIV ******/
sl_FsOpen(
    (_u8*) PRIV_FILE_NAME,
    FS_MODE_OPEN_CREATE(
        4*1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
    ),
    NULL,
    &fileHandle
);
_i32 writtenLen_PRIV = sl_FsWrite(fileHandle, 0, PRIV_KEY, PRIV_KEY_LEN);
sl_FsClose(fileHandle, NULL, NULL, 0);
fileHandle = 0;

/****** For CERT ******/
sl_FsOpen(
    (_u8*) CERT_FILE_NAME,
    FS_MODE_OPEN_CREATE(
        4*1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
    ),
    NULL,
    &fileHandle
);
_i32 writtenLen_CERT = sl_FsWrite(fileHandle, 0, CERT_KEY, CERT_KEY_LEN);
sl_FsClose(fileHandle, NULL, NULL, 0);
fileHandle = 0;

/****** For CA ******/
sl_FsOpen(
    (_u8*) CA_FILE_NAME,
    FS_MODE_OPEN_CREATE(
        4*1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
    ),
    NULL,
    &fileHandle
);
_i32 writtenLen_CA = sl_FsWrite(fileHandle, 0, CA_KEY, CA_KEY_LEN);
sl_FsClose(fileHandle, NULL, NULL, 0);
fileHandle = 0;


On this step, keep in mind that I have not included error-handling. For example, if a file was not created, the fileHandle will stay 0, after calling sl_FsOpen. Consequently, the file cannot be written to. I recommend to handle that case specifically, and actually abort the entire flashing process. If one of the files cannot be created, it porbably already exists, which shouldn't be the case on the first time you are running the application. If it does already exist, but has to be fixed, use the function sl_FsDel((_u8*) YOUR_FILE_NAME, 0) to delete each of the files.


Additionally, I have added variables for writtenLen as a return for each call of the function sl_FsWrite(). It would be useful to check, the actual written length was. If it is less than the length of your key, then this part has to be rewritten to write the key in two steps. Therefore I recommend to add printf-statements like this:

 

printf("Written Length for %s: %d\n\r", PRIV_FILE_NAME, (int) writtenLen_PRIV);


for every file's writing operation here.


---- Regarding Step 8 ----


Completely delete the mappings. As I have found out, it will not work like this. There is another way, though. For this, go to the source-file mqttXDK.c located at:

source > paho > xdk

There, remove the lines 160 to 166 inside TLSConnectNetwork():

if (certificates != NULL) {
  retVal = sl_SetSockOpt(n->my_socket, SL_SOL_SOCKET, SL_SO_SECURE_FILES, certificates->secureFiles, sizeof(SlSockSecureFiles_t));
  if(retVal < 0)
  {
    return retVal;
  }
}


and replace them with the following:

sl_SetSockOpt(
  n->my_socket,
  SL_SOL_SOCKET,
  SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,
  PRIV_FILE_NAME,
  strlen(PRIV_FILE_NAME)
);
sl_SetSockOpt(
  n->my_socket,
  SL_SOL_SOCKET,
  SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,
  CERT_FILE_NAME,
  strlen(CERT_FILE_NAME)
);
sl_SetSockOpt(
  n->my_socket,
  SL_SOL_SOCKET,
  SL_SO_SECURE_FILES_CA_FILE_NAME,
  CA_FILE_NAME,
  strlen(CA_FILE_NAME)
);


Finally, add

#define PRIV_FILE_NAME "privkey.der"
#define CERT_FILE_NAME "cert.der"
#define CA_FILE_NAME "aws-iot-rootCA.der"


below the includes in mqttXDK.c.


This essentially has the same effect as what was intended with the certificates-variable, but in a straight-forward manner, by setting each file directly.
Do implement these changes, and report back. Also, try simply building the project, without running or flashing it, by right-clicking the project in the Project Explorer, and then selecting Build Project. If errors occur during the build-process, they will be printed to the console. If only warnings are left (and not errors), the application can be flashed.


Kind regards,
Franjo

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
14.08.17 02:18 als Antwort auf Franjo Stjepandic.

Hi Franjon,

After running the Build Project, there are some errors while compliling. 

Errors
===============

1. make\mingw32-make.exe[1]: *** [C:/XDK-Workbench/workspace/MQTT_Paho_Latest/debug/XDK_PAHO_DEMO.out] Error 1    C/C++ Problem

2. mingw32-make: *** [debug] Error 2    C/C++ Problem

3. recipe for target 'C:/XDK-Workbench/workspace/MQTT_Paho_Latest/debug/XDK_PAHO_DEMO.out' failed    line 90    C/C++ Problem

4. recipe for target 'debug' failed    Makefile    /MQTT_Paho_Latest    line 50    C/C++ Problem

5. Symbol 'gpioPortA' could not be resolved    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 414    Semantic Error

6. Symbol 'gpioPortB' could not be resolved    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 418    Semantic Error

7. Symbol 'gpioPortB' could not be resolved    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 422    Semantic Error

8. Symbol 'UINT32_MAX' could not be resolved    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 482    Semantic Error

9. Symbol 'UINT32_MAX' could not be resolved    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 493    Semantic Error

10. Type 'PTD_pinOutToggle(PTD_PORT_LED_ORANGE, PTD_PIN_LED_ORANGE)' could not be resolved    mqttPahoClient.c   /MQTT_Paho_Latest/source    line 418    Semantic Error

11. Type 'PTD_pinOutToggle(PTD_PORT_LED_RED, PTD_PIN_LED_RED)' could not be resolved    mqttPahoClient.c   /MQTT_Paho_Latest/source    line 414    Semantic Error

12. Type 'PTD_pinOutToggle(PTD_PORT_LED_YELLOW, PTD_PIN_LED_YELLOW)' could not be resolved    mqttPahoClient.c   /MQTT_Paho_Latest/source    line 422    Semantic Error

13. Type 'uint32_t' could not be resolved    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 369    Semantic Error

14. Type 'uint8_t' could not be resolved    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 368    Semantic Error

15. Type 'uint8_t' could not be resolved    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 426    Semantic Error

16. Type 'uint8_t' could not be resolved    mqttXDK.c    /MQTT_Paho_Latest/source/paho/XDK    line 81    Semantic Error

17. Type 'uint8_t' could not be resolved    mqttXDK.c    /MQTT_Paho_Latest/source/paho/XDK    line 101    Semantic Error

18. undefined reference to `flashCertificates'    mqttPahoClient.c    /MQTT_Paho_Latest/source    line 584    C/C++ Problem
 

mqttPahoClient.c
=====================

/******************************************************************************
**    COPYRIGHT (c) 2016        Bosch Connected Devices and Solutions GmbH
**
**    The use of this software is subject to the XDK SDK EULA
**
*******************************************************************************
**
**    OBJECT NAME:    mqttClient.c
**
**    DESCRIPTION:    Source Code for the MQTT Paho Client
**
**    PURPOSE:        Initializes the Paho Client and sets up subscriptions,
**                    starts the task to pubish and receive data,
**                    initializes the timer to stream data,
**                    defines the callback function for subscibed topics
**
**    AUTHOR(S):        Bosch Connected Devices and Solutions GmbH (BCDS)
**
**    Revision History:
**
**    Date             Name        Company      Description
**  2016.Apr         crk        BCDS         Initial Release
**
*******************************************************************************/

/* system header files */
#include <stdint.h>

/* own header files */
#include "mqttPahoClient.h"
#include "mqttConfig.h"
#include "mqttSensor.h"

/*************** Step 1 ***************/
#include "socket.h"            // AdeMike

/* additional interface header files */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "PTD_portDriver_ph.h"
#include "PTD_portDriver_ih.h"
#include "WDG_watchdog_ih.h"

/* paho header files */
#include "MQTTConnect.h"

/* constant definitions ***************************************************** */

/*************** Step 6 ***************/
#define PRIV_FILE_NAME "privkey.der"    // AdeMike
unsigned char PRIV_KEY [] = {
        0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50,
        0x52, 0x49, 0x56, 0x41, 0x54, 0x45, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A,
        0x4D, 0x49, 0x49, 0x45, 0x6F, 0x77, 0x49, 0x42, 0x41, 0x41, 0x4B, 0x43, 0x41, 0x51, 0x45, 0x41,
        0x70, 0x39, 0x59, 0x4E, 0x72, 0x5A, 0x67, 0x51, 0x64, 0x67, 0x68, 0x72, 0x48, 0x70, 0x70, 0x54,
        0x30, 0x4A, 0x6D, 0x75, 0x74, 0x52, 0x61, 0x6C, 0x41, 0x4C, 0x2B, 0x35, 0x35, 0x6D, 0x7A, 0x61,
        0x5A, 0x79, 0x79, 0x52, 0x79, 0x43, 0x58, 0x42, 0x6B, 0x41, 0x57, 0x72, 0x5A, 0x76, 0x61, 0x49,
        0x0A, 0x55, 0x54, 0x65, 0x58, 0x61, 0x6D, 0x32, 0x51, 0x6F, 0x69, 0x4D, 0x4D, 0x50, 0x71, 0x38,
        0x4E, 0x7A, 0x63, 0x2F, 0x6D, 0x6F, 0x45, 0x44, 0x46, 0x77, 0x68, 0x6C, 0x43, 0x6B, 0x50, 0x30,
        0x74, 0x4B, 0x42, 0x61, 0x70, 0x6E, 0x6F, 0x52, 0x2B, 0x63, 0x44, 0x36, 0x52, 0x2F, 0x77, 0x61,
        0x78, 0x76, 0x2F, 0x65, 0x59, 0x55, 0x77, 0x54, 0x65, 0x55, 0x53, 0x70, 0x5A, 0x2B, 0x32, 0x7A,
        0x55, 0x0A, 0x56, 0x58, 0x6C, 0x49, 0x5A, 0x6B, 0x51, 0x33, 0x77, 0x75, 0x79, 0x51, 0x48, 0x55,
        0x54, 0x56, 0x30, 0x2F, 0x6A, 0x4D, 0x30, 0x47, 0x42, 0x45, 0x69, 0x2B, 0x48, 0x57, 0x4E, 0x34,
        0x6F, 0x4D, 0x69, 0x50, 0x43, 0x67, 0x59, 0x49, 0x31, 0x36, 0x78, 0x74, 0x55, 0x33, 0x4C, 0x64,
        0x49, 0x58, 0x66, 0x32, 0x37, 0x4C, 0x52, 0x49, 0x66, 0x4B, 0x64, 0x4C, 0x2B, 0x45, 0x33, 0x2B,
        0x49, 0x77, 0x0A, 0x35, 0x48, 0x37, 0x59, 0x51, 0x37, 0x55, 0x41, 0x49, 0x73, 0x61, 0x78, 0x75,
        0x4D, 0x41, 0x61, 0x6B, 0x55, 0x6B, 0x53, 0x49, 0x49, 0x72, 0x48, 0x34, 0x53, 0x53, 0x41, 0x4B,
        0x66, 0x2B, 0x75, 0x51, 0x6F, 0x34, 0x75, 0x42, 0x62, 0x39, 0x31, 0x46, 0x6F, 0x68, 0x55, 0x4E,
        0x37, 0x51, 0x56, 0x59, 0x4A, 0x38, 0x4E, 0x7A, 0x66, 0x79, 0x31, 0x76, 0x44, 0x33, 0x45, 0x38,
        0x33, 0x7A, 0x35, 0x0A, 0x2B, 0x44, 0x2B, 0x68, 0x36, 0x74, 0x4A, 0x6D, 0x46, 0x51, 0x6B, 0x5A,
        0x50, 0x2B, 0x33, 0x67, 0x6F, 0x66, 0x48, 0x69, 0x6F, 0x68, 0x57, 0x73, 0x6B, 0x42, 0x67, 0x6E,
        0x76, 0x4C, 0x33, 0x50, 0x66, 0x79, 0x6E, 0x58, 0x67, 0x46, 0x6A, 0x71, 0x36, 0x66, 0x47, 0x52,
        0x5A, 0x2B, 0x69, 0x6D, 0x6A, 0x43, 0x37, 0x47, 0x51, 0x72, 0x47, 0x4E, 0x55, 0x42, 0x2B, 0x46,
        0x6E, 0x6D, 0x58, 0x36, 0x0A, 0x35, 0x45, 0x57, 0x78, 0x41, 0x57, 0x6B, 0x68, 0x6C, 0x53, 0x75,
        0x79, 0x4E, 0x2B, 0x39, 0x46, 0x4A, 0x73, 0x62, 0x38, 0x48, 0x47, 0x50, 0x62, 0x38, 0x53, 0x53,
        0x41, 0x56, 0x50, 0x73, 0x75, 0x51, 0x4D, 0x57, 0x54, 0x72, 0x77, 0x49, 0x44, 0x41, 0x51, 0x41,
        0x42, 0x41, 0x6F, 0x49, 0x42, 0x41, 0x47, 0x42, 0x69, 0x30, 0x4B, 0x59, 0x69, 0x44, 0x30, 0x6F,
        0x4A, 0x32, 0x61, 0x4C, 0x51, 0x0A, 0x6C, 0x46, 0x50, 0x57, 0x2F, 0x6E, 0x74, 0x6E, 0x44, 0x73,
        0x6D, 0x59, 0x55, 0x65, 0x57, 0x67, 0x47, 0x2B, 0x6C, 0x6D, 0x73, 0x69, 0x34, 0x55, 0x61, 0x4D,
        0x34, 0x53, 0x51, 0x33, 0x59, 0x31, 0x48, 0x4F, 0x49, 0x76, 0x6E, 0x39, 0x68, 0x79, 0x4A, 0x62,
        0x37, 0x48, 0x69, 0x2B, 0x2B, 0x76, 0x7A, 0x71, 0x69, 0x6B, 0x76, 0x64, 0x6A, 0x49, 0x65, 0x67,
        0x6E, 0x58, 0x51, 0x65, 0x42, 0x4D, 0x0A, 0x56, 0x5A, 0x4F, 0x52, 0x4F, 0x45, 0x59, 0x64, 0x35,
        0x78, 0x4D, 0x46, 0x44, 0x41, 0x6B, 0x2B, 0x79, 0x66, 0x50, 0x70, 0x2B, 0x47, 0x4F, 0x74, 0x42,
        0x78, 0x50, 0x72, 0x30, 0x35, 0x4E, 0x4E, 0x30, 0x37, 0x39, 0x6D, 0x6B, 0x49, 0x71, 0x53, 0x6F,
        0x4D, 0x64, 0x6A, 0x33, 0x66, 0x76, 0x42, 0x48, 0x56, 0x2F, 0x48, 0x6F, 0x62, 0x41, 0x46, 0x71,
        0x54, 0x67, 0x41, 0x4D, 0x57, 0x72, 0x68, 0x0A, 0x38, 0x41, 0x4C, 0x77, 0x31, 0x64, 0x6D, 0x39,
        0x52, 0x6F, 0x5A, 0x4C, 0x79, 0x6F, 0x32, 0x59, 0x2B, 0x76, 0x2B, 0x6E, 0x48, 0x44, 0x73, 0x32,
        0x46, 0x4C, 0x48, 0x6F, 0x6E, 0x32, 0x55, 0x46, 0x39, 0x56, 0x37, 0x37, 0x36, 0x39, 0x71, 0x4E,
        0x79, 0x79, 0x36, 0x6C, 0x41, 0x2F, 0x6F, 0x66, 0x78, 0x52, 0x53, 0x4A, 0x4C, 0x6C, 0x74, 0x42,
        0x72, 0x71, 0x7A, 0x2B, 0x47, 0x36, 0x35, 0x65, 0x0A, 0x47, 0x67, 0x45, 0x4E, 0x61, 0x75, 0x4B,
        0x35, 0x68, 0x70, 0x65, 0x30, 0x48, 0x37, 0x67, 0x57, 0x2B, 0x2F, 0x38, 0x6D, 0x59, 0x39, 0x51,
        0x37, 0x5A, 0x46, 0x61, 0x63, 0x62, 0x73, 0x73, 0x72, 0x4F, 0x55, 0x76, 0x42, 0x48, 0x7A, 0x52,
        0x42, 0x72, 0x53, 0x62, 0x4C, 0x4D, 0x31, 0x70, 0x6C, 0x35, 0x4F, 0x78, 0x70, 0x70, 0x30, 0x79,
        0x41, 0x79, 0x76, 0x54, 0x59, 0x79, 0x66, 0x42, 0x58, 0x0A, 0x53, 0x6D, 0x50, 0x6D, 0x36, 0x53,
        0x75, 0x56, 0x4F, 0x56, 0x71, 0x55, 0x65, 0x6F, 0x32, 0x63, 0x61, 0x38, 0x45, 0x48, 0x37, 0x72,
        0x4D, 0x37, 0x2B, 0x79, 0x72, 0x33, 0x67, 0x61, 0x4A, 0x41, 0x2B, 0x39, 0x78, 0x55, 0x50, 0x75,
        0x66, 0x58, 0x70, 0x77, 0x48, 0x70, 0x62, 0x4A, 0x41, 0x45, 0x30, 0x6E, 0x6E, 0x76, 0x4A, 0x59,
        0x51, 0x37, 0x30, 0x36, 0x57, 0x2B, 0x63, 0x73, 0x7A, 0x6E, 0x0A, 0x44, 0x54, 0x4E, 0x6A, 0x63,
        0x59, 0x45, 0x43, 0x67, 0x59, 0x45, 0x41, 0x36, 0x54, 0x49, 0x53, 0x4E, 0x6C, 0x39, 0x65, 0x78,
        0x36, 0x75, 0x5A, 0x69, 0x30, 0x69, 0x77, 0x4E, 0x57, 0x56, 0x46, 0x51, 0x79, 0x4E, 0x64, 0x57,
        0x6C, 0x69, 0x49, 0x76, 0x47, 0x47, 0x5A, 0x64, 0x5A, 0x45, 0x6C, 0x6B, 0x73, 0x77, 0x36, 0x6C,
        0x4C, 0x49, 0x33, 0x34, 0x4F, 0x75, 0x4A, 0x33, 0x65, 0x69, 0x74, 0x0A, 0x4C, 0x6C, 0x78, 0x6E,
        0x53, 0x65, 0x58, 0x70, 0x49, 0x6E, 0x56, 0x52, 0x4D, 0x69, 0x2B, 0x66, 0x69, 0x51, 0x39, 0x35,
        0x67, 0x77, 0x74, 0x70, 0x37, 0x2B, 0x37, 0x41, 0x34, 0x6F, 0x47, 0x41, 0x58, 0x6B, 0x30, 0x53,
        0x4E, 0x66, 0x47, 0x31, 0x46, 0x49, 0x43, 0x72, 0x6B, 0x43, 0x74, 0x59, 0x78, 0x38, 0x68, 0x42,
        0x65, 0x36, 0x62, 0x2F, 0x6C, 0x49, 0x48, 0x47, 0x66, 0x52, 0x50, 0x5A, 0x0A, 0x6E, 0x76, 0x78,
        0x6B, 0x38, 0x51, 0x73, 0x33, 0x69, 0x50, 0x74, 0x64, 0x4E, 0x50, 0x31, 0x48, 0x45, 0x76, 0x2F,
        0x4F, 0x46, 0x4E, 0x72, 0x4D, 0x74, 0x4B, 0x56, 0x62, 0x32, 0x2B, 0x61, 0x6E, 0x6F, 0x43, 0x53,
        0x66, 0x6A, 0x66, 0x32, 0x69, 0x70, 0x56, 0x42, 0x76, 0x44, 0x78, 0x4E, 0x4F, 0x6A, 0x62, 0x46,
        0x4D, 0x51, 0x2B, 0x38, 0x43, 0x67, 0x59, 0x45, 0x41, 0x75, 0x44, 0x2B, 0x2B, 0x0A, 0x4E, 0x61,
        0x59, 0x4C, 0x52, 0x35, 0x48, 0x74, 0x51, 0x71, 0x4E, 0x4E, 0x2F, 0x62, 0x57, 0x56, 0x6A, 0x51,
        0x57, 0x77, 0x48, 0x55, 0x4C, 0x73, 0x59, 0x61, 0x2B, 0x75, 0x57, 0x68, 0x4B, 0x31, 0x51, 0x4B,
        0x50, 0x51, 0x63, 0x6C, 0x75, 0x53, 0x78, 0x33, 0x71, 0x7A, 0x47, 0x68, 0x68, 0x53, 0x62, 0x43,
        0x4A, 0x4A, 0x4F, 0x63, 0x56, 0x67, 0x2F, 0x78, 0x73, 0x79, 0x59, 0x4B, 0x70, 0x6D, 0x0A, 0x48,
        0x52, 0x56, 0x31, 0x67, 0x58, 0x67, 0x68, 0x54, 0x46, 0x4A, 0x73, 0x61, 0x59, 0x42, 0x79, 0x71,
        0x32, 0x52, 0x62, 0x68, 0x2B, 0x50, 0x63, 0x45, 0x6A, 0x42, 0x34, 0x47, 0x69, 0x6C, 0x32, 0x47,
        0x51, 0x52, 0x5A, 0x34, 0x58, 0x43, 0x75, 0x44, 0x37, 0x65, 0x4B, 0x4D, 0x66, 0x4D, 0x63, 0x30,
        0x6A, 0x5A, 0x43, 0x47, 0x72, 0x79, 0x6F, 0x69, 0x36, 0x42, 0x62, 0x54, 0x64, 0x7A, 0x58, 0x0A,
        0x34, 0x57, 0x62, 0x42, 0x58, 0x45, 0x66, 0x36, 0x47, 0x65, 0x63, 0x30, 0x59, 0x70, 0x32, 0x57,
        0x4F, 0x72, 0x6D, 0x52, 0x54, 0x64, 0x37, 0x42, 0x44, 0x51, 0x74, 0x63, 0x55, 0x49, 0x4B, 0x63,
        0x76, 0x6F, 0x61, 0x34, 0x37, 0x45, 0x45, 0x43, 0x67, 0x59, 0x45, 0x41, 0x6B, 0x62, 0x2B, 0x69,
        0x31, 0x47, 0x72, 0x39, 0x4D, 0x53, 0x7A, 0x57, 0x64, 0x64, 0x43, 0x44, 0x6D, 0x59, 0x76, 0x6E,
        0x0A, 0x49, 0x31, 0x51, 0x36, 0x4A, 0x35, 0x71, 0x49, 0x4D, 0x37, 0x32, 0x49, 0x6A, 0x59, 0x75,
        0x66, 0x67, 0x55, 0x57, 0x32, 0x49, 0x33, 0x50, 0x55, 0x4B, 0x76, 0x62, 0x73, 0x48, 0x30, 0x38,
        0x71, 0x31, 0x6E, 0x77, 0x59, 0x62, 0x6E, 0x36, 0x4E, 0x48, 0x4F, 0x56, 0x59, 0x54, 0x31, 0x61,
        0x6D, 0x6A, 0x71, 0x4B, 0x6D, 0x58, 0x72, 0x70, 0x47, 0x68, 0x78, 0x69, 0x68, 0x59, 0x37, 0x42,
        0x76, 0x0A, 0x44, 0x41, 0x46, 0x39, 0x72, 0x55, 0x75, 0x5A, 0x30, 0x75, 0x75, 0x73, 0x7A, 0x78,
        0x6E, 0x59, 0x6A, 0x6C, 0x31, 0x69, 0x57, 0x43, 0x65, 0x44, 0x50, 0x45, 0x31, 0x30, 0x51, 0x6E,
        0x36, 0x69, 0x6D, 0x4A, 0x54, 0x46, 0x66, 0x6B, 0x5A, 0x31, 0x65, 0x6C, 0x38, 0x6F, 0x33, 0x56,
        0x4B, 0x6B, 0x46, 0x6F, 0x4C, 0x64, 0x53, 0x66, 0x6D, 0x4B, 0x30, 0x69, 0x6B, 0x37, 0x35, 0x5A,
        0x41, 0x66, 0x0A, 0x47, 0x70, 0x39, 0x70, 0x50, 0x66, 0x54, 0x56, 0x73, 0x42, 0x38, 0x36, 0x6D,
        0x71, 0x43, 0x46, 0x69, 0x31, 0x66, 0x53, 0x41, 0x2B, 0x38, 0x43, 0x67, 0x59, 0x41, 0x59, 0x36,
        0x73, 0x33, 0x76, 0x64, 0x58, 0x41, 0x72, 0x45, 0x71, 0x6F, 0x53, 0x6A, 0x41, 0x45, 0x39, 0x49,
        0x58, 0x53, 0x44, 0x4B, 0x4E, 0x54, 0x44, 0x63, 0x45, 0x79, 0x46, 0x66, 0x58, 0x76, 0x48, 0x78,
        0x4B, 0x58, 0x73, 0x0A, 0x67, 0x76, 0x72, 0x71, 0x72, 0x45, 0x57, 0x79, 0x59, 0x6E, 0x36, 0x63,
        0x4E, 0x64, 0x50, 0x58, 0x75, 0x64, 0x39, 0x4C, 0x52, 0x38, 0x30, 0x78, 0x55, 0x74, 0x31, 0x43,
        0x51, 0x32, 0x6B, 0x68, 0x33, 0x38, 0x67, 0x50, 0x5A, 0x55, 0x36, 0x6A, 0x67, 0x72, 0x59, 0x55,
        0x6F, 0x6F, 0x46, 0x66, 0x65, 0x6D, 0x67, 0x43, 0x66, 0x61, 0x64, 0x43, 0x63, 0x6E, 0x6D, 0x62,
        0x6D, 0x43, 0x58, 0x58, 0x0A, 0x68, 0x6B, 0x59, 0x64, 0x66, 0x64, 0x36, 0x63, 0x55, 0x34, 0x63,
        0x46, 0x38, 0x45, 0x6E, 0x69, 0x68, 0x2B, 0x48, 0x79, 0x75, 0x62, 0x62, 0x56, 0x67, 0x79, 0x38,
        0x31, 0x33, 0x58, 0x72, 0x34, 0x69, 0x61, 0x76, 0x32, 0x72, 0x65, 0x6B, 0x39, 0x33, 0x59, 0x32,
        0x78, 0x46, 0x48, 0x79, 0x2F, 0x6E, 0x6C, 0x37, 0x76, 0x4F, 0x41, 0x50, 0x46, 0x6E, 0x74, 0x61,
        0x79, 0x4D, 0x4B, 0x66, 0x41, 0x0A, 0x41, 0x48, 0x6F, 0x37, 0x77, 0x51, 0x4B, 0x42, 0x67, 0x42,
        0x31, 0x74, 0x75, 0x30, 0x63, 0x7A, 0x48, 0x75, 0x4F, 0x50, 0x35, 0x72, 0x7A, 0x31, 0x48, 0x54,
        0x4F, 0x6C, 0x6E, 0x36, 0x31, 0x57, 0x2F, 0x2B, 0x5A, 0x39, 0x59, 0x2F, 0x2B, 0x65, 0x6F, 0x70,
        0x79, 0x70, 0x53, 0x41, 0x4E, 0x57, 0x79, 0x6D, 0x59, 0x4C, 0x2B, 0x42, 0x58, 0x69, 0x6E, 0x6D,
        0x56, 0x38, 0x76, 0x41, 0x35, 0x54, 0x0A, 0x48, 0x31, 0x55, 0x75, 0x49, 0x78, 0x35, 0x41, 0x50,
        0x42, 0x6F, 0x41, 0x65, 0x68, 0x49, 0x35, 0x70, 0x35, 0x61, 0x4F, 0x4A, 0x2F, 0x59, 0x63, 0x41,
        0x61, 0x78, 0x55, 0x30, 0x4A, 0x44, 0x38, 0x37, 0x58, 0x6A, 0x37, 0x6E, 0x57, 0x48, 0x70, 0x56,
        0x50, 0x64, 0x4F, 0x59, 0x45, 0x66, 0x59, 0x6E, 0x79, 0x76, 0x67, 0x58, 0x6E, 0x41, 0x63, 0x67,
        0x4F, 0x63, 0x6D, 0x4F, 0x45, 0x4A, 0x74, 0x0A, 0x69, 0x32, 0x56, 0x6D, 0x2B, 0x6B, 0x4A, 0x52,
        0x65, 0x63, 0x44, 0x79, 0x4E, 0x49, 0x50, 0x45, 0x77, 0x61, 0x4F, 0x62, 0x79, 0x4F, 0x6C, 0x67,
        0x63, 0x5A, 0x6D, 0x6C, 0x52, 0x62, 0x6C, 0x72, 0x4F, 0x47, 0x77, 0x59, 0x73, 0x62, 0x70, 0x6B,
        0x55, 0x7A, 0x74, 0x74, 0x4E, 0x57, 0x78, 0x58, 0x43, 0x61, 0x49, 0x6C, 0x0A, 0x2D, 0x2D, 0x2D,
        0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x52, 0x49, 0x56, 0x41, 0x54,
        0x45, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A
};
int PRIV_KEY_LEN = 1675;

#define CERT_FILE_NAME "cert.der"    // AdeMike
unsigned char CERT_KEY [] = {
        0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
        0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A, 0x4D, 0x49, 0x49, 0x44,
        0x57, 0x54, 0x43, 0x43, 0x41, 0x6B, 0x47, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x55,
        0x42, 0x56, 0x39, 0x2B, 0x48, 0x31, 0x35, 0x64, 0x67, 0x64, 0x59, 0x30, 0x34, 0x57, 0x37, 0x31,
        0x55, 0x54, 0x4D, 0x7A, 0x54, 0x6F, 0x74, 0x4E, 0x2B, 0x45, 0x41, 0x77, 0x44, 0x51, 0x59, 0x4A,
        0x4B, 0x6F, 0x5A, 0x49, 0x68, 0x76, 0x63, 0x4E, 0x41, 0x51, 0x45, 0x4C, 0x0A, 0x42, 0x51, 0x41,
        0x77, 0x54, 0x54, 0x46, 0x4C, 0x4D, 0x45, 0x6B, 0x47, 0x41, 0x31, 0x55, 0x45, 0x43, 0x77, 0x78,
        0x43, 0x51, 0x57, 0x31, 0x68, 0x65, 0x6D, 0x39, 0x75, 0x49, 0x46, 0x64, 0x6C, 0x59, 0x69, 0x42,
        0x54, 0x5A, 0x58, 0x4A, 0x32, 0x61, 0x57, 0x4E, 0x6C, 0x63, 0x79, 0x42, 0x50, 0x50, 0x55, 0x46,
        0x74, 0x59, 0x58, 0x70, 0x76, 0x62, 0x69, 0x35, 0x6A, 0x62, 0x32, 0x30, 0x67, 0x0A, 0x53, 0x57,
        0x35, 0x6A, 0x4C, 0x69, 0x42, 0x4D, 0x50, 0x56, 0x4E, 0x6C, 0x59, 0x58, 0x52, 0x30, 0x62, 0x47,
        0x55, 0x67, 0x55, 0x31, 0x51, 0x39, 0x56, 0x32, 0x46, 0x7A, 0x61, 0x47, 0x6C, 0x75, 0x5A, 0x33,
        0x52, 0x76, 0x62, 0x69, 0x42, 0x44, 0x50, 0x56, 0x56, 0x54, 0x4D, 0x42, 0x34, 0x58, 0x44, 0x54,
        0x45, 0x33, 0x4D, 0x44, 0x67, 0x77, 0x4D, 0x6A, 0x41, 0x35, 0x4D, 0x44, 0x41, 0x30, 0x0A, 0x4D,
        0x6C, 0x6F, 0x58, 0x44, 0x54, 0x51, 0x35, 0x4D, 0x54, 0x49, 0x7A, 0x4D, 0x54, 0x49, 0x7A, 0x4E,
        0x54, 0x6B, 0x31, 0x4F, 0x56, 0x6F, 0x77, 0x48, 0x6A, 0x45, 0x63, 0x4D, 0x42, 0x6F, 0x47, 0x41,
        0x31, 0x55, 0x45, 0x41, 0x77, 0x77, 0x54, 0x51, 0x56, 0x64, 0x54, 0x49, 0x45, 0x6C, 0x76, 0x56,
        0x43, 0x42, 0x44, 0x5A, 0x58, 0x4A, 0x30, 0x61, 0x57, 0x5A, 0x70, 0x59, 0x32, 0x46, 0x30, 0x0A,
        0x5A, 0x54, 0x43, 0x43, 0x41, 0x53, 0x49, 0x77, 0x44, 0x51, 0x59, 0x4A, 0x4B, 0x6F, 0x5A, 0x49,
        0x68, 0x76, 0x63, 0x4E, 0x41, 0x51, 0x45, 0x42, 0x42, 0x51, 0x41, 0x44, 0x67, 0x67, 0x45, 0x50,
        0x41, 0x44, 0x43, 0x43, 0x41, 0x51, 0x6F, 0x43, 0x67, 0x67, 0x45, 0x42, 0x41, 0x4B, 0x66, 0x57,
        0x44, 0x61, 0x32, 0x59, 0x45, 0x48, 0x59, 0x49, 0x61, 0x78, 0x36, 0x61, 0x55, 0x39, 0x43, 0x5A,
        0x0A, 0x72, 0x72, 0x55, 0x57, 0x70, 0x51, 0x43, 0x2F, 0x75, 0x65, 0x5A, 0x73, 0x32, 0x6D, 0x63,
        0x73, 0x6B, 0x63, 0x67, 0x6C, 0x77, 0x5A, 0x41, 0x46, 0x71, 0x32, 0x62, 0x32, 0x69, 0x46, 0x45,
        0x33, 0x6C, 0x32, 0x70, 0x74, 0x6B, 0x4B, 0x49, 0x6A, 0x44, 0x44, 0x36, 0x76, 0x44, 0x63, 0x33,
        0x50, 0x35, 0x71, 0x42, 0x41, 0x78, 0x63, 0x49, 0x5A, 0x51, 0x70, 0x44, 0x39, 0x4C, 0x53, 0x67,
        0x57, 0x0A, 0x71, 0x5A, 0x36, 0x45, 0x66, 0x6E, 0x41, 0x2B, 0x6B, 0x66, 0x38, 0x47, 0x73, 0x62,
        0x2F, 0x33, 0x6D, 0x46, 0x4D, 0x45, 0x33, 0x6C, 0x45, 0x71, 0x57, 0x66, 0x74, 0x73, 0x31, 0x46,
        0x56, 0x35, 0x53, 0x47, 0x5A, 0x45, 0x4E, 0x38, 0x4C, 0x73, 0x6B, 0x42, 0x31, 0x45, 0x31, 0x64,
        0x50, 0x34, 0x7A, 0x4E, 0x42, 0x67, 0x52, 0x49, 0x76, 0x68, 0x31, 0x6A, 0x65, 0x4B, 0x44, 0x49,
        0x6A, 0x77, 0x0A, 0x6F, 0x47, 0x43, 0x4E, 0x65, 0x73, 0x62, 0x56, 0x4E, 0x79, 0x33, 0x53, 0x46,
        0x33, 0x39, 0x75, 0x79, 0x30, 0x53, 0x48, 0x79, 0x6E, 0x53, 0x2F, 0x68, 0x4E, 0x2F, 0x69, 0x4D,
        0x4F, 0x52, 0x2B, 0x32, 0x45, 0x4F, 0x31, 0x41, 0x43, 0x4C, 0x47, 0x73, 0x62, 0x6A, 0x41, 0x47,
        0x70, 0x46, 0x4A, 0x45, 0x69, 0x43, 0x4B, 0x78, 0x2B, 0x45, 0x6B, 0x67, 0x43, 0x6E, 0x2F, 0x72,
        0x6B, 0x4B, 0x4F, 0x0A, 0x4C, 0x67, 0x57, 0x2F, 0x64, 0x52, 0x61, 0x49, 0x56, 0x44, 0x65, 0x30,
        0x46, 0x57, 0x43, 0x66, 0x44, 0x63, 0x33, 0x38, 0x74, 0x62, 0x77, 0x39, 0x78, 0x50, 0x4E, 0x38,
        0x2B, 0x66, 0x67, 0x2F, 0x6F, 0x65, 0x72, 0x53, 0x5A, 0x68, 0x55, 0x4A, 0x47, 0x54, 0x2F, 0x74,
        0x34, 0x4B, 0x48, 0x78, 0x34, 0x71, 0x49, 0x56, 0x72, 0x4A, 0x41, 0x59, 0x4A, 0x37, 0x79, 0x39,
        0x7A, 0x33, 0x38, 0x70, 0x0A, 0x31, 0x34, 0x42, 0x59, 0x36, 0x75, 0x6E, 0x78, 0x6B, 0x57, 0x66,
        0x6F, 0x70, 0x6F, 0x77, 0x75, 0x78, 0x6B, 0x4B, 0x78, 0x6A, 0x56, 0x41, 0x66, 0x68, 0x5A, 0x35,
        0x6C, 0x2B, 0x75, 0x52, 0x46, 0x73, 0x51, 0x46, 0x70, 0x49, 0x5A, 0x55, 0x72, 0x73, 0x6A, 0x66,
        0x76, 0x52, 0x53, 0x62, 0x47, 0x2F, 0x42, 0x78, 0x6A, 0x32, 0x2F, 0x45, 0x6B, 0x67, 0x46, 0x54,
        0x37, 0x4C, 0x6B, 0x44, 0x46, 0x0A, 0x6B, 0x36, 0x38, 0x43, 0x41, 0x77, 0x45, 0x41, 0x41, 0x61,
        0x4E, 0x67, 0x4D, 0x46, 0x34, 0x77, 0x48, 0x77, 0x59, 0x44, 0x56, 0x52, 0x30, 0x6A, 0x42, 0x42,
        0x67, 0x77, 0x46, 0x6F, 0x41, 0x55, 0x38, 0x75, 0x5A, 0x6A, 0x4F, 0x4D, 0x79, 0x6A, 0x39, 0x46,
        0x35, 0x59, 0x6F, 0x51, 0x30, 0x6C, 0x34, 0x70, 0x71, 0x6A, 0x62, 0x59, 0x76, 0x33, 0x43, 0x64,
        0x6B, 0x77, 0x48, 0x51, 0x59, 0x44, 0x0A, 0x56, 0x52, 0x30, 0x4F, 0x42, 0x42, 0x59, 0x45, 0x46,
        0x46, 0x65, 0x38, 0x68, 0x4E, 0x53, 0x65, 0x32, 0x47, 0x62, 0x67, 0x39, 0x32, 0x48, 0x57, 0x58,
        0x78, 0x49, 0x67, 0x59, 0x62, 0x71, 0x74, 0x70, 0x53, 0x4F, 0x42, 0x4D, 0x41, 0x77, 0x47, 0x41,
        0x31, 0x55, 0x64, 0x45, 0x77, 0x45, 0x42, 0x2F, 0x77, 0x51, 0x43, 0x4D, 0x41, 0x41, 0x77, 0x44,
        0x67, 0x59, 0x44, 0x56, 0x52, 0x30, 0x50, 0x0A, 0x41, 0x51, 0x48, 0x2F, 0x42, 0x41, 0x51, 0x44,
        0x41, 0x67, 0x65, 0x41, 0x4D, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33,
        0x44, 0x51, 0x45, 0x42, 0x43, 0x77, 0x55, 0x41, 0x41, 0x34, 0x49, 0x42, 0x41, 0x51, 0x42, 0x57,
        0x62, 0x46, 0x57, 0x74, 0x73, 0x79, 0x61, 0x61, 0x45, 0x37, 0x4D, 0x75, 0x30, 0x38, 0x67, 0x36,
        0x75, 0x50, 0x75, 0x4B, 0x66, 0x6D, 0x33, 0x63, 0x0A, 0x65, 0x5A, 0x51, 0x57, 0x2B, 0x59, 0x50,
        0x71, 0x47, 0x4E, 0x66, 0x64, 0x6E, 0x42, 0x59, 0x72, 0x34, 0x2F, 0x30, 0x6C, 0x55, 0x43, 0x2B,
        0x62, 0x44, 0x6F, 0x72, 0x66, 0x7A, 0x75, 0x2B, 0x74, 0x74, 0x5A, 0x59, 0x6E, 0x44, 0x33, 0x6E,
        0x42, 0x49, 0x69, 0x56, 0x70, 0x62, 0x4A, 0x36, 0x48, 0x64, 0x70, 0x46, 0x6E, 0x6A, 0x34, 0x4B,
        0x53, 0x51, 0x2B, 0x54, 0x67, 0x59, 0x7A, 0x2B, 0x41, 0x0A, 0x35, 0x7A, 0x58, 0x30, 0x6C, 0x75,
        0x56, 0x4D, 0x44, 0x67, 0x6B, 0x49, 0x41, 0x66, 0x2F, 0x52, 0x35, 0x5A, 0x47, 0x51, 0x77, 0x53,
        0x4C, 0x74, 0x34, 0x50, 0x4F, 0x65, 0x38, 0x62, 0x52, 0x5A, 0x69, 0x32, 0x6A, 0x76, 0x48, 0x30,
        0x4C, 0x6D, 0x48, 0x43, 0x46, 0x38, 0x32, 0x6F, 0x2B, 0x4F, 0x35, 0x6F, 0x69, 0x6A, 0x64, 0x6E,
        0x63, 0x6A, 0x5A, 0x6C, 0x4C, 0x45, 0x74, 0x62, 0x63, 0x39, 0x0A, 0x4A, 0x70, 0x49, 0x74, 0x30,
        0x57, 0x61, 0x68, 0x64, 0x51, 0x66, 0x47, 0x65, 0x50, 0x69, 0x74, 0x39, 0x33, 0x58, 0x51, 0x65,
        0x6A, 0x6C, 0x68, 0x56, 0x44, 0x54, 0x4B, 0x36, 0x59, 0x36, 0x66, 0x68, 0x35, 0x37, 0x69, 0x2B,
        0x41, 0x58, 0x6B, 0x6E, 0x37, 0x4E, 0x36, 0x4C, 0x73, 0x6E, 0x49, 0x52, 0x65, 0x36, 0x6C, 0x50,
        0x4C, 0x77, 0x46, 0x68, 0x6F, 0x5A, 0x71, 0x66, 0x57, 0x4F, 0x46, 0x0A, 0x78, 0x7A, 0x7A, 0x4B,
        0x5A, 0x44, 0x65, 0x38, 0x6D, 0x4C, 0x63, 0x71, 0x64, 0x49, 0x36, 0x5A, 0x45, 0x70, 0x36, 0x4D,
        0x41, 0x2B, 0x46, 0x73, 0x74, 0x56, 0x4E, 0x4F, 0x7A, 0x2B, 0x59, 0x4E, 0x54, 0x64, 0x7A, 0x51,
        0x31, 0x36, 0x62, 0x77, 0x56, 0x76, 0x37, 0x68, 0x6F, 0x53, 0x56, 0x32, 0x57, 0x66, 0x33, 0x6B,
        0x36, 0x32, 0x4E, 0x46, 0x7A, 0x58, 0x73, 0x63, 0x35, 0x35, 0x6E, 0x47, 0x0A, 0x35, 0x6F, 0x57,
        0x31, 0x46, 0x76, 0x6B, 0x53, 0x41, 0x75, 0x67, 0x35, 0x42, 0x73, 0x74, 0x2B, 0x50, 0x38, 0x45,
        0x6A, 0x70, 0x36, 0x65, 0x41, 0x50, 0x77, 0x78, 0x47, 0x4B, 0x32, 0x42, 0x37, 0x43, 0x72, 0x72,
        0x35, 0x5A, 0x47, 0x53, 0x67, 0x6E, 0x5A, 0x41, 0x6C, 0x56, 0x74, 0x4E, 0x73, 0x67, 0x74, 0x49,
        0x55, 0x49, 0x37, 0x6D, 0x38, 0x72, 0x58, 0x2B, 0x33, 0x0A, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45,
        0x4E, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D,
        0x2D, 0x2D, 0x2D, 0x0A
};
int CERT_KEY_LEN = 1220;

#define CA_FILE_NAME "aws-iot-rootCA.der"    // AdeMike
unsigned char CA_KEY [] = {
        0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49,
        0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0D, 0x0A, 0x4D, 0x49, 0x49,
        0x45, 0x30, 0x7A, 0x43, 0x43, 0x41, 0x37, 0x75, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49,
        0x51, 0x47, 0x4E, 0x72, 0x52, 0x6E, 0x69, 0x5A, 0x39, 0x36, 0x4C, 0x74, 0x4B, 0x49, 0x56, 0x6A,
        0x4E, 0x7A, 0x47, 0x73, 0x37, 0x53, 0x6A, 0x41, 0x4E, 0x42, 0x67, 0x6B, 0x71, 0x68, 0x6B, 0x69,
        0x47, 0x39, 0x77, 0x30, 0x42, 0x41, 0x51, 0x55, 0x46, 0x41, 0x44, 0x43, 0x42, 0x0D, 0x0A, 0x79,
        0x6A, 0x45, 0x4C, 0x4D, 0x41, 0x6B, 0x47, 0x41, 0x31, 0x55, 0x45, 0x42, 0x68, 0x4D, 0x43, 0x56,
        0x56, 0x4D, 0x78, 0x46, 0x7A, 0x41, 0x56, 0x42, 0x67, 0x4E, 0x56, 0x42, 0x41, 0x6F, 0x54, 0x44,
        0x6C, 0x5A, 0x6C, 0x63, 0x6D, 0x6C, 0x54, 0x61, 0x57, 0x64, 0x75, 0x4C, 0x43, 0x42, 0x4A, 0x62,
        0x6D, 0x4D, 0x75, 0x4D, 0x52, 0x38, 0x77, 0x48, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4C, 0x0D,
        0x0A, 0x45, 0x78, 0x5A, 0x57, 0x5A, 0x58, 0x4A, 0x70, 0x55, 0x32, 0x6C, 0x6E, 0x62, 0x69, 0x42,
        0x55, 0x63, 0x6E, 0x56, 0x7A, 0x64, 0x43, 0x42, 0x4F, 0x5A, 0x58, 0x52, 0x33, 0x62, 0x33, 0x4A,
        0x72, 0x4D, 0x54, 0x6F, 0x77, 0x4F, 0x41, 0x59, 0x44, 0x56, 0x51, 0x51, 0x4C, 0x45, 0x7A, 0x45,
        0x6F, 0x59, 0x79, 0x6B, 0x67, 0x4D, 0x6A, 0x41, 0x77, 0x4E, 0x69, 0x42, 0x57, 0x5A, 0x58, 0x4A,
        0x70, 0x0D, 0x0A, 0x55, 0x32, 0x6C, 0x6E, 0x62, 0x69, 0x77, 0x67, 0x53, 0x57, 0x35, 0x6A, 0x4C,
        0x69, 0x41, 0x74, 0x49, 0x45, 0x5A, 0x76, 0x63, 0x69, 0x42, 0x68, 0x64, 0x58, 0x52, 0x6F, 0x62,
        0x33, 0x4A, 0x70, 0x65, 0x6D, 0x56, 0x6B, 0x49, 0x48, 0x56, 0x7A, 0x5A, 0x53, 0x42, 0x76, 0x62,
        0x6D, 0x78, 0x35, 0x4D, 0x55, 0x55, 0x77, 0x51, 0x77, 0x59, 0x44, 0x56, 0x51, 0x51, 0x44, 0x45,
        0x7A, 0x78, 0x57, 0x0D, 0x0A, 0x5A, 0x58, 0x4A, 0x70, 0x55, 0x32, 0x6C, 0x6E, 0x62, 0x69, 0x42,
        0x44, 0x62, 0x47, 0x46, 0x7A, 0x63, 0x79, 0x41, 0x7A, 0x49, 0x46, 0x42, 0x31, 0x59, 0x6D, 0x78,
        0x70, 0x59, 0x79, 0x42, 0x51, 0x63, 0x6D, 0x6C, 0x74, 0x59, 0x58, 0x4A, 0x35, 0x49, 0x45, 0x4E,
        0x6C, 0x63, 0x6E, 0x52, 0x70, 0x5A, 0x6D, 0x6C, 0x6A, 0x59, 0x58, 0x52, 0x70, 0x62, 0x32, 0x34,
        0x67, 0x51, 0x58, 0x56, 0x30, 0x0D, 0x0A, 0x61, 0x47, 0x39, 0x79, 0x61, 0x58, 0x52, 0x35, 0x49,
        0x43, 0x30, 0x67, 0x52, 0x7A, 0x55, 0x77, 0x48, 0x68, 0x63, 0x4E, 0x4D, 0x44, 0x59, 0x78, 0x4D,
        0x54, 0x41, 0x34, 0x4D, 0x44, 0x41, 0x77, 0x4D, 0x44, 0x41, 0x77, 0x57, 0x68, 0x63, 0x4E, 0x4D,
        0x7A, 0x59, 0x77, 0x4E, 0x7A, 0x45, 0x32, 0x4D, 0x6A, 0x4D, 0x31, 0x4F, 0x54, 0x55, 0x35, 0x57,
        0x6A, 0x43, 0x42, 0x79, 0x6A, 0x45, 0x4C, 0x0D, 0x0A, 0x4D, 0x41, 0x6B, 0x47, 0x41, 0x31, 0x55,
        0x45, 0x42, 0x68, 0x4D, 0x43, 0x56, 0x56, 0x4D, 0x78, 0x46, 0x7A, 0x41, 0x56, 0x42, 0x67, 0x4E,
        0x56, 0x42, 0x41, 0x6F, 0x54, 0x44, 0x6C, 0x5A, 0x6C, 0x63, 0x6D, 0x6C, 0x54, 0x61, 0x57, 0x64,
        0x75, 0x4C, 0x43, 0x42, 0x4A, 0x62, 0x6D, 0x4D, 0x75, 0x4D, 0x52, 0x38, 0x77, 0x48, 0x51, 0x59,
        0x44, 0x56, 0x51, 0x51, 0x4C, 0x45, 0x78, 0x5A, 0x57, 0x0D, 0x0A, 0x5A, 0x58, 0x4A, 0x70, 0x55,
        0x32, 0x6C, 0x6E, 0x62, 0x69, 0x42, 0x55, 0x63, 0x6E, 0x56, 0x7A, 0x64, 0x43, 0x42, 0x4F, 0x5A,
        0x58, 0x52, 0x33, 0x62, 0x33, 0x4A, 0x72, 0x4D, 0x54, 0x6F, 0x77, 0x4F, 0x41, 0x59, 0x44, 0x56,
        0x51, 0x51, 0x4C, 0x45, 0x7A, 0x45, 0x6F, 0x59, 0x79, 0x6B, 0x67, 0x4D, 0x6A, 0x41, 0x77, 0x4E,
        0x69, 0x42, 0x57, 0x5A, 0x58, 0x4A, 0x70, 0x55, 0x32, 0x6C, 0x6E, 0x0D, 0x0A, 0x62, 0x69, 0x77,
        0x67, 0x53, 0x57, 0x35, 0x6A, 0x4C, 0x69, 0x41, 0x74, 0x49, 0x45, 0x5A, 0x76, 0x63, 0x69, 0x42,
        0x68, 0x64, 0x58, 0x52, 0x6F, 0x62, 0x33, 0x4A, 0x70, 0x65, 0x6D, 0x56, 0x6B, 0x49, 0x48, 0x56,
        0x7A, 0x5A, 0x53, 0x42, 0x76, 0x62, 0x6D, 0x78, 0x35, 0x4D, 0x55, 0x55, 0x77, 0x51, 0x77, 0x59,
        0x44, 0x56, 0x51, 0x51, 0x44, 0x45, 0x7A, 0x78, 0x57, 0x5A, 0x58, 0x4A, 0x70, 0x0D, 0x0A, 0x55,
        0x32, 0x6C, 0x6E, 0x62, 0x69, 0x42, 0x44, 0x62, 0x47, 0x46, 0x7A, 0x63, 0x79, 0x41, 0x7A, 0x49,
        0x46, 0x42, 0x31, 0x59, 0x6D, 0x78, 0x70, 0x59, 0x79, 0x42, 0x51, 0x63, 0x6D, 0x6C, 0x74, 0x59,
        0x58, 0x4A, 0x35, 0x49, 0x45, 0x4E, 0x6C, 0x63, 0x6E, 0x52, 0x70, 0x5A, 0x6D, 0x6C, 0x6A, 0x59,
        0x58, 0x52, 0x70, 0x62, 0x32, 0x34, 0x67, 0x51, 0x58, 0x56, 0x30, 0x61, 0x47, 0x39, 0x79, 0x0D,
        0x0A, 0x61, 0x58, 0x52, 0x35, 0x49, 0x43, 0x30, 0x67, 0x52, 0x7A, 0x55, 0x77, 0x67, 0x67, 0x45,
        0x69, 0x4D, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45,
        0x42, 0x41, 0x51, 0x55, 0x41, 0x41, 0x34, 0x49, 0x42, 0x44, 0x77, 0x41, 0x77, 0x67, 0x67, 0x45,
        0x4B, 0x41, 0x6F, 0x49, 0x42, 0x41, 0x51, 0x43, 0x76, 0x4A, 0x41, 0x67, 0x49, 0x4B, 0x58, 0x6F,
        0x31, 0x0D, 0x0A, 0x6E, 0x6D, 0x41, 0x4D, 0x71, 0x75, 0x64, 0x4C, 0x4F, 0x30, 0x37, 0x63, 0x66,
        0x4C, 0x77, 0x38, 0x52, 0x52, 0x79, 0x37, 0x4B, 0x2B, 0x44, 0x2B, 0x4B, 0x51, 0x4C, 0x35, 0x56,
        0x77, 0x69, 0x6A, 0x5A, 0x49, 0x55, 0x56, 0x4A, 0x2F, 0x58, 0x78, 0x72, 0x63, 0x67, 0x78, 0x69,
        0x56, 0x30, 0x69, 0x36, 0x43, 0x71, 0x71, 0x70, 0x6B, 0x4B, 0x7A, 0x6A, 0x2F, 0x69, 0x35, 0x56,
        0x62, 0x65, 0x78, 0x0D, 0x0A, 0x74, 0x30, 0x75, 0x7A, 0x2F, 0x6F, 0x39, 0x2B, 0x42, 0x31, 0x66,
        0x73, 0x37, 0x30, 0x50, 0x62, 0x5A, 0x6D, 0x49, 0x56, 0x59, 0x63, 0x39, 0x67, 0x44, 0x61, 0x54,
        0x59, 0x33, 0x76, 0x6A, 0x67, 0x77, 0x32, 0x49, 0x49, 0x50, 0x56, 0x51, 0x54, 0x36, 0x30, 0x6E,
        0x4B, 0x57, 0x56, 0x53, 0x46, 0x4A, 0x75, 0x55, 0x72, 0x6A, 0x78, 0x75, 0x66, 0x36, 0x2F, 0x57,
        0x68, 0x6B, 0x63, 0x49, 0x7A, 0x0D, 0x0A, 0x53, 0x64, 0x68, 0x44, 0x59, 0x32, 0x70, 0x53, 0x53,
        0x39, 0x4B, 0x50, 0x36, 0x48, 0x42, 0x52, 0x54, 0x64, 0x47, 0x4A, 0x61, 0x58, 0x76, 0x48, 0x63,
        0x50, 0x61, 0x7A, 0x33, 0x42, 0x4A, 0x30, 0x32, 0x33, 0x74, 0x64, 0x53, 0x31, 0x62, 0x54, 0x6C,
        0x72, 0x38, 0x56, 0x64, 0x36, 0x47, 0x77, 0x39, 0x4B, 0x49, 0x6C, 0x38, 0x71, 0x38, 0x63, 0x6B,
        0x6D, 0x63, 0x59, 0x35, 0x66, 0x51, 0x47, 0x0D, 0x0A, 0x42, 0x4F, 0x2B, 0x51, 0x75, 0x65, 0x51,
        0x41, 0x35, 0x4E, 0x30, 0x36, 0x74, 0x52, 0x6E, 0x2F, 0x41, 0x72, 0x72, 0x30, 0x50, 0x4F, 0x37,
        0x67, 0x69, 0x2B, 0x73, 0x33, 0x69, 0x2B, 0x7A, 0x30, 0x31, 0x36, 0x7A, 0x79, 0x39, 0x76, 0x41,
        0x39, 0x72, 0x39, 0x31, 0x31, 0x6B, 0x54, 0x4D, 0x5A, 0x48, 0x52, 0x78, 0x41, 0x79, 0x33, 0x51,
        0x6B, 0x47, 0x53, 0x47, 0x54, 0x32, 0x52, 0x54, 0x2B, 0x0D, 0x0A, 0x72, 0x43, 0x70, 0x53, 0x78,
        0x34, 0x2F, 0x56, 0x42, 0x45, 0x6E, 0x6B, 0x6A, 0x57, 0x4E, 0x48, 0x69, 0x44, 0x78, 0x70, 0x67,
        0x38, 0x76, 0x2B, 0x52, 0x37, 0x30, 0x72, 0x66, 0x6B, 0x2F, 0x46, 0x6C, 0x61, 0x34, 0x4F, 0x6E,
        0x64, 0x54, 0x52, 0x51, 0x38, 0x42, 0x6E, 0x63, 0x2B, 0x4D, 0x55, 0x43, 0x48, 0x37, 0x6C, 0x50,
        0x35, 0x39, 0x7A, 0x75, 0x44, 0x4D, 0x4B, 0x7A, 0x31, 0x30, 0x2F, 0x0D, 0x0A, 0x4E, 0x49, 0x65,
        0x57, 0x69, 0x75, 0x35, 0x54, 0x36, 0x43, 0x55, 0x56, 0x41, 0x67, 0x4D, 0x42, 0x41, 0x41, 0x47,
        0x6A, 0x67, 0x62, 0x49, 0x77, 0x67, 0x61, 0x38, 0x77, 0x44, 0x77, 0x59, 0x44, 0x56, 0x52, 0x30,
        0x54, 0x41, 0x51, 0x48, 0x2F, 0x42, 0x41, 0x55, 0x77, 0x41, 0x77, 0x45, 0x42, 0x2F, 0x7A, 0x41,
        0x4F, 0x42, 0x67, 0x4E, 0x56, 0x48, 0x51, 0x38, 0x42, 0x41, 0x66, 0x38, 0x45, 0x0D, 0x0A, 0x42,
        0x41, 0x4D, 0x43, 0x41, 0x51, 0x59, 0x77, 0x62, 0x51, 0x59, 0x49, 0x4B, 0x77, 0x59, 0x42, 0x42,
        0x51, 0x55, 0x48, 0x41, 0x51, 0x77, 0x45, 0x59, 0x54, 0x42, 0x66, 0x6F, 0x56, 0x32, 0x67, 0x57,
        0x7A, 0x42, 0x5A, 0x4D, 0x46, 0x63, 0x77, 0x56, 0x52, 0x59, 0x4A, 0x61, 0x57, 0x31, 0x68, 0x5A,
        0x32, 0x55, 0x76, 0x5A, 0x32, 0x6C, 0x6D, 0x4D, 0x43, 0x45, 0x77, 0x48, 0x7A, 0x41, 0x48, 0x0D,
        0x0A, 0x42, 0x67, 0x55, 0x72, 0x44, 0x67, 0x4D, 0x43, 0x47, 0x67, 0x51, 0x55, 0x6A, 0x2B, 0x58,
        0x54, 0x47, 0x6F, 0x61, 0x73, 0x6A, 0x59, 0x35, 0x72, 0x77, 0x38, 0x2B, 0x41, 0x61, 0x74, 0x52,
        0x49, 0x47, 0x43, 0x78, 0x37, 0x47, 0x53, 0x34, 0x77, 0x4A, 0x52, 0x59, 0x6A, 0x61, 0x48, 0x52,
        0x30, 0x63, 0x44, 0x6F, 0x76, 0x4C, 0x32, 0x78, 0x76, 0x5A, 0x32, 0x38, 0x75, 0x64, 0x6D, 0x56,
        0x79, 0x0D, 0x0A, 0x61, 0x58, 0x4E, 0x70, 0x5A, 0x32, 0x34, 0x75, 0x59, 0x32, 0x39, 0x74, 0x4C,
        0x33, 0x5A, 0x7A, 0x62, 0x47, 0x39, 0x6E, 0x62, 0x79, 0x35, 0x6E, 0x61, 0x57, 0x59, 0x77, 0x48,
        0x51, 0x59, 0x44, 0x56, 0x52, 0x30, 0x4F, 0x42, 0x42, 0x59, 0x45, 0x46, 0x48, 0x2F, 0x54, 0x5A,
        0x61, 0x66, 0x43, 0x33, 0x65, 0x79, 0x37, 0x38, 0x44, 0x41, 0x4A, 0x38, 0x30, 0x4D, 0x35, 0x2B,
        0x67, 0x4B, 0x76, 0x0D, 0x0A, 0x4D, 0x7A, 0x45, 0x7A, 0x4D, 0x41, 0x30, 0x47, 0x43, 0x53, 0x71,
        0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45, 0x42, 0x42, 0x51, 0x55, 0x41, 0x41, 0x34, 0x49,
        0x42, 0x41, 0x51, 0x43, 0x54, 0x4A, 0x45, 0x6F, 0x77, 0x58, 0x32, 0x4C, 0x50, 0x32, 0x42, 0x71,
        0x59, 0x4C, 0x7A, 0x33, 0x71, 0x33, 0x4A, 0x6B, 0x74, 0x76, 0x58, 0x66, 0x32, 0x70, 0x58, 0x6B,
        0x69, 0x4F, 0x4F, 0x7A, 0x45, 0x0D, 0x0A, 0x70, 0x36, 0x42, 0x34, 0x45, 0x71, 0x31, 0x69, 0x44,
        0x6B, 0x56, 0x77, 0x5A, 0x4D, 0x58, 0x6E, 0x6C, 0x32, 0x59, 0x74, 0x6D, 0x41, 0x6C, 0x2B, 0x58,
        0x36, 0x2F, 0x57, 0x7A, 0x43, 0x68, 0x6C, 0x38, 0x67, 0x47, 0x71, 0x43, 0x42, 0x70, 0x48, 0x33,
        0x76, 0x6E, 0x35, 0x66, 0x4A, 0x4A, 0x61, 0x43, 0x47, 0x6B, 0x67, 0x44, 0x64, 0x6B, 0x2B, 0x62,
        0x57, 0x34, 0x38, 0x44, 0x57, 0x37, 0x59, 0x0D, 0x0A, 0x35, 0x67, 0x61, 0x52, 0x51, 0x42, 0x69,
        0x35, 0x2B, 0x4D, 0x48, 0x74, 0x33, 0x39, 0x74, 0x42, 0x71, 0x75, 0x43, 0x57, 0x49, 0x4D, 0x6E,
        0x4E, 0x5A, 0x42, 0x55, 0x34, 0x67, 0x63, 0x6D, 0x55, 0x37, 0x71, 0x4B, 0x45, 0x4B, 0x51, 0x73,
        0x54, 0x62, 0x34, 0x37, 0x62, 0x44, 0x4E, 0x30, 0x6C, 0x41, 0x74, 0x75, 0x6B, 0x69, 0x78, 0x6C,
        0x45, 0x30, 0x6B, 0x46, 0x36, 0x42, 0x57, 0x6C, 0x4B, 0x0D, 0x0A, 0x57, 0x45, 0x39, 0x67, 0x79,
        0x6E, 0x36, 0x43, 0x61, 0x67, 0x73, 0x43, 0x71, 0x69, 0x55, 0x58, 0x4F, 0x62, 0x58, 0x62, 0x66,
        0x2B, 0x65, 0x45, 0x5A, 0x53, 0x71, 0x56, 0x69, 0x72, 0x32, 0x47, 0x33, 0x6C, 0x36, 0x42, 0x46,
        0x6F, 0x4D, 0x74, 0x45, 0x4D, 0x7A, 0x65, 0x2F, 0x61, 0x69, 0x43, 0x4B, 0x6D, 0x30, 0x6F, 0x48,
        0x77, 0x30, 0x4C, 0x78, 0x4F, 0x58, 0x6E, 0x47, 0x69, 0x59, 0x5A, 0x0D, 0x0A, 0x34, 0x66, 0x51,
        0x52, 0x62, 0x78, 0x43, 0x31, 0x6C, 0x66, 0x7A, 0x6E, 0x51, 0x67, 0x55, 0x79, 0x32, 0x38, 0x36,
        0x64, 0x55, 0x56, 0x34, 0x6F, 0x74, 0x70, 0x36, 0x46, 0x30, 0x31, 0x76, 0x76, 0x70, 0x58, 0x31,
        0x46, 0x51, 0x48, 0x4B, 0x4F, 0x74, 0x77, 0x35, 0x72, 0x44, 0x67, 0x62, 0x37, 0x4D, 0x7A, 0x56,
        0x49, 0x63, 0x62, 0x69, 0x64, 0x4A, 0x34, 0x76, 0x45, 0x5A, 0x56, 0x38, 0x4E, 0x0D, 0x0A, 0x68,
        0x6E, 0x61, 0x63, 0x52, 0x48, 0x72, 0x32, 0x6C, 0x56, 0x7A, 0x32, 0x58, 0x54, 0x49, 0x49, 0x4D,
        0x36, 0x52, 0x55, 0x74, 0x68, 0x67, 0x2F, 0x61, 0x46, 0x7A, 0x79, 0x51, 0x6B, 0x71, 0x46, 0x4F,
        0x46, 0x53, 0x44, 0x58, 0x39, 0x48, 0x6F, 0x4C, 0x50, 0x4B, 0x73, 0x45, 0x64, 0x61, 0x6F, 0x37,
        0x57, 0x4E, 0x71, 0x0D, 0x0A, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x45, 0x4E, 0x44, 0x20, 0x43, 0x45,
        0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D
};
int CA_KEY_LEN = 1758;

/* local variables ********************************************************** */
// Buffers
static unsigned char buf[CLIENT_BUFF_SIZE];
static unsigned char readbuf[CLIENT_BUFF_SIZE];

// Client Task/Timer Variables
static xTimerHandle     clientStreamTimerHandle      = POINTER_NULL;  // timer handle for data stream
static xTaskHandle      clientTaskHandler            = POINTER_NULL;  // task handle for MQTT Client
static uint8_t clientDataGetFlag = NUMBER_UINT8_ZERO;
static uint32_t clientMessageId = 0;

// Subscribe topics variables
char clientTopicRed[CLIENT_BUFF_SIZE];
char clientTopicOrange[CLIENT_BUFF_SIZE];
char clientTopicYellow[CLIENT_BUFF_SIZE];
char clientTopicDataGet[CLIENT_BUFF_SIZE];
char clientTopicDataStream[CLIENT_BUFF_SIZE];
const char *clientTopicRed_ptr = TOPIC_LED_RED;
const char *clientTopicOrange_ptr = TOPIC_LED_ORANGE;
const char *clientTopicYellow_ptr = TOPIC_LED_YELLOW;
const char *clientTopicDataGet_ptr = TOPIC_DATA_GET;
const char *clientTopicDataStream_ptr = TOPIC_DATA_STREAM;

/* global variables ********************************************************* */

/*************** Step 2 ***************/
/* Create a global variable of type SlSockSecureFiles_t, called certificates. */
SlSockSecureFiles_t certificates;    // AdeMike

// Network and Client Configuration
Network n;
Client c;

/* inline functions ********************************************************* */

/* local functions ********************************************************** */
static void clientRecv(MessageData* md);
static void clientTask(void *pvParameters);

/**
 * @brief callback function for subriptions
 *        toggles LEDS or sets read data flag
 *
 * @param[in] md - received message from the MQTT Broker
 *
 * @return NONE
 */
static void clientRecv(MessageData* md)
{
    /* Initialize Variables */
    MQTTMessage* message = md->message;

    if((strncmp(md->topicName->lenstring.data, clientTopicRed_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
        PTD_pinOutToggle(PTD_PORT_LED_RED, PTD_PIN_LED_RED);
    }
    else if((strncmp(md->topicName->lenstring.data, clientTopicOrange_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
        PTD_pinOutToggle(PTD_PORT_LED_ORANGE, PTD_PIN_LED_ORANGE);
    }
    else if((strncmp(md->topicName->lenstring.data, clientTopicYellow_ptr, md->topicName->lenstring.len) == 0)) {
        /* Toggle the Red LED  During Configurat */
        PTD_pinOutToggle(PTD_PORT_LED_YELLOW, PTD_PIN_LED_YELLOW);
    }
    else if((strncmp(md->topicName->lenstring.data, clientTopicDataGet_ptr, md->topicName->lenstring.len) == 0)) {
        /* Immediately Stream the Sensor Data */
        clientDataGetFlag = (uint8_t) ENABLED;
    }

    printf("Subscribed Topic, %.*s, Message Received: %.*s\r\n", md->topicName->lenstring.len, md->topicName->lenstring.data,
                                                               (int)message->payloadlen, (char*)message->payload);
}

/**
 * @brief publish sensor data, get sensor data, or
 *        yield mqtt client to check subscriptions
 *
 * @param[in] pvParameters UNUSED/PASSED THROUGH
 *
 * @return NONE
 */
static void clientTask(void *pvParameters)
{
    /* Initialize Variables */
    MQTTMessage msg;

    /* Forever Loop Necessary for freeRTOS Task */
    for(;;)
    {
        WDG_feedingWatchdog();
        /* Publish Live Data Stream */
        if(sensorStreamBuffer.length > NUMBER_UINT32_ZERO)
        {
            msg.id = clientMessageId++;
            msg.qos = 0;
            msg.payload = sensorStreamBuffer.data;
            msg.payloadlen = sensorStreamBuffer.length;
            MQTTPublish(&c, clientTopicDataStream_ptr, &msg);

            memset(sensorStreamBuffer.data, 0x00, SENSOR_DATA_BUF_SIZE);
            sensorStreamBuffer.length = NUMBER_UINT32_ZERO;
        }
        else if(clientDataGetFlag) {
            sensorStreamData(pvParameters);
            clientDataGetFlag = DISABLED;
        }
        else {
            MQTTYield(&c, CLIENT_YIELD_TIMEOUT);
        }
    }
}

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

/**
 * @brief starts the data streaming timer
 *
 * @return NONE
 */
void clientStartTimer(void)
{
    /* Start the timers */
    xTimerStart(clientStreamTimerHandle, UINT32_MAX);
    return;
}
/**
 * @brief stops the data streaming timer
 *
 * @return NONE
 */
void clientStopTimer(void)
{
    /* Stop the timers */
    xTimerStop(clientStreamTimerHandle, UINT32_MAX);
    return;
}

/**
 * @brief Initializes the MQTT Paho Client, set up subscriptions and initializes the timers and tasks
 *
 * @return NONE
 */


// AdeMike from HTTPS

/*************** Step 5 ***************/
// Flash the Certificate BEFORE attempting to connect.
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)12;
    dateTime.sl_tm_mon =   (_u32)3;
    dateTime.sl_tm_year =  (_u32)2017;
    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;

    // AdeMike Keys
    /*************** Step 7 ***************/
    /****** For PRIV ******/
    sl_FsOpen(
            (_u8*) PRIV_FILE_NAME,
            FS_MODE_OPEN_CREATE(
                    4*1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
            ),
            NULL,
            &fileHandle
    );
    _i32 writtenLen_PRIV = sl_FsWrite(fileHandle, 0, PRIV_KEY, PRIV_KEY_LEN);
    printf("Written Length for %s: %d\n\r", PRIV_FILE_NAME, (int) writtenLen_PRIV);
    sl_FsClose(fileHandle, NULL, NULL, 0);
    fileHandle = 0;

    /****** For CERT ******/
    sl_FsOpen(
            (_u8*) CERT_FILE_NAME,
            FS_MODE_OPEN_CREATE(
                    4*1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
            ),
            NULL,
            &fileHandle
    );
    _i32 writtenLen_CERT = sl_FsWrite(fileHandle, 0, CERT_KEY, CERT_KEY_LEN);
    printf("Written Length for %s: %d\n\r", CERT_FILE_NAME, (int) writtenLen_CERT);
    sl_FsClose(fileHandle, NULL, NULL, 0);
    fileHandle = 0;

    /****** For CA ******/
    sl_FsOpen(
            (_u8*) CA_FILE_NAME,
            FS_MODE_OPEN_CREATE(
                    4*1024, _FS_FILE_PUBLIC_WRITE | _FS_FILE_PUBLIC_READ
            ),
            NULL,
            &fileHandle
    );
    _i32 writtenLen_CA = sl_FsWrite(fileHandle, 0, CA_KEY, CA_KEY_LEN);
    printf("Written Length for %s: %d\n\r", CA_FILE_NAME, (int) writtenLen_CA);
    sl_FsClose(fileHandle, NULL, NULL, 0);
    fileHandle = 0;

    }

void clientInit(void)
{
    /* Initialize Variables */
    int rc = 0;
    NewNetwork(&n);

    /*************** Step 3 ***************/
    flashCertificates();        // AdeMike
    // ConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT);

    /*************** Step 4 ***************/
    TLSConnectNetwork(&n, MQTT_BROKER_NAME, MQTT_PORT, &certificates, SL_SO_SEC_METHOD_TLSV1_2, SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256, 0);    // AdeMike
    MQTTClient(&c, &n, 1000, buf, CLIENT_BUFF_SIZE, readbuf, CLIENT_BUFF_SIZE);

    /* Configure the MQTT Connection Data */
    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.willFlag = 0;
    data.MQTTVersion = 3;
    data.clientID.cstring = MQTT_CLIENT_ID;
    data.keepAliveInterval = 100;
    data.cleansession = 1;

    printf("Connecting to %s %d\r\n", MQTT_BROKER_NAME, MQTT_PORT);

    /* Connect to the MQTT Broker */
    rc = MQTTConnect(&c, &data);

    /* Set Subscribe Topic Strings */
    memset(clientTopicRed, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicRed, TOPIC_LED_RED, (const char*) MQTT_CLIENT_ID);
    clientTopicRed_ptr = (char*) clientTopicRed;

    memset(clientTopicOrange, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicOrange, TOPIC_LED_ORANGE, (const char*) MQTT_CLIENT_ID);
    clientTopicOrange_ptr = (char*) clientTopicOrange;

    memset(clientTopicYellow, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicYellow, TOPIC_LED_YELLOW, (const char*) MQTT_CLIENT_ID);
    clientTopicYellow_ptr = (char*) clientTopicYellow;

    memset(clientTopicDataGet, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicDataGet, TOPIC_DATA_GET, (const char*) MQTT_CLIENT_ID);
    clientTopicDataGet_ptr = (char*) clientTopicDataGet;

    memset(clientTopicDataStream, 0x00, CLIENT_BUFF_SIZE);
    sprintf((char*) clientTopicDataStream, TOPIC_DATA_STREAM, (const char*) MQTT_CLIENT_ID);
    clientTopicDataStream_ptr = (char*) clientTopicDataStream;

    /* Subscribe to the Topics (set callback functions) */
    rc = MQTTSubscribe(&c, clientTopicRed_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicOrange_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicYellow_ptr, QOS0, clientRecv);
    rc = MQTTSubscribe(&c, clientTopicDataGet_ptr, QOS0, clientRecv);

    /* Create Live Data Stream Timer */
    clientStreamTimerHandle = xTimerCreate(
            (const char * const) "Data Stream",
            STREAM_RATE,
            TIMER_AUTORELOAD_ON,
            NULL,
            sensorStreamData);

    /* Create MQTT Client Task */
    rc = xTaskCreate(clientTask, (const char * const) "Mqtt Client App",
                            CLIENT_TASK_STACK_SIZE, NULL, CLIENT_TASK_PRIORITY, &clientTaskHandler);

    /* Error Occured Exit App */
    if(rc < 0)
    {
        clientDeinit();
    }

    return;
}

/**
 * @brief Disconnect from the MQTT Client
 *
 * @return NONE
 */
void clientDeinit(void)
{
    MQTTDisconnect(&c);
    n.disconnect(&n);
}
 

mqttXDK.c
===================

/*******************************************************************************
 * Copyright (c) 2014 IBM Corp.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 *
 * The Eclipse Public License is available at
 *    http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 *   http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *    Allan Stockdill-Mander - initial API and implementation and/or initial documentation
 *******************************************************************************/
/******************************************************************************
**    COPYRIGHT (c) 2016        Bosch Connected Devices and Solutions GmbH
**
**    The use of this software is subject to the XDK SDK EULA
**
*******************************************************************************
**
**    OBJECT NAME:    mqttXDK.c
**
**    DESCRIPTION:    Links the Paho MQTT Client to the XDK Platform
**
**    PURPOSE:        Defines the timer and network functions
**                    the Paho Stack uses to interface with the platform
**
**    AUTHOR(S):      Bosch Connected Devices and Solutions GmbH (BCDS)
**
**    Revision History:
**
**    Date             Name        Company      Description
**  2016.Apr         crk        BCDS         Edited Paho's CC3200 Platform source
**                                           to port code to the XDK Platform
**
*******************************************************************************/

/* system header files */
#include <stdint.h>

/* interface header files */
#include "BCDS_PowerMgt.h"

/* own header files */
#include "mqttXDK.h"

/* AdeMike */
#define PRIV_FILE_NAME "privkey.der"
#define CERT_FILE_NAME "cert.der"
#define CA_FILE_NAME "aws-iot-rootCA.der"

char expired(Timer* timer) {
    long left = timer->end_time - PowerMgt_GetSystemTimeMs();
    return (left < 0);
}


void countdown_ms(Timer* timer, unsigned int timeout) {
    timer->end_time = PowerMgt_GetSystemTimeMs() + timeout;
}


void countdown(Timer* timer, unsigned int timeout) {
    timer->end_time = PowerMgt_GetSystemTimeMs() + (timeout * 1000);
}


int left_ms(Timer* timer) {
    long left = timer->end_time - PowerMgt_GetSystemTimeMs();
    return (left < 0) ? 0 : left;
}


void InitTimer(Timer* timer) {
    timer->end_time = 0;
}


int xdk_read(Network* n, uint8_t* buffer, int len, int timeout_ms) {
    SlTimeval_t timeVal;
    SlFdSet_t fdset;
    int rc = 0;
    int recvLen = 0;

    SL_FD_ZERO(&fdset);
    SL_FD_SET(n->my_socket, &fdset);

    timeVal.tv_sec = 0;
    timeVal.tv_usec = timeout_ms * 1000;
    if (sl_Select(n->my_socket + 1, &fdset, NULL, NULL, &timeVal) == 1) {
        do {
            rc = sl_Recv(n->my_socket, buffer + recvLen, len - recvLen, 0);
            recvLen += rc;
        } while(recvLen < len);
    }
    return recvLen;
}

int xdk_write(Network* n, uint8_t* buffer, int len, int timeout_ms) {
    SlTimeval_t timeVal;
    SlFdSet_t fdset;
    int rc = 0;
    int readySock;

    SL_FD_ZERO(&fdset);
    SL_FD_SET(n->my_socket, &fdset);

    timeVal.tv_sec = 0;
    timeVal.tv_usec = timeout_ms * 1000;
    do {
        readySock = sl_Select(n->my_socket + 1, NULL, &fdset, NULL, &timeVal);
    } while(readySock != 1);
    rc = sl_Send(n->my_socket, buffer, len, 0);
    return rc;
}
void xdk_disconnect(Network* n) {
    sl_Close(n->my_socket);
}

void NewNetwork(Network* n) {
    n->my_socket = 0;
    n->mqttread = xdk_read;
    n->mqttwrite = xdk_write;
    n->disconnect = xdk_disconnect;
}

int TLSConnectNetwork(Network *n, char* addr, int port, SlSockSecureFiles_t* certificates, unsigned char sec_method, unsigned int cipher, char server_verify) {
    SlSockAddrIn_t sAddr;
    int addrSize;
    int retVal;
    unsigned long ipAddress;

    retVal = sl_NetAppDnsGetHostByName((_i8*) addr, strlen(addr), &ipAddress, AF_INET);
    if (retVal < 0) {
        return -1;
    }

    sAddr.sin_family = AF_INET;
    sAddr.sin_port = sl_Htons((unsigned short)port);
    sAddr.sin_addr.s_addr = sl_Htonl(ipAddress);

    addrSize = sizeof(SlSockAddrIn_t);

    n->my_socket = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
    if (n->my_socket < 0) {
        return -1;
    }

    SlSockSecureMethod method;
    method.secureMethod = sec_method;
    retVal = sl_SetSockOpt(n->my_socket, SL_SOL_SOCKET, SL_SO_SECMETHOD, &method, sizeof(method));
    if (retVal < 0) {
        return retVal;
    }

    SlSockSecureMask mask;
    mask.secureMask = cipher;
    retVal = sl_SetSockOpt(n->my_socket, SL_SOL_SOCKET, SL_SO_SECURE_MASK, &mask, sizeof(mask));
    if (retVal < 0) {
        return retVal;
    }

    /* AdeMike */
    sl_SetSockOpt(
      n->my_socket,
      SL_SOL_SOCKET,
      SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,
      PRIV_FILE_NAME,
      strlen(PRIV_FILE_NAME)
    );

    sl_SetSockOpt(
      n->my_socket,
      SL_SOL_SOCKET,
      SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,
      CERT_FILE_NAME,
      strlen(CERT_FILE_NAME)
    );

    sl_SetSockOpt(
      n->my_socket,
      SL_SOL_SOCKET,
      SL_SO_SECURE_FILES_CA_FILE_NAME,
      CA_FILE_NAME,
      strlen(CA_FILE_NAME)
    );

    retVal = sl_Connect(n->my_socket, ( SlSockAddr_t *)&sAddr, addrSize);
    if( retVal < 0 ) {
        if (server_verify || retVal != -453) {
            sl_Close(n->my_socket);
            return retVal;
        }
    }

    return retVal;
}

int ConnectNetwork(Network* n, char* addr, int port)
{
    SlSockAddrIn_t sAddr;
    int addrSize;
    int retVal = -1;
    unsigned long ipAddress;

    sl_NetAppDnsGetHostByName((_i8*) addr, strlen((char*)addr), &ipAddress, AF_INET);

    sAddr.sin_family = AF_INET;
    sAddr.sin_port = sl_Htons((unsigned short)port);
    sAddr.sin_addr.s_addr = sl_Htonl(ipAddress);

    addrSize = sizeof(SlSockAddrIn_t);

    n->my_socket = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
    if( n->my_socket < 0 ) {
        // error
        return -1;
    }

    retVal = sl_Connect(n->my_socket, ( SlSockAddr_t *)&sAddr, addrSize);
    if( retVal < 0 ) {
        // error
        sl_Close(n->my_socket);
        return retVal;
    }

    return retVal;
}
 

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
14.08.17 14:05 als Antwort auf Michael Ng.

Hello Michael,

the errors regarding unresolved variables can be solved by right clicking your project, browsing down to Index and then clicking rebuild. This issue only occurs, because the XDK Workbench's static checks cannot find the variables and types. The compiler will still be able to find them.

Regarding your second error undefined reference to flashCertificates mqttPahoClient.c. This is because you defined the function with the name flashCertificate(), but you use the function with the name flashCertificates(). To solve this, either rename the function's definition to flashCertificates() or rename the function's call inside the function clientInit() to flashCertificate().

Afterwards, your code should be able to be built without any issues.

Please let me know if this was helpful and do not hesitate to ask if you have further questions.

Kind regards,
Franjo

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
15.08.17 04:50 als Antwort auf Franjo Stjepandic.

Hi Franjo,

When I flash the firmware codes into XDK 110 devices, it nearly be successful worked. However, this was the response:

 INFO | MICHAEL: Ip address of the device: 192.168.2.182 
 INFO | MICHAEL: MAC address of the device: XX:XX:XX:XX:XX:XX 
 INFO | MICHAEL: Written Length for privkey.der: -100
 INFO | MICHAEL: Written Length for cert.der: -100
 INFO | MICHAEL: Written Length for aws-iot-rootCA.der: -100
 INFO | MICHAEL: Connecting to xxxxxxxxxxx.iot.ap-southeast-1.amazonaws.com 8883

The connection cannot be established successfully.

Regards.

Michael.

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
15.08.17 12:13 als Antwort auf Michael Ng.

Great work - if you finally have a working solution please let me know and i will try do this also.

Amazon AWS - i do actually a lot of stuff here also with XDK, Alexa, Firestick...
At the moment i have my own applications (MQTT and HTTP) running - they communicate with the XDK - and my software is able to send data to the Bosch IoT Cloud, Relayr Cloud, my own cloud, Cayenne, DeviceBit, Adafruit, Blynk ... etc. This was my power gateway solution to get rid of the XDK problems sending his data directly.

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
15.08.17 13:03 als Antwort auf Achim Kern.

Hello Michael,

the error code -100 is returned when the length for Fs_Write() is too long. The maximum is 1024, and I forgot to take that into regard as well.

You could replace each of the write operations in flashCertificates():

_i32 writtenLen_CA = sl_FsWrite(fileHandle, 0, (_u8 *) CA_KEY, CA_KEY_LEN);
printf("Written Length for %s: %d\n\r", CA_FILE_NAME, (int) writtenLen_CA);

with the following code:

_i32 writtenLen_CA = sl_FsWrite(fileHandle, 0, (_u8 *) CA_KEY, 1024);
printf("1. Written Length for %s: %d\n\r", CA_FILE_NAME, (int) writtenLen_CA);
writtenLen_CA = sl_FsWrite(fileHandle, 1024, (_u8 *) CA_KEY, CA_KEY_LEN - 1024);
printf("2. Written Length for %s: %d\n\r", CA_FILE_NAME, (int) writtenLen_CA);

This code will write the 1024 bytes, and then the rest of the bytes that have not been written yet. Remember to rename the variables for each file, this example shows the rootCA file. Do this for the privkey and cert accordingly.

The prints should respectively sum up to each file length. For example, it should be 1758 for the rootCA file.

Kind regards,
Franjo

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
28.08.17 02:33 als Antwort auf Franjo Stjepandic.

Hi Franjo,

Sorry for delay to update cause recently very busy for works. 

Anyway, the codes finally worked with no error.

However, still cannot be connected.

Is it my certificates got problem and I need to create a new ones?

Or my mqtt Topic not matched?
 

Here are the outputs.

 INFO | MICHAEL: 1. Written Length for privkey.der: 1024
 INFO | MICHAEL: 2. Written Length for privkey.der: 651
 INFO | MICHAEL: 1. Written Length for cert.der: 1024
 INFO | MICHAEL: 2. Written Length for cert.der: 196
 INFO | MICHAEL: 1. Written Length for aws-iot-rootCA.der: 1024
 INFO | MICHAEL: 2. Written Length for aws-iot-rootCA.der: 734
 INFO | MICHAEL: Connecting to xxxxxxxxxx.iot.ap-southeast-1.amazonaws.com 8883

Please advise.

Many Thanks.

Michael.

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
25.08.17 14:18 als Antwort auf Michael Ng.

Hello Michael,

at this point, I am quite sure that the certificates are flashed correctly onto the XDK. They also seem to be set as security options correctly. I would like to know how you verified whether the XDK can connect or not.

To verify whether your XDK connected, I recommend to take a look at the return code of MQTTConnect(). This function is called in mqttPahoClient.c inside the function clientInit() some lines below TLSConnectNetwork().

If the return code is a negative number (either -1 or -2), an error occured. If it is exactly 0, the connection was successful. If it is -1, I recommend to enable logging in your AWS IoT setup, so that you will be able to verify whether the broker actually receives a connection attempt by the XDK.

At this point, it is difficult to provide an accurate diagnosis of the issue, since it is no longer related to building or programming the application, but a networking issue instead. Therefore, I cannot pinpoint the problem to whether your certificates are the problem or if the topic does not match.

Kind regards,
Franjo

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
28.08.17 04:55 als Antwort auf Franjo Stjepandic.

Dear Franjo,

Can I insert the verification code as follow?

    /* Connect to the MQTT Broker */
    rc = MQTTConnect(&c, &data);

    printf("Connecting code is %d\r\n", rc);

Michael.

 

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
28.08.17 15:55 als Antwort auf Michael Ng.

Hello Michael,

you can, of course, insert the verification code as posted.

Kind regards,
Franjo

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
16.07.18 14:07 als Antwort auf Franjo Stjepandic.

Hi All,

 

Does anyone have a updated version of this, or can point me to a version which works on Workbence 3.x?

 

Thanks!

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
23.07.18 08:04 als Antwort auf Michael O'Malley.
Hello Michael,

Unfortunately, the MQTT paho demo mentioned in this thread is since the release of the XDK-Workbench 3.0.0 no longer available for download in the XDK community.

If you require the functionality to send sensor data over MQTT to AWS then you would need to implement that on your own.

For that, you can use the explanations I made in this thread here . There I explained in detail what is required to make a connection over MQTT to the AWS IoT Core, but I assume the same principles apply to your use case too.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
23.07.18 07:52 als Antwort auf Franjo Stjepandic.

Hello Franjo & Micheal,

I followed above codings but I'm getting error  -456

SL_ESECBADCAFILE                      (-456)  /* error secure level bad CA file */

I tested my DER with openssl and it works.

openssl s_client -connect ajx5lv34md62c.iot.ap-southeast-1.amazonaws.com:8883 -CAfile root-CA.der -keyform der -key XDK110-private.der -keyform der -cert XDK110-cert.der -certform DER

PEM & DER files at https://we.tl/TLB7PnS241

 

Kindly advise.

 

0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
23.07.18 13:11 als Antwort auf L CC.
Hello L CC,

could you please tell me how long the certificate is you try to use ?

If it's longer than 1024 bytes or even longer than 2048 bytes, then you need to loop the writing process. For looping the writing process, you can use the following code snippet:

 
_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)
     );
}


Please let me know if that was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Stimmen)
RE: MQTT-PAHO and AWS IoT
Antwort
23.07.18 15:10 als Antwort auf Franjo Stjepandic.

Hi Franjo,

You are correct. It was the issue when writing the certs.

I have solved it and now have successfully published MQTT with TLS.

Thanks so much.

 

 

0 (0 Stimmen)