How to Send the thread network name through CoAP Response

Hi i was wondering how could i send, with a coap response, one's device network name and a, for exaple a temperature value, like this:

<device's network name>: <temperature value>

I tried this, but failed:

const char *myTemperatureJson = "23.32";
const char *buf[] = {CONFIG_OPENTHREAD_NETWORK_NAME,'   ', myTemperatureJson};
.
.
.
error = otMessageAppend(p_response, buf, strlen(buf));
Is there any other way to do this?
thanks
Parents
  • Hello,

    I tried this, but failed:

    So what happened? Does it compile? Does it run? Are you able to send the message, or does it "crash"? Do you receive any messages? Is it corrupted? Is it equal to your *buf[] after your second line?

    BR,
    Edvin

  • Sorry

    when i build it prints this:

    Building coap_rec_myserver
    west build --build-dir c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\build c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver

    [0/16] Performing build step for '802154_rpmsg_subimage'
    ninja: no work to do.
    [2/14] Building C object CMakeFiles/app.dir/src/main.c.obj
    FAILED: CMakeFiles/app.dir/src/main.c.obj
    C:\ncs\toolchains\v2.1.1\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DMBEDTLS_CONFIG_FILE=\"nrf-config.h\" -DMBEDTLS_USER_CONFIG_FILE=\"nrf-config-user.h\" -DNRF5340_XXAA_APPLICATION -DNRF_802154_ACK_TIMEOUT_ENABLED=1 -DNRF_802154_ECB_PRIORITY=-1 -DNRF_802154_ENCRYPTION_ENABLED=1 -DNRF_802154_IE_WRITER_ENABLED=1 -DNRF_802154_INTERNAL_RADIO_IRQ_HANDLING=0 -DNRF_802154_PENDING_EXTENDED_ADDRESSES="" -DNRF_802154_PENDING_SHORT_ADDRESSES="" -DNRF_802154_RX_BUFFERS=16 -DNRF_802154_SECURITY_WRITER_ENABLED=1 -DNRF_802154_SWI_PRIORITY=1 -DNRF_802154_TX_STARTED_NOTIFY_ENABLED=1 -DNRF_802154_USE_RAW_API=1 -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=2 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.1.1/zephyr/include/zephyr -IC:/ncs/v2.1.1/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.1.1/zephyr/soc/arm/nordic_nrf/nrf53 -IC:/ncs/v2.1.1/zephyr/lib/libc/newlib/include -IC:/ncs/v2.1.1/zephyr/lib/util/fnmatch/. -IC:/ncs/v2.1.1/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.1.1/zephyr/subsys/net/lib/sockets/. -IC:/ncs/v2.1.1/zephyr/subsys/settings/include -IC:/ncs/v2.1.1/nrf/include -IC:/ncs/v2.1.1/zephyr/modules/openthread/platform/. -IC:/ncs/v2.1.1/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.1.1/modules/hal/nordic/nrfx -IC:/ncs/v2.1.1/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.1.1/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.1.1/zephyr/modules/hal_nordic/nrfx/. -Imodules/libmetal/libmetal/lib/include -IC:/ncs/v2.1.1/modules/lib/open-amp/open-amp/lib/include -IC:/ncs/v2.1.1/nrfxlib/openthread/include -IC:/ncs/v2.1.1/nrfxlib/nrf_802154/serialization/include -IC:/ncs/v2.1.1/nrfxlib/nrf_802154/serialization/include/platform -IC:/ncs/v2.1.1/nrfxlib/nrf_802154/serialization/include/serialization -IC:/ncs/v2.1.1/nrfxlib/nrf_802154/serialization/include/host -Imodules/nrfxlib/nrfxlib/nrf_security/src/include/generated -IC:/ncs/v2.1.1/nrfxlib/nrf_security/include -IC:/ncs/v2.1.1/nrfxlib/nrf_security/include/mbedtls -IC:/ncs/v2.1.1/nrfxlib/nrf_security/include/psa -IC:/ncs/v2.1.1/mbedtls/include -IC:/ncs/v2.1.1/mbedtls/include/mbedtls -IC:/ncs/v2.1.1/mbedtls/include/psa -IC:/ncs/v2.1.1/mbedtls/library -IC:/ncs/v2.1.1/nrfxlib/nrf_security/../crypto/nrf_oberon/include -IC:/ncs/v2.1.1/nrfxlib/nrf_security/../crypto/nrf_oberon/include/mbedtls -IC:/ncs/v2.1.1/nrfxlib/nrf_security/../crypto/nrf_oberon/include/psa -IC:/ncs/v2.1.1/nrfxlib/crypto/nrf_oberon/include/mbedtls -IC:/ncs/v2.1.1/nrfxlib/crypto/nrf_oberon/include -isystem C:/ncs/v2.1.1/zephyr/subsys/cpp/include -isystem C:/ncs/v2.1.1/nrfxlib/crypto/nrf_cc312_platform/include -Os -imacros C:/progetti/nexter/VS/esempi/server-send__client-receive/coap_rec_myserver/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mfp16-format=ieee --sysroot=C:/ncs/toolchains/v2.1.1/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.1.1/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=C:/progetti/nexter/VS/esempi/server-send__client-receive/coap_rec_myserver=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.1.1/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.1.1=WEST_TOPDIR -ffunction-sections -fdata-sections -specs=nano.specs -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:53: warning: multi-character character constant [-Wmultichar]
    24 | const char *buf[] = {CONFIG_OPENTHREAD_NETWORK_NAME,' ', myTemperatureJson};
    | ^~~~~
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:53: warning: initialization of 'const char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:53: note: (near initialization for 'buf[1]')
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:60: error: initializer element is not constant
    24 | const char *buf[] = {CONFIG_OPENTHREAD_NETWORK_NAME,' ', myTemperatureJson};
    | ^~~~~~~~~~~~~~~~~
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:60: note: (near initialization for 'buf[2]')
    ../src/main.c: In function 'temperature_response_send':
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:93:50: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
    93 | error = otMessageAppend(p_response, buf, strlen(buf));
    | ^~~
    | |
    | const char **
    In file included from C:\ncs\v2.1.1\zephyr\include\zephyr\net\net_core.h:17,
    from C:\ncs\v2.1.1\zephyr\include\zephyr\net\net_if.h:25,
    from C:\ncs\v2.1.1\zephyr\include\zephyr\net\openthread.h:23,
    from c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:11:
    c:\ncs\toolchains\v2.1.1\opt\zephyr-sdk\arm-zephyr-eabi\arm-zephyr-eabi\sys-include\string.h:41:17: note: expected 'const char *' but argument is of type 'const char **'
    41 | size_t strlen (const char *);
    | ^~~~~~~~~~~~
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'c:\ncs\toolchains\v2.1.1\opt\bin\cmake.EXE' --build 'c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\build'

Reply
  • Sorry

    when i build it prints this:

    Building coap_rec_myserver
    west build --build-dir c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\build c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver

    [0/16] Performing build step for '802154_rpmsg_subimage'
    ninja: no work to do.
    [2/14] Building C object CMakeFiles/app.dir/src/main.c.obj
    FAILED: CMakeFiles/app.dir/src/main.c.obj
    C:\ncs\toolchains\v2.1.1\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DMBEDTLS_CONFIG_FILE=\"nrf-config.h\" -DMBEDTLS_USER_CONFIG_FILE=\"nrf-config-user.h\" -DNRF5340_XXAA_APPLICATION -DNRF_802154_ACK_TIMEOUT_ENABLED=1 -DNRF_802154_ECB_PRIORITY=-1 -DNRF_802154_ENCRYPTION_ENABLED=1 -DNRF_802154_IE_WRITER_ENABLED=1 -DNRF_802154_INTERNAL_RADIO_IRQ_HANDLING=0 -DNRF_802154_PENDING_EXTENDED_ADDRESSES="" -DNRF_802154_PENDING_SHORT_ADDRESSES="" -DNRF_802154_RX_BUFFERS=16 -DNRF_802154_SECURITY_WRITER_ENABLED=1 -DNRF_802154_SWI_PRIORITY=1 -DNRF_802154_TX_STARTED_NOTIFY_ENABLED=1 -DNRF_802154_USE_RAW_API=1 -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=2 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.1.1/zephyr/include/zephyr -IC:/ncs/v2.1.1/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.1.1/zephyr/soc/arm/nordic_nrf/nrf53 -IC:/ncs/v2.1.1/zephyr/lib/libc/newlib/include -IC:/ncs/v2.1.1/zephyr/lib/util/fnmatch/. -IC:/ncs/v2.1.1/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.1.1/zephyr/subsys/net/lib/sockets/. -IC:/ncs/v2.1.1/zephyr/subsys/settings/include -IC:/ncs/v2.1.1/nrf/include -IC:/ncs/v2.1.1/zephyr/modules/openthread/platform/. -IC:/ncs/v2.1.1/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.1.1/modules/hal/nordic/nrfx -IC:/ncs/v2.1.1/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.1.1/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.1.1/zephyr/modules/hal_nordic/nrfx/. -Imodules/libmetal/libmetal/lib/include -IC:/ncs/v2.1.1/modules/lib/open-amp/open-amp/lib/include -IC:/ncs/v2.1.1/nrfxlib/openthread/include -IC:/ncs/v2.1.1/nrfxlib/nrf_802154/serialization/include -IC:/ncs/v2.1.1/nrfxlib/nrf_802154/serialization/include/platform -IC:/ncs/v2.1.1/nrfxlib/nrf_802154/serialization/include/serialization -IC:/ncs/v2.1.1/nrfxlib/nrf_802154/serialization/include/host -Imodules/nrfxlib/nrfxlib/nrf_security/src/include/generated -IC:/ncs/v2.1.1/nrfxlib/nrf_security/include -IC:/ncs/v2.1.1/nrfxlib/nrf_security/include/mbedtls -IC:/ncs/v2.1.1/nrfxlib/nrf_security/include/psa -IC:/ncs/v2.1.1/mbedtls/include -IC:/ncs/v2.1.1/mbedtls/include/mbedtls -IC:/ncs/v2.1.1/mbedtls/include/psa -IC:/ncs/v2.1.1/mbedtls/library -IC:/ncs/v2.1.1/nrfxlib/nrf_security/../crypto/nrf_oberon/include -IC:/ncs/v2.1.1/nrfxlib/nrf_security/../crypto/nrf_oberon/include/mbedtls -IC:/ncs/v2.1.1/nrfxlib/nrf_security/../crypto/nrf_oberon/include/psa -IC:/ncs/v2.1.1/nrfxlib/crypto/nrf_oberon/include/mbedtls -IC:/ncs/v2.1.1/nrfxlib/crypto/nrf_oberon/include -isystem C:/ncs/v2.1.1/zephyr/subsys/cpp/include -isystem C:/ncs/v2.1.1/nrfxlib/crypto/nrf_cc312_platform/include -Os -imacros C:/progetti/nexter/VS/esempi/server-send__client-receive/coap_rec_myserver/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mfp16-format=ieee --sysroot=C:/ncs/toolchains/v2.1.1/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.1.1/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=C:/progetti/nexter/VS/esempi/server-send__client-receive/coap_rec_myserver=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.1.1/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.1.1=WEST_TOPDIR -ffunction-sections -fdata-sections -specs=nano.specs -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:53: warning: multi-character character constant [-Wmultichar]
    24 | const char *buf[] = {CONFIG_OPENTHREAD_NETWORK_NAME,' ', myTemperatureJson};
    | ^~~~~
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:53: warning: initialization of 'const char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:53: note: (near initialization for 'buf[1]')
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:60: error: initializer element is not constant
    24 | const char *buf[] = {CONFIG_OPENTHREAD_NETWORK_NAME,' ', myTemperatureJson};
    | ^~~~~~~~~~~~~~~~~
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:24:60: note: (near initialization for 'buf[2]')
    ../src/main.c: In function 'temperature_response_send':
    c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:93:50: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
    93 | error = otMessageAppend(p_response, buf, strlen(buf));
    | ^~~
    | |
    | const char **
    In file included from C:\ncs\v2.1.1\zephyr\include\zephyr\net\net_core.h:17,
    from C:\ncs\v2.1.1\zephyr\include\zephyr\net\net_if.h:25,
    from C:\ncs\v2.1.1\zephyr\include\zephyr\net\openthread.h:23,
    from c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\src\main.c:11:
    c:\ncs\toolchains\v2.1.1\opt\zephyr-sdk\arm-zephyr-eabi\arm-zephyr-eabi\sys-include\string.h:41:17: note: expected 'const char *' but argument is of type 'const char **'
    41 | size_t strlen (const char *);
    | ^~~~~~~~~~~~
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'c:\ncs\toolchains\v2.1.1\opt\bin\cmake.EXE' --build 'c:\progetti\nexter\VS\esempi\server-send__client-receive\coap_rec_myserver\build'

Children
No Data
Related