Simple MQTT message not publishing

Hello there, I am having problems publishing a message to the server I set up on emqx. Here are the changes I made to the kconfig file (I have not changed the main.c code).

After making these changes, this it what appears on my AT terminal

Which leads me to believe it is connecting to the server and subscribing, but then I get this when I press button 1 to publish a message.

and I get this in the mqttx application to view the traffic. ("oof" is not here)

I am trying to figure out why the message is not publishing on here, any help would be appreciated.

Parents
  • Hello, 

    Are you able to publish this topic from a computer? You device does seem to receive the topic as well. Would it be possible for you to test with e.g. testopic/pub and testopic/sub to verify functionality?

    Kind regards,
    Øyvind

  • I tried changing the kconfig file as seen below...

    but I am still not receiving any messages on the server, the resending of the message however, has stopped.

  • Looks like there is an issue with your broker settings. I've tested using test.mosquitt.org without issues:

    2022-11-25T07:36:06.270Z DEBUG modem << *** Booting Zephyr OS build v3.1.99-ncs1-1  ***
    2022-11-25T07:36:07.277Z DEBUG modem << [00:00:00.508,422] [0m<inf> mqtt_simple: The MQTT simple sample started[0m
    2022-11-25T07:36:07.294Z DEBUG modem << [00:00:00.508,453] [0m<inf> mqtt_simple: Disabling PSM and eDRX[0m
    2022-11-25T07:36:07.295Z DEBUG modem << [00:00:00.509,216] [0m<inf> mqtt_simple: LTE Link Connecting...[0m
    2022-11-25T07:36:09.183Z DEBUG modem << [00:00:02.415,588] [0m<inf> mqtt_simple: LTE Link Connected![0m
    2022-11-25T07:36:09.198Z DEBUG modem << [00:00:02.726,440] [0m<inf> mqtt_simple: IPv4 Address found 91.121.93.94[0m
    2022-11-25T07:36:09.200Z DEBUG modem << [00:00:02.726,898] [0m<dbg> mqtt_simple: client_id_get: client_id = nrf-352656108600951[0m
    2022-11-25T07:36:09.204Z DEBUG modem << [00:00:02.947,387] [0m<inf> mqtt_simple: MQTT client connected[0m
    2022-11-25T07:36:09.221Z DEBUG modem << [00:00:02.947,418] [0m<inf> mqtt_simple: Subscribing to: my/subscribe/topic len 18[0m
    2022-11-25T07:36:09.223Z DEBUG modem << [00:00:03.020,416] [0m<inf> mqtt_simple: SUBACK packet id: 1234[0m
    2022-11-25T07:36:15.992Z DEBUG modem << [00:00:09.223,236] [0m<inf> mqtt_simple: Publishing: DevZone techsupport 298948[0m
    2022-11-25T07:36:16.010Z DEBUG modem << [00:00:09.223,297] [0m<inf> mqtt_simple: to topic: /testTopic len: 10[0m
    2022-11-25T07:36:16.012Z DEBUG modem << [00:00:09.427,856] [0m<inf> mqtt_simple: PUBACK packet id: 3373[0m
    2022-11-25T07:37:24.967Z DEBUG modem << [00:01:18.203,582] [0m<inf> mqtt_simple: MQTT PUBLISH result=0 len=36[0m
    2022-11-25T07:37:24.985Z DEBUG modem << [00:01:18.203,704] [0m<inf> mqtt_simple: Received: Hello to nrf-352656108600951 from PC[0m
    2022-11-25T07:37:24.987Z DEBUG modem << [00:01:18.204,254] [0m<inf> mqtt_simple: Publishing: Hello to nrf-352656108600951 from PC[0m
    2022-11-25T07:37:24.990Z DEBUG modem << [00:01:18.204,284] [0m<inf> mqtt_simple: to topic: /testTopic len: 10[0m
    2022-11-25T07:37:24.996Z DEBUG modem << [00:01:18.299,530] [0m<inf> mqtt_simple: PUBACK packet id: 20614[0m
    

    Here I have subscribed to /testTopic as your original post. We can see that I receive both messages posted to this topic from my nRF9160DK and my computer

    Can you please retry with the same broker? Also, please use the prj.conf to configure your project and leave Kconfig untouched. Here is my prj.conf

    #
    # Copyright (c) 2020 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # Networking
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    
    # Modem library
    CONFIG_NRF_MODEM_LIB=y
    
    # MQTT
    CONFIG_MQTT_LIB=y
    CONFIG_MQTT_LIB_TLS=n
    CONFIG_MQTT_CLEAN_SESSION=y
    
    # Application
    CONFIG_MQTT_PUB_TOPIC="/testTopic"
    # CONFIG_MQTT_SUB_TOPIC="my/subscribe/topic"
    # CONFIG_MQTT_CLIENT_ID="my-client-id"
    CONFIG_MQTT_BROKER_HOSTNAME="test.mosquitto.org"
    # CONFIG_MQTT_BROKER_PORT=1883
    CONFIG_BUTTON_EVENT_PUBLISH_MSG="DevZone techsupport 298948"
    
    # Button support
    CONFIG_DK_LIBRARY=y
    
    # Enable logging
    CONFIG_LOG=y
    CONFIG_MQTT_SIMPLE_LOG_LEVEL_DBG=y
    
    # Memory
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # NewLib C
    CONFIG_NEWLIB_LIBC=y
    '

    Kind regards,
    Øyvind

  • Thank you, I have made changes in the prj.conf according to what you sent as seen below, but I also kept my broker since it is already configured to my mobile application.

    This solved my initial issue and now I can connect to the server, I also commented out these lines below so that it would stop echoing messages to my second issue

     .

Reply Children
No Data
Related