Skip to content

Commit

Permalink
Fixes for using the -f [file] option with examples. Allow build-tim…
Browse files Browse the repository at this point in the history
…e override of `MAX_BUFFER_SIZE` in examples.
  • Loading branch information
dgarske committed Nov 22, 2023
1 parent 86c424f commit 5518e4a
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions examples/aws/awsiot.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ static int mTestDone = 0;
#define APP_HARDWARE "wolf_aws_iot_demo"
#define APP_FIRMWARE_VERSION LIBWOLFMQTT_VERSION_STRING

#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 512 /* Maximum size for network read/write callbacks */
#endif
#define AWSIOT_HOST "a2dujmi05ideo2-ats.iot.us-west-2.amazonaws.com"
#define AWSIOT_DEVICE_ID "demoDevice"
#define AWSIOT_QOS MQTT_QOS_1
Expand Down
2 changes: 2 additions & 0 deletions examples/azure/azureiothub.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ static int mTestDone = 0;
* https://azure.microsoft.com/en-us/documentation/articles/iot-hub-sas-tokens/#using-sas-tokens-as-a-device
* https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support
*/
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024 /* Maximum size for network read/write callbacks */
#endif
#define AZURE_API_VERSION "?api-version=2018-06-30"
#define AZURE_HOST "wolfMQTT.azure-devices.net"
#define AZURE_DEVICE_ID "demoDevice"
Expand Down
2 changes: 2 additions & 0 deletions examples/firmware/fwclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
#include "examples/mqttnet.h"

/* Configuration */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE FIRMWARE_MAX_PACKET
#endif

/* Locals */
static int mStopRead = 0;
Expand Down
2 changes: 2 additions & 0 deletions examples/firmware/fwpush.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
#include "examples/mqttnet.h"

/* Configuration */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE FIRMWARE_MAX_PACKET
#endif

/* Locals */
static int mStopRead = 0;
Expand Down
4 changes: 4 additions & 0 deletions examples/mqttclient/mqttclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ static int mStopRead = 0;

/* Maximum size for network read/write callbacks. There is also a v5 define that
describes the max MQTT control packet size, DEFAULT_MAX_PKT_SZ. */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024
#endif

#ifdef WOLFMQTT_PROPERTY_CB
#define MAX_CLIENT_ID_LEN 64
Expand Down Expand Up @@ -504,6 +506,8 @@ int mqttclient_test(MQTTCtx *mqttCtx)

if ((mqttCtx->pub_file) && (mqttCtx->publish.buffer)) {
WOLFMQTT_FREE(mqttCtx->publish.buffer);
mqttCtx->publish.buffer = NULL;
mqttCtx->pub_file = NULL; /* don't try and send file again */
}

PRINTF("MQTT Publish: Topic %s, %s (%d)",
Expand Down
2 changes: 2 additions & 0 deletions examples/multithread/multithread.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@

/* Maximum size for network read/write callbacks. There is also a v5 define that
describes the max MQTT control packet size, DEFAULT_MAX_PKT_SZ. */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024
#endif

/* Total size of test message to build */
#define TEST_MESSAGE_SIZE 1048 /* span more than one max packet */
Expand Down
4 changes: 4 additions & 0 deletions examples/nbclient/nbclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ static int mTestDone = 0;
/* Configuration */

/* Maximum size for network read/write callbacks. */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024
#endif

#ifdef WOLFMQTT_PROPERTY_CB
#define MAX_CLIENT_ID_LEN 64
Expand Down Expand Up @@ -444,6 +446,8 @@ int mqttclient_test(MQTTCtx *mqttCtx)

if ((mqttCtx->pub_file) && (mqttCtx->publish.buffer)) {
WOLFMQTT_FREE(mqttCtx->publish.buffer);
mqttCtx->publish.buffer = NULL;
mqttCtx->pub_file = NULL; /* don't try and send file again */
}

PRINTF("MQTT Publish: Topic %s, %s (%d)",
Expand Down
6 changes: 5 additions & 1 deletion examples/pub-sub/mqtt-pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
/* Configuration */

/* Maximum size for network read/write callbacks. There is also a v5 define that
describes the max MQTT control packet size, DEFAULT_MAX_PKT_SZ. */
* describes the max MQTT control packet size, DEFAULT_MAX_PKT_SZ. */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024
#endif

#ifdef WOLFMQTT_PROPERTY_CB
#define MAX_CLIENT_ID_LEN 64
Expand Down Expand Up @@ -381,6 +383,8 @@ int pub_client(MQTTCtx *mqttCtx)

if ((mqttCtx->pub_file) && (mqttCtx->publish.buffer)) {
WOLFMQTT_FREE(mqttCtx->publish.buffer);
mqttCtx->publish.buffer = NULL;
mqttCtx->pub_file = NULL; /* don't try and send file again */
}
if (mqttCtx->debug_on) {
PRINTF("MQTT Publish: Topic %s, %s (%d)",
Expand Down
4 changes: 3 additions & 1 deletion examples/pub-sub/mqtt-sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ static int mStopRead = 0;
/* Configuration */

/* Maximum size for network read/write callbacks. There is also a v5 define that
describes the max MQTT control packet size, DEFAULT_MAX_PKT_SZ. */
* describes the max MQTT control packet size, DEFAULT_MAX_PKT_SZ. */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024
#endif

#ifdef WOLFMQTT_PROPERTY_CB
#define MAX_CLIENT_ID_LEN 64
Expand Down
12 changes: 7 additions & 5 deletions examples/sn-client/sn-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ static int mStopRead = 0;

/* Configuration */
/* Maximum size for network read/write callbacks. */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024
#endif
#define TEST_MESSAGE "test"
#define SHORT_TOPIC_NAME "s1"

Expand Down Expand Up @@ -215,11 +217,11 @@ int sn_test(MQTTCtx *mqttCtx)
/* Send Connect and wait for Connect Ack */
rc = SN_Client_Connect(&mqttCtx->client, connect);

if (rc != MQTT_CODE_SUCCESS) {
PRINTF("MQTT-SN Connect: %s (%d)",
MqttClient_ReturnCodeToString(rc), rc);
goto disconn;
}
if (rc != MQTT_CODE_SUCCESS) {
PRINTF("MQTT-SN Connect: %s (%d)",
MqttClient_ReturnCodeToString(rc), rc);
goto disconn;
}

/* Validate Connect Ack info */
PRINTF("....MQTT-SN Connect Ack: Return Code %u",
Expand Down
2 changes: 2 additions & 0 deletions examples/sn-client/sn-client_qos-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ static int mStopRead = 0;

/* Configuration */
/* Maximum size for network read/write callbacks. */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024
#endif
#define TEST_MESSAGE "QoS-1 test message"
char SHORT_TOPIC_NAME[] = {1};

Expand Down
2 changes: 2 additions & 0 deletions examples/sn-client/sn-multithread.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
/* Configuration */

/* Maximum size for network read/write callbacks. */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024
#endif
#define TEST_MESSAGE "test00"
/* Number of publish tasks. Each will send a unique message to the broker. */
#define NUM_PUB_TASKS 10
Expand Down
2 changes: 2 additions & 0 deletions examples/wiot/wiot.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ static int mStopRead = 0;
static int mTestDone = 0;

/* Configuration */
#ifndef MAX_BUFFER_SIZE
#define MAX_BUFFER_SIZE 1024 /* Maximum size for network read/write callbacks */
#endif

/* Undefine if using an IBM WIOT Platform account that you created. */
#define WIOT_USE_QUICKSTART
Expand Down

0 comments on commit 5518e4a

Please sign in to comment.