diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dded2729..8050c039 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -160,7 +160,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - OS: ["contiki", "lwip", "riot"] + OS: ["contiki", "lwip", "riot", "zephyr"] steps: - uses: actions/checkout@v4 - name: setup diff --git a/examples/zephyr/Makefile b/examples/zephyr/Makefile index 6ab8e6ce..82c688b7 100644 --- a/examples/zephyr/Makefile +++ b/examples/zephyr/Makefile @@ -1,8 +1,27 @@ -ZEPHYR_PROJECT?=~/zephyrproject +ZEPHYR_PROJECT?=zephyrproject -all: coap-client +all: $(ZEPHYR_PROJECT) coap-client -coap-client: client-src/src/main.c client-src/* +${ZEPHYR_PROJECT}: + python3 -m venv ${ZEPHYR_PROJECT}/.venv ;\ + ls -l ${ZEPHYR_PROJECT}/.venv/bin/activate ;\ + . ${ZEPHYR_PROJECT}/.venv/bin/activate ;\ + pip install west ;\ + west init ${ZEPHYR_PROJECT} ;\ + cd ${ZEPHYR_PROJECT} ;\ + west update -n ;\ + west zephyr-export ;\ + west packages pip --install ;\ + cd zephyr ;\ + if [ "${GITHUB_WORKSPACE}"a = "a" ] ; then \ + west sdk install --install-base=$(ZEPHYR_PROJECT)/../ ;\ + else \ + west sdk install --install-base=$(ZEPHYR_PROJECT)/../ -t x86_64-zephyr-elf ;\ + fi ;\ + cd ../../ ;\ + deactivate + +coap-client: client-src/src/main.c client-src/* ../../src/*.c ../../include/*/* @LIBCOAP_DIR=`pwd`/../.. ;\ (if [ -f $(ZEPHYR_PROJECT)/.venv/bin/activate ]; then \ . $(ZEPHYR_PROJECT)/.venv/bin/activate ;\ diff --git a/examples/zephyr/README b/examples/zephyr/README index e50022da..e88bacaa 100644 --- a/examples/zephyr/README +++ b/examples/zephyr/README @@ -1,20 +1,28 @@ Example of libcoap running in Zephyr ==================================== +If the Zephyr project environment is already installed outside of the libcoap +environment, then ZEPHYR_PROJECT need to be set to where it is already installed +(i.e export ZEPHYR_PROJECT=~/zephyrproject ). -The Zephyr project environment needs to be pre-installed. By default, the -libcoap Makefile assumes that this is located at ~/zephyrproject . +If ZEPHYR_PROJECT is not set, then this defaults in this Makefile to the directory +zephyrproject under the examples/zephyr directory. To build the coap-client example, do $ make -The executable gets built in ~/zephyrproject/zephyr/build/zephyr/zephyr.exe -which is then copied to coap-client . +The executable gets built in ${ZEPHYR_PROJECT}/zephyr/build/zephyr/zephyr.exe +which is then copied to coap-client in the examples/zephyr directory. + +./coap-client does a 'GET coaps://libcoap-net' using PSK with logging enabled. For using the native_sim board using Linux, you may need to do something like -the following (ens32 is the external interface name) +the following (ens32 is the external interface name, your environment may +be different) + $ sudo ${ZEPHYR_PROJECT}/tools/net-tools/net-setup.sh start $ sudo iptables -t nat -A POSTROUTING -o ens32 -j MASQUERADE $ sudo sysctl -w net.ipv4.conf.all.forwarding=1 -so that ./coap-client is able to get out onto the internet. +so that ./coap-client is able to route traffic out onto the internet and get +responses. diff --git a/src/coap_io.c b/src/coap_io.c index 8bc1caa1..439b8301 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -258,8 +258,13 @@ coap_socket_connect_udp(coap_socket_t *sock, if (ioctl(sock->fd, FIONBIO, &on) == COAP_SOCKET_ERROR) #endif { - coap_log_warn("coap_socket_connect_udp: ioctl FIONBIO: %s\n", - coap_socket_strerror()); + /* Ignore Zephyr unexpected Success response */ + if (errno != 0) { + int keep_errno = errno; + + coap_log_warn("coap_socket_connect_udp: ioctl FIONBIO: %s (%d)\n", + coap_socket_strerror(), keep_errno); + } } switch (connect_addr.addr.sa.sa_family) {