From 3925ab5abf0abf8782b2ddce8092d6f382a16efe Mon Sep 17 00:00:00 2001 From: Archit Aggarwal Date: Thu, 13 Aug 2020 18:27:11 +0000 Subject: [PATCH 1/2] Add #ifndefs around config macros in demos to allow them to be overridden --- demos/mqtt/mqtt_demo_basic_tls/demo_config.h | 12 ++++++++---- demos/mqtt/mqtt_demo_lightweight/demo_config.h | 4 +++- demos/mqtt/mqtt_demo_plaintext/demo_config.h | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/demos/mqtt/mqtt_demo_basic_tls/demo_config.h b/demos/mqtt/mqtt_demo_basic_tls/demo_config.h index 2d7ff9dcdd..501fa99567 100644 --- a/demos/mqtt/mqtt_demo_basic_tls/demo_config.h +++ b/demos/mqtt/mqtt_demo_basic_tls/demo_config.h @@ -56,26 +56,30 @@ * the instructions in https://mosquitto.org/ for running a Mosquitto broker * locally. */ -#define BROKER_ENDPOINT "test.mosquitto.org" +#ifndef BROKER_ENDPOINT + #define BROKER_ENDPOINT "test.mosquitto.org" +#endif /** * @brief Length of MQTT server host name. */ -#define BROKER_ENDPOINT_LENGTH ( ( uint16_t ) ( sizeof( BROKER_ENDPOINT ) - 1 ) ) +#define BROKER_ENDPOINT_LENGTH ( ( uint16_t ) ( sizeof( BROKER_ENDPOINT ) - 1 ) ) /** * @brief MQTT server port number. * * In general, port 8883 is for secured MQTT connections. */ -#define BROKER_PORT ( 8883 ) +#define BROKER_PORT ( 8883 ) /** * @brief Path of the file containing the server's root CA certificate. * * This certificate should be PEM-encoded. */ -#define ROOT_CA_CERT_PATH "certificates/mosquitto.org.crt" +#ifndef ROOT_CA_CERT_PATH + #define ROOT_CA_CERT_PATH "certificates/mosquitto.org.crt" +#endif /** * @brief Length of path to server certificate. diff --git a/demos/mqtt/mqtt_demo_lightweight/demo_config.h b/demos/mqtt/mqtt_demo_lightweight/demo_config.h index da90a63df9..a122f4ac5d 100644 --- a/demos/mqtt/mqtt_demo_lightweight/demo_config.h +++ b/demos/mqtt/mqtt_demo_lightweight/demo_config.h @@ -53,7 +53,9 @@ * This demo uses the Mosquitto test server. This is a public MQTT server; do not * publish anything sensitive to this server. */ -#define BROKER_ENDPOINT "test.mosquitto.org" +#ifndef BROKER_ENDPOINT + #define BROKER_ENDPOINT "test.mosquitto.org" +#endif /** * @brief Length of MQTT server host name. diff --git a/demos/mqtt/mqtt_demo_plaintext/demo_config.h b/demos/mqtt/mqtt_demo_plaintext/demo_config.h index 8fbe99cc26..3854c616dc 100644 --- a/demos/mqtt/mqtt_demo_plaintext/demo_config.h +++ b/demos/mqtt/mqtt_demo_plaintext/demo_config.h @@ -53,7 +53,9 @@ * This demo uses the Mosquitto test server. This is a public MQTT server; do not * publish anything sensitive to this server. */ -#define BROKER_ENDPOINT "test.mosquitto.org" +#ifndef BROKER_ENDPOINT + #define BROKER_ENDPOINT "test.mosquitto.org" +#endif /** * @brief MQTT server port number. From 30e60b7a65df56e6849a1137f7ba41666a7c5618 Mon Sep 17 00:00:00 2001 From: Archit Aggarwal Date: Thu, 13 Aug 2020 18:54:09 +0000 Subject: [PATCH 2/2] Add #error statements for BROKER_ENDPOINT in demo source files --- demos/mqtt/mqtt_demo_basic_tls/mqtt_demo_basic_tls.c | 5 ++++- demos/mqtt/mqtt_demo_lightweight/mqtt_demo_lightweight.c | 5 +++++ demos/mqtt/mqtt_demo_plaintext/mqtt_demo_plaintext.c | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/demos/mqtt/mqtt_demo_basic_tls/mqtt_demo_basic_tls.c b/demos/mqtt/mqtt_demo_basic_tls/mqtt_demo_basic_tls.c index af35cbfea3..21da0a2b18 100644 --- a/demos/mqtt/mqtt_demo_basic_tls/mqtt_demo_basic_tls.c +++ b/demos/mqtt/mqtt_demo_basic_tls/mqtt_demo_basic_tls.c @@ -61,8 +61,11 @@ * These configuration settings are required to run the basic TLS demo. * Throw compilation error if the below configs are not defined. */ +#ifndef BROKER_ENDPOINT + #error "Please define an MQTT broker endpoint, BROKER_ENDPOINT, in demo_config.h." +#endif #ifndef ROOT_CA_CERT_PATH - #error "Please define path to Root CA certificate of the MQTT broker(ROOT_CA_CERT_PATH) in demo_config.h." + #error "Please define path to Root CA certificate of the MQTT broker, ROOT_CA_CERT_PATH, in demo_config.h." #endif #ifndef CLIENT_IDENTIFIER #error "Please define a unique CLIENT_IDENTIFIER." diff --git a/demos/mqtt/mqtt_demo_lightweight/mqtt_demo_lightweight.c b/demos/mqtt/mqtt_demo_lightweight/mqtt_demo_lightweight.c index fb6cfb7f0e..03f6516c13 100644 --- a/demos/mqtt/mqtt_demo_lightweight/mqtt_demo_lightweight.c +++ b/demos/mqtt/mqtt_demo_lightweight/mqtt_demo_lightweight.c @@ -55,6 +55,11 @@ /* Reconnect parameters. */ #include "transport_reconnect.h" +/* Check that the broker endpoint is defined. */ +#ifndef BROKER_ENDPOINT + #error "Please define an MQTT broker endpoint, BROKER_ENDPOINT, in demo_config.h." +#endif + /* Check that client identifier is defined. */ #ifndef CLIENT_IDENTIFIER #error "Please define a unique CLIENT_IDENTIFIER." diff --git a/demos/mqtt/mqtt_demo_plaintext/mqtt_demo_plaintext.c b/demos/mqtt/mqtt_demo_plaintext/mqtt_demo_plaintext.c index 04864c1e6c..d238e0d580 100644 --- a/demos/mqtt/mqtt_demo_plaintext/mqtt_demo_plaintext.c +++ b/demos/mqtt/mqtt_demo_plaintext/mqtt_demo_plaintext.c @@ -58,8 +58,11 @@ * These configuration settings are required to run the plaintext demo. * Throw compilation error if the below configs are not defined. */ +#ifndef BROKER_ENDPOINT + #error "Please define an MQTT broker endpoint, BROKER_ENDPOINT, in demo_config.h." +#endif #ifndef CLIENT_IDENTIFIER - #error "Please define a unique CLIENT_IDENTIFIER." + #error "Please define a unique CLIENT_IDENTIFIER in demo_config.h." #endif /**