From ef2b581c10b7f14af71a40810747734ff837f698 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Sun, 27 Nov 2022 01:22:06 +0100 Subject: [PATCH] paho: use GNRC instead of lwip --- examples/paho-mqtt/Makefile | 20 ++++---------------- examples/paho-mqtt/Makefile.ci | 2 ++ examples/paho-mqtt/Makefile.gnrc | 16 ++++++++++++++++ examples/paho-mqtt/Makefile.lwip | 25 +++++++++++++++++++++++++ examples/paho-mqtt/main.c | 6 ++++++ pkg/paho-mqtt/contrib/riot_iface.c | 4 +--- 6 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 examples/paho-mqtt/Makefile.gnrc create mode 100644 examples/paho-mqtt/Makefile.lwip diff --git a/examples/paho-mqtt/Makefile b/examples/paho-mqtt/Makefile index e6e6c2e083..f5928bd05c 100644 --- a/examples/paho-mqtt/Makefile +++ b/examples/paho-mqtt/Makefile @@ -34,24 +34,12 @@ USEMODULE += netdev_default USEPKG += paho-mqtt # paho-mqtt depends on TCP support, choose which stacks you want +GNRC_IPV6 ?= 1 LWIP_IPV4 ?= 0 -LWIP_IPV6 ?= 1 +LWIP_IPV6 ?= 0 -ifneq (0,$(LWIP_IPV4)) - USEMODULE += ipv4_addr - USEMODULE += lwip_arp - USEMODULE += lwip_ipv4 - USEMODULE += lwip_dhcp_auto - CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 -endif - -ifneq (0,$(LWIP_IPV6)) - USEMODULE += ipv6_addr - USEMODULE += lwip_ipv6_autoconfig -endif - -USEMODULE += lwip_netdev -USEMODULE += lwip +include Makefile.lwip +include Makefile.gnrc USEMODULE += sock_async_event USEMODULE += sock_ip diff --git a/examples/paho-mqtt/Makefile.ci b/examples/paho-mqtt/Makefile.ci index 101fab6a7f..8e0855dffc 100644 --- a/examples/paho-mqtt/Makefile.ci +++ b/examples/paho-mqtt/Makefile.ci @@ -1,7 +1,9 @@ BOARD_INSUFFICIENT_MEMORY := \ airfy-beacon \ blackpill \ + blackpill-128kib \ bluepill \ + bluepill-128kib \ bluepill-stm32f030c8 \ calliope-mini \ hifive1 \ diff --git a/examples/paho-mqtt/Makefile.gnrc b/examples/paho-mqtt/Makefile.gnrc new file mode 100644 index 0000000000..802d9f1148 --- /dev/null +++ b/examples/paho-mqtt/Makefile.gnrc @@ -0,0 +1,16 @@ +ifneq (0,$(GNRC_IPV6)) + ifneq (0,$(USE_LWIP)) + $(error No valid choice: Select either LWIP or GNRC) + endif + USEMODULE += auto_init_gnrc_netif + # Activate ICMPv6 error messages + USEMODULE += gnrc_icmpv6_error + # Specify the mandatory networking modules for IPv6 + USEMODULE += gnrc_ipv6_default + # Additional networking modules that can be dropped if not needed + USEMODULE += gnrc_icmpv6_echo +else + ifeq (0,$(USE_LWIP)) + $(error No network stack selected. Please choose either GNRC or LWIP) + endif +endif diff --git a/examples/paho-mqtt/Makefile.lwip b/examples/paho-mqtt/Makefile.lwip new file mode 100644 index 0000000000..fe16608954 --- /dev/null +++ b/examples/paho-mqtt/Makefile.lwip @@ -0,0 +1,25 @@ +USE_LWIP := 0 +ifneq (0,$(LWIP_IPV4)) + USE_LWIP := 1 +endif +ifneq (0,$(LWIP_IPV6)) + USE_LWIP := 1 +endif + +ifneq (0,$(LWIP_IPV4)) + USEMODULE += ipv4_addr + USEMODULE += lwip_arp + USEMODULE += lwip_ipv4 + USEMODULE += lwip_dhcp_auto + CFLAGS += -DETHARP_SUPPORT_STATIC_ENTRIES=1 +endif + +ifneq (0,$(LWIP_IPV6)) + USEMODULE += ipv6_addr + USEMODULE += lwip_ipv6_autoconfig +endif + +ifneq (0,$(USE_LWIP)) + USEMODULE += lwip_netdev + USEMODULE += lwip +endif diff --git a/examples/paho-mqtt/main.c b/examples/paho-mqtt/main.c index 163e90d105..f044a74430 100644 --- a/examples/paho-mqtt/main.c +++ b/examples/paho-mqtt/main.c @@ -29,6 +29,9 @@ #include "paho_mqtt.h" #include "MQTTClient.h" +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + #define BUF_SIZE 1024 #define MQTT_VERSION_v311 4 /* MQTT v3.1.1 version is 4 */ #define COMMAND_TIMEOUT_MS 4000 @@ -293,6 +296,9 @@ static unsigned char readbuf[BUF_SIZE]; int main(void) { + if (IS_USED(MODULE_GNRC_ICMPV6_ECHO)) { + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + } #ifdef MODULE_LWIP /* let LWIP initialize */ ztimer_sleep(ZTIMER_MSEC, 1 * MS_PER_SEC); diff --git a/pkg/paho-mqtt/contrib/riot_iface.c b/pkg/paho-mqtt/contrib/riot_iface.c index 964b146c01..b9af162c4f 100644 --- a/pkg/paho-mqtt/contrib/riot_iface.c +++ b/pkg/paho-mqtt/contrib/riot_iface.c @@ -39,11 +39,9 @@ #define TSRB_MAX_SIZE (1024) #endif -#ifdef MODULE_LWIP static uint8_t buffer[TSRB_MAX_SIZE]; static uint8_t _temp_buf[TSRB_MAX_SIZE]; static tsrb_t tsrb_lwip_tcp; -#endif #ifndef PAHO_MQTT_YIELD_MS #define PAHO_MQTT_YIELD_MS (10) @@ -75,7 +73,7 @@ static int mqtt_read(struct Network *n, unsigned char *buf, int len, uint32_t send_time = ztimer_now(ZTIMER_MSEC) + timeout_ms; do { rc = sock_tcp_read(&n->sock, _buf, _len, _timeout); - if (rc == -EAGAIN) { + if ((rc == -EAGAIN) || (rc == -ETIMEDOUT)) { rc = 0; }