aws-iot-sdk: patch aws iot sdk samples code to properly work on our platforms

This patch modifies the code of some of the provided samples to be able to run
them in our platforms. By default, these applications cannot find the
certificates in the device, and the command line options are not working.

Patched samples:
 * shadow_sample
 * shadow_sample_console_echo
 * subscribe_publish_sample

See https://github.com/aws/aws-iot-device-sdk-embedded-C.

https://jira.digi.com/browse/DEL-4101

Signed-off-by: Tatiana Leon <tatiana.leon@digi.com>
This commit is contained in:
Tatiana Leon 2017-05-05 18:25:41 +02:00
parent 8a1a67f592
commit c525e2caaf
2 changed files with 150 additions and 0 deletions

View File

@ -0,0 +1,149 @@
From: Tatiana Leon <tatiana.leon@digi.com>
Date: Wed, 3 May 2017 18:12:52 +0200
Subject: [PATCH] aws-iot-samples: modify provided samples to work in our
platforms
Signed-off-by: Tatiana Leon <tatiana.leon@digi.com>
---
samples/linux/shadow_sample/shadow_sample.c | 20 ++++++++++----------
.../shadow_sample_console_echo/shadow_console_echo.c | 20 ++++++++++----------
.../subscribe_publish_sample.c | 12 ++++++------
3 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/samples/linux/shadow_sample/shadow_sample.c b/samples/linux/shadow_sample/shadow_sample.c
index 9a0b270..fc73a2d 100644
--- a/samples/linux/shadow_sample/shadow_sample.c
+++ b/samples/linux/shadow_sample/shadow_sample.c
@@ -59,7 +59,7 @@
#define MAX_LENGTH_OF_UPDATE_JSON_BUFFER 200
-static char certDirectory[PATH_MAX + 1] = "../../../certs";
+static char certDirectory[PATH_MAX + 1] = "";
static char HostAddress[255] = AWS_IOT_MQTT_HOST;
static uint32_t port = AWS_IOT_MQTT_PORT;
static uint8_t numPubs = 5;
@@ -164,27 +164,27 @@ int main(int argc, char **argv) {
char rootCA[PATH_MAX + 1];
char clientCRT[PATH_MAX + 1];
char clientKey[PATH_MAX + 1];
- char CurrentWD[PATH_MAX + 1];
IOT_INFO("\nAWS IoT SDK Version %d.%d.%d-%s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
- getcwd(CurrentWD, sizeof(CurrentWD));
- snprintf(rootCA, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_ROOT_CA_FILENAME);
- snprintf(clientCRT, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_CERTIFICATE_FILENAME);
- snprintf(clientKey, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_PRIVATE_KEY_FILENAME);
+ parseInputArgsForConnectParams(argc, argv);
+
+ if (certDirectory[0] == '\0')
+ snprintf(certDirectory, PATH_MAX + 1, "%s", "/etc/ssl/certs");
+ snprintf(rootCA, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_ROOT_CA_FILENAME);
+ snprintf(clientCRT, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_CERTIFICATE_FILENAME);
+ snprintf(clientKey, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_PRIVATE_KEY_FILENAME);
IOT_DEBUG("rootCA %s", rootCA);
IOT_DEBUG("clientCRT %s", clientCRT);
IOT_DEBUG("clientKey %s", clientKey);
- parseInputArgsForConnectParams(argc, argv);
-
// initialize the mqtt client
AWS_IoT_Client mqttClient;
ShadowInitParameters_t sp = ShadowInitParametersDefault;
- sp.pHost = AWS_IOT_MQTT_HOST;
- sp.port = AWS_IOT_MQTT_PORT;
+ sp.pHost = HostAddress;
+ sp.port = port;
sp.pClientCRT = clientCRT;
sp.pClientKey = clientKey;
sp.pRootCA = rootCA;
diff --git a/samples/linux/shadow_sample_console_echo/shadow_console_echo.c b/samples/linux/shadow_sample_console_echo/shadow_console_echo.c
index 1c491fb..e333094 100644
--- a/samples/linux/shadow_sample_console_echo/shadow_console_echo.c
+++ b/samples/linux/shadow_sample_console_echo/shadow_console_echo.c
@@ -53,7 +53,7 @@
* @note Ensure the buffer sizes in aws_iot_config.h are big enough to receive the delta message. The delta message will also contain the metadata with the timestamps
*/
-char certDirectory[PATH_MAX + 1] = "../../../certs";
+char certDirectory[PATH_MAX + 1] = "";
char HostAddress[255] = AWS_IOT_MQTT_HOST;
uint32_t port = AWS_IOT_MQTT_PORT;
bool messageArrivedOnDelta = false;
@@ -80,27 +80,27 @@ int main(int argc, char** argv) {
char rootCA[PATH_MAX + 1];
char clientCRT[PATH_MAX + 1];
char clientKey[PATH_MAX + 1];
- char CurrentWD[PATH_MAX + 1];
IOT_INFO("\nAWS IoT SDK Version %d.%d.%d-%s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
- getcwd(CurrentWD, sizeof(CurrentWD));
- snprintf(rootCA, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_ROOT_CA_FILENAME);
- snprintf(clientCRT, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_CERTIFICATE_FILENAME);
- snprintf(clientKey, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_PRIVATE_KEY_FILENAME);
+ parseInputArgsForConnectParams(argc, argv);
+
+ if (certDirectory[0] == '\0')
+ snprintf(certDirectory, PATH_MAX + 1, "%s", "/etc/ssl/certs");
+ snprintf(rootCA, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_ROOT_CA_FILENAME);
+ snprintf(clientCRT, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_CERTIFICATE_FILENAME);
+ snprintf(clientKey, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_PRIVATE_KEY_FILENAME);
IOT_DEBUG("rootCA %s", rootCA);
IOT_DEBUG("clientCRT %s", clientCRT);
IOT_DEBUG("clientKey %s", clientKey);
- parseInputArgsForConnectParams(argc, argv);
-
// initialize the mqtt client
AWS_IoT_Client mqttClient;
ShadowInitParameters_t sp = ShadowInitParametersDefault;
- sp.pHost = AWS_IOT_MQTT_HOST;
- sp.port = AWS_IOT_MQTT_PORT;
+ sp.pHost = HostAddress;
+ sp.port = port;
sp.pClientCRT = clientCRT;
sp.pClientKey = clientKey;
sp.pRootCA = rootCA;
diff --git a/samples/linux/subscribe_publish_sample/subscribe_publish_sample.c b/samples/linux/subscribe_publish_sample/subscribe_publish_sample.c
index 4f92645..d0fef05 100644
--- a/samples/linux/subscribe_publish_sample/subscribe_publish_sample.c
+++ b/samples/linux/subscribe_publish_sample/subscribe_publish_sample.c
@@ -40,7 +40,7 @@
/**
* @brief Default cert location
*/
-char certDirectory[PATH_MAX + 1] = "../../../certs";
+char certDirectory[PATH_MAX + 1] = "";
/**
* @brief Default MQTT HOST URL is pulled from the aws_iot_config.h
@@ -132,7 +132,6 @@ int main(int argc, char **argv) {
char rootCA[PATH_MAX + 1];
char clientCRT[PATH_MAX + 1];
char clientKey[PATH_MAX + 1];
- char CurrentWD[PATH_MAX + 1];
char cPayload[100];
int32_t i = 0;
@@ -150,10 +149,11 @@ int main(int argc, char **argv) {
IOT_INFO("\nAWS IoT SDK Version %d.%d.%d-%s\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
- getcwd(CurrentWD, sizeof(CurrentWD));
- snprintf(rootCA, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_ROOT_CA_FILENAME);
- snprintf(clientCRT, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_CERTIFICATE_FILENAME);
- snprintf(clientKey, PATH_MAX + 1, "%s/%s/%s", CurrentWD, certDirectory, AWS_IOT_PRIVATE_KEY_FILENAME);
+ if (certDirectory[0] == '\0')
+ snprintf(certDirectory, PATH_MAX + 1, "%s", "/etc/ssl/certs");
+ snprintf(rootCA, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_ROOT_CA_FILENAME);
+ snprintf(clientCRT, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_CERTIFICATE_FILENAME);
+ snprintf(clientKey, PATH_MAX + 1, "%s/%s", certDirectory, AWS_IOT_PRIVATE_KEY_FILENAME);
IOT_DEBUG("rootCA %s", rootCA);
IOT_DEBUG("clientCRT %s", clientCRT);

View File

@ -10,6 +10,7 @@ DEPENDS = "mbedtls"
SRC_URI = " \ SRC_URI = " \
https://github.com/aws/aws-iot-device-sdk-embedded-C/archive/v${PV}.tar.gz \ https://github.com/aws/aws-iot-device-sdk-embedded-C/archive/v${PV}.tar.gz \
file://0001-aws-iot-samples-modify-provided-samples-to-work-in-o.patch \
file://aws_iot_config.h.template \ file://aws_iot_config.h.template \
file://awsiotsdk.pc \ file://awsiotsdk.pc \
file://Makefile \ file://Makefile \