mirror of https://github.com/wolfSSL/wolfMQTT.git
Code review fixes
- Use macros in user settings to configure connection settings - Fix `main()` signature - Add note with link in main README - Add debugging info to READMEpull/333/head
parent
178c051db5
commit
50530d90e0
|
|
@ -92,6 +92,10 @@ cd ../wolfmqtt
|
|||
make
|
||||
```
|
||||
|
||||
### Zephyr RTOS
|
||||
|
||||
Support for Zephyr is available in the [zephyr](zephyr) directory. For instructions on how to build for Zephyr, see the [README.md](zephyr/README.md).
|
||||
|
||||
## Architecture
|
||||
|
||||
The library has three components.
|
||||
|
|
|
|||
|
|
@ -709,21 +709,6 @@ static int run_client(int argc, char** argv)
|
|||
mqttCtx.app_name = "mqttclient";
|
||||
mqttCtx.message = DEFAULT_MESSAGE;
|
||||
|
||||
#ifdef WOLFMQTT_ZEPHYR
|
||||
#ifdef CONFIG_NET_CONFIG_PEER_IPV4_ADDR
|
||||
mqttCtx.host = CONFIG_NET_CONFIG_PEER_IPV4_ADDR;
|
||||
#endif
|
||||
#ifdef ENABLE_MQTT_TLS
|
||||
mqttCtx.use_tls = 1;
|
||||
#endif
|
||||
#ifdef CONFIG_NET_CONFIG_PEER_PORT
|
||||
mqttCtx.port = CONFIG_NET_CONFIG_PEER_PORT;
|
||||
#endif
|
||||
#ifdef WOLFMQTT_TOPIC
|
||||
mqttCtx.topic_name = WOLFMQTT_TOPIC;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* parse arguments */
|
||||
rc = mqtt_parse_args(&mqttCtx, argc, argv);
|
||||
if (rc != 0) {
|
||||
|
|
@ -754,9 +739,12 @@ static int run_client(int argc, char** argv)
|
|||
}
|
||||
|
||||
#ifdef WOLFMQTT_ZEPHYR
|
||||
void main(void)
|
||||
/* In zephyr commit 0b90fd5adf1f01625412efadba4331b5041fb828 the main signature
|
||||
* was changed from void main(void) to int main(void). Zephyr doesn't provide a
|
||||
* way to check the version of Zephyr at compile time so support the latest. */
|
||||
int main(void)
|
||||
{
|
||||
(void)run_client(0, NULL);
|
||||
return run_client(0, NULL);
|
||||
}
|
||||
#else
|
||||
int main(int argc, char** argv)
|
||||
|
|
|
|||
|
|
@ -264,6 +264,9 @@ void mqtt_init_ctx(MQTTCtx* mqttCtx)
|
|||
mqttCtx->topic_alias = 1;
|
||||
mqttCtx->topic_alias_max = 1;
|
||||
#endif
|
||||
#ifdef WOLFMQTT_DEFAULT_TLS
|
||||
mqttCtx->use_tls = WOLFMQTT_DEFAULT_TLS;
|
||||
#endif
|
||||
}
|
||||
|
||||
int mqtt_parse_args(MQTTCtx* mqttCtx, int argc, char** argv)
|
||||
|
|
|
|||
|
|
@ -77,8 +77,12 @@
|
|||
#define DEFAULT_MQTT_QOS MQTT_QOS_0
|
||||
#define DEFAULT_KEEP_ALIVE_SEC 60
|
||||
#define DEFAULT_CLIENT_ID "WolfMQTTClient"
|
||||
#define WOLFMQTT_TOPIC_NAME "wolfMQTT/example/"
|
||||
#define DEFAULT_TOPIC_NAME WOLFMQTT_TOPIC_NAME"testTopic"
|
||||
#ifndef WOLFMQTT_TOPIC_NAME
|
||||
#define WOLFMQTT_TOPIC_NAME "wolfMQTT/example/"
|
||||
#define DEFAULT_TOPIC_NAME WOLFMQTT_TOPIC_NAME"testTopic"
|
||||
#else
|
||||
#define DEFAULT_TOPIC_NAME WOLFMQTT_TOPIC_NAME
|
||||
#endif
|
||||
#define DEFAULT_AUTH_METHOD "EXTERNAL"
|
||||
#define PRINT_BUFFER_SIZE 80
|
||||
#define DEFAULT_MESSAGE "test"
|
||||
|
|
|
|||
|
|
@ -33,10 +33,7 @@
|
|||
|
||||
/* Windows uses the vs_settings.h file included vis mqtt_types.h */
|
||||
#if !defined(WOLFMQTT_USER_SETTINGS) && \
|
||||
!defined(_WIN32) && !defined(USE_WINDOWS_API) && \
|
||||
!defined(CONFIG_WOLFMQTT_SETTINGS_FILE) /* Zephyr config option */
|
||||
/* If options.h is missing use the "./configure" script. Otherwise, copy
|
||||
* the template "wolfmqtt/options.h.in" into "wolfmqtt/options.h" */
|
||||
!defined(_WIN32) && !defined(USE_WINDOWS_API)
|
||||
#include <wolfmqtt/options.h>
|
||||
#endif
|
||||
#include "wolfmqtt/mqtt_types.h"
|
||||
|
|
|
|||
|
|
@ -64,17 +64,6 @@
|
|||
#include "user_settings.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ZEPHYR_WOLFMQTT_MODULE
|
||||
#define WOLFMQTT_ZEPHYR
|
||||
#ifdef CONFIG_WOLFMQTT_TLS
|
||||
#undef ENABLE_MQTT_TLS
|
||||
#define ENABLE_MQTT_TLS
|
||||
#endif
|
||||
#ifdef CONFIG_WOLFMQTT_SETTINGS_FILE
|
||||
#include CONFIG_WOLFMQTT_SETTINGS_FILE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_MQTT_TLS
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && \
|
||||
(!defined(USE_WINDOWS_API) || defined(BUILDING_CMAKE))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
if(CONFIG_WOLFMQTT)
|
||||
zephyr_include_directories(${ZEPHYR_CURRENT_MODULE_DIR})
|
||||
zephyr_include_directories(${ZEPHYR_CURRENT_MODULE_DIR}/zephyr)
|
||||
zephyr_library_include_directories(${ZEPHYR_CURRENT_MODULE_DIR})
|
||||
FILE(GLOB wolfmqtt_sources ${ZEPHYR_CURRENT_MODULE_DIR}/src/*.c)
|
||||
target_sources(app PRIVATE ${wolfmqtt_sources})
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ menuconfig WOLFMQTT
|
|||
if WOLFMQTT
|
||||
config WOLFMQTT_SETTINGS_FILE
|
||||
string "wolfMQTT settings file"
|
||||
default "wolfMQTT_user_settings.h"
|
||||
help
|
||||
Use a specific wolfMQTT settings file.
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ Follow the [instructions](https://docs.zephyrproject.org/latest/develop/getting_
|
|||
### Modify your project's west manifest
|
||||
|
||||
Add wolfMQTT as a project to your west.yml:
|
||||
|
||||
```
|
||||
manifest:
|
||||
remotes:
|
||||
|
|
@ -50,12 +51,17 @@ CMakeFiles.txt in the build system.
|
|||
|
||||
## Build and Run Samples
|
||||
|
||||
Follow the [instructions](https://docs.zephyrproject.org/latest/connectivity/networking/qemu_setup.html) to setup the infratructure to enable networking in QEMU. Run the following commands in parallel in this order in the `zephyrproject` directory to allow comunication between the QEMU instance and the host.
|
||||
Follow the [instructions](https://docs.zephyrproject.org/latest/connectivity/networking/qemu_setup.html) to setup the infratructure to enable networking in QEMU. Run the following commands in parallel in this order in the `net-tools` directory to allow comunication between the QEMU instance and the host. Make sure to disable any software that modifies the local network like VPN's.
|
||||
|
||||
```bash
|
||||
./loop-socat.sh
|
||||
sudo ./loop-slip-tap.sh
|
||||
mosquitto -c modules/lib/wolfmqtt/scripts/broker_test/mosquitto.conf
|
||||
```
|
||||
|
||||
Run the following commands in parallel in this order in the `zephyrproject` directory to setup a MQTT broker and subscriber.
|
||||
|
||||
```bash
|
||||
cd modules/lib/wolfmqtt && mosquitto -c scripts/broker_test/mosquitto.conf
|
||||
mosquitto_sub -t sensors
|
||||
```
|
||||
|
||||
|
|
@ -78,3 +84,18 @@ cd [zephyrproject]
|
|||
west build -p auto -b qemu_x86 modules/lib/wolfmqtt/zephyr/samples/client_tls
|
||||
west build -t run
|
||||
```
|
||||
|
||||
### Debugging using QEMU
|
||||
|
||||
To attach a debugger to the QEMU instance run:
|
||||
|
||||
```bash
|
||||
west build -t debugserver_qemu
|
||||
```
|
||||
|
||||
And attach gdb with:
|
||||
|
||||
```bash
|
||||
$ gdb path/to/zephyr.elf
|
||||
(gdb) target remote localhost:1234
|
||||
```
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ project(mqtt_client)
|
|||
|
||||
FILE(GLOB app_sources ../../../examples/mqttclient/*.c ../../../examples/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
zephyr_library_include_directories(app PRIVATE ${ZEPHYR_WOLFMQTT_MODULE_DIR}/zephyr)
|
||||
target_include_directories(app PUBLIC ${ZEPHYR_WOLFMQTT_MODULE_DIR}/zephyr/client)
|
||||
add_definitions(-DWOLFMQTT_USER_SETTINGS)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=16384
|
|||
|
||||
# Enable the MQTT Lib
|
||||
CONFIG_WOLFMQTT=y
|
||||
CONFIG_WOLFMQTT_SETTINGS_FILE="samples/client/user_settings.h"
|
||||
|
||||
# Networking
|
||||
CONFIG_NETWORKING=y
|
||||
|
|
@ -14,7 +15,6 @@ CONFIG_NET_TCP=y
|
|||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
|
||||
|
||||
# For IPv6
|
||||
#CONFIG_NET_IPV6=y
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef WOLFMQTT_OPTIONS_H
|
||||
#define WOLFMQTT_OPTIONS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#undef NO_FILESYSTEM
|
||||
#define NO_FILESYSTEM
|
||||
|
||||
#define WOLFMQTT_TOPIC_NAME "sensors"
|
||||
#define DEFAULT_MQTT_HOST "192.0.2.2"
|
||||
|
||||
#if defined(CONFIG_WOLFSSL_DEBUG)
|
||||
#undef DEBUG_WOLFSSL
|
||||
#define DEBUG_WOLFSSL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFMQTT_OPTIONS_H */
|
||||
|
||||
|
|
@ -5,6 +5,7 @@ project(mqtt_client_tls)
|
|||
|
||||
FILE(GLOB app_sources ../../../examples/mqttclient/*.c ../../../examples/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
zephyr_library_include_directories(app PRIVATE ${ZEPHYR_WOLFMQTT_MODULE_DIR}/zephyr)
|
||||
target_include_directories(app PRIVATE ${ZEPHYR_WOLFMQTT_MODULE_DIR}/zephyr/client_tls)
|
||||
add_definitions(-DWOLFSSL_USER_SETTINGS)
|
||||
add_definitions(-DWOLFMQTT_USER_SETTINGS)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ CONFIG_MAIN_STACK_SIZE=32768
|
|||
# Enable the MQTT Lib
|
||||
CONFIG_WOLFMQTT=y
|
||||
CONFIG_WOLFMQTT_TLS=y
|
||||
CONFIG_WOLFMQTT_SETTINGS_FILE="samples/client_tls/user_settings.h"
|
||||
|
||||
# Networking
|
||||
CONFIG_NETWORKING=y
|
||||
|
|
@ -14,7 +15,6 @@ CONFIG_NET_TCP=y
|
|||
CONFIG_NET_IPV4=y
|
||||
CONFIG_NET_CONFIG_SETTINGS=y
|
||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
|
||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
|
||||
CONFIG_NET_PKT_TX_COUNT=10
|
||||
|
||||
# For IPv6
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@ extern "C" {
|
|||
#undef NO_FILESYSTEM
|
||||
#define NO_FILESYSTEM
|
||||
|
||||
#define WOLFMQTT_TOPIC "sensors"
|
||||
#define WOLFMQTT_TOPIC_NAME "sensors"
|
||||
#define WOLFMQTT_DEFAULT_TLS 1
|
||||
#define DEFAULT_MQTT_HOST "192.0.2.2"
|
||||
#define ENABLE_MQTT_TLS
|
||||
|
||||
const static unsigned char root_ca[] = {
|
||||
0x30, 0x82, 0x04, 0xe9, 0x30, 0x82, 0x03, 0xd1, 0xa0, 0x03, 0x02, 0x01,
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef USER_SETTINGS_H
|
||||
#define USER_SETTINGS_H
|
||||
|
||||
#ifdef CONFIG_WOLFMQTT_SETTINGS_FILE
|
||||
#include CONFIG_WOLFMQTT_SETTINGS_FILE
|
||||
#endif
|
||||
|
||||
#define WOLFMQTT_ZEPHYR
|
||||
|
||||
#ifdef CONFIG_WOLFSSL_SETTINGS_FILE
|
||||
#include CONFIG_WOLFSSL_SETTINGS_FILE
|
||||
#endif
|
||||
|
||||
#endif /* USER_SETTINGS_H */
|
||||
Loading…
Reference in New Issue