Hi, I am trying the MQTT_SIMPLE sample on both the nRF9160DK and my own custom board. I have mfw_nrf9160_1.3.1 on both nRF9160 and I am using SDK v1.8.0. LTE connection seems ok, but I don't seem to be able to connect to my AWS EC2. Here are the console messages:
*** Booting Zephyr OS build v2.7.0-ncs1 ***
[00:00:00.205,871] <wrn> at_notif: Already initialized. Nothing to do
[00:00:00.205,932] <inf> at_host: UART check failed: 12. Dropping buffer and retrying.
[00:00:00.225,006] <inf> mqtt_simple: The MQTT simple sample started
[00:00:00.225,006] <inf> mqtt_simple: Disabling PSM and eDRX
[00:00:00.225,830] <inf> mqtt_simple: LTE Link Connecting...
[00:00:11.566,528] <inf> mqtt_simple: LTE Link Connected!
[00:00:12.205,474] <inf> mqtt_simple: IPv4 Address found 52.60.???.???
[00:00:12.205,505] <dbg> mqtt_simple.client_id_get: client_id = my-client-id
[00:00:12.205,932] <dbg> net_mqtt_sock_tcp.mqtt_client_tcp_connect: (0x20014ac8): Created socket 1
[00:00:12.588,592] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:00:12.588,592] <inf> mqtt_simple: to topic: testing len: 7
[00:00:12.588,592] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x00]: >> Topic size 0x00000007, Data size 0x00000023
[00:00:12.712,982] <dbg> net_mqtt_enc.connect_request_encode: (0x20014ac8): Encoding Protocol Version 04.
--- 6 messages dropped ---
[00:00:12.712,982] <dbg> net_mqtt_enc.connect_request_encode: (0x20014ac8): Encoding Keep Alive Time 003c.
--- 4 messages dropped ---
[00:00:12.713,043] <dbg> net_mqtt_enc: Encoding Username.
?? ?? ?? ?? ?? ?? ?? |???????
[00:00:12.713,043] <dbg> net_mqtt_enc.pack_utf8_str: (0x20014ac8): >> str_size:00000009 cur:0x200154d3, end:0x20015536
[00:00:12.713,073] <dbg> net_mqtt_enc.pack_uint16: (0x20014ac8): >> val:0007 cur:0x200154d3, end:0x20015536
[00:00:12.713,073] <dbg> net_mqtt_enc: Encoding Password.
?? ?? ?? ?? ?? ?? ?? |???????
[00:00:12.713,073] <dbg> net_mqtt_enc.pack_utf8_str: (0x20014ac8): >> str_size:00000009 cur:0x200154dc, end:0x20015536
[00:00:12.713,104] <dbg> net_mqtt_enc.pack_uint16: (0x20014ac8): >> val:0007 cur:0x200154dc, end:0x20015536
[00:00:12.713,104] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20014ac8): << msg type:0x10 length:0x0000002a
--- 1 messages dropped ---
[00:00:12.713,134] <dbg> net_mqtt_enc.mqtt_encode_fixed_header: (0x20014ac8): Fixed header length = 02
[00:00:12.713,165] <dbg> net_mqtt_enc.pack_uint8: (0x20014ac8): >> val:10 cur:0x200154b9, end:0x20015536
[00:00:12.713,165] <dbg> net_mqtt_enc.packet_length_encode: (0x20014ac8): >> length:0x0000002a cur:0x200154ba, end:0x20015536
[00:00:12.713,806] <dbg> net_mqtt.client_connect: (0x20014ac8): Connect completed
[00:00:12.713,836] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:00:12.713,867] <err> mqtt_simple: Publish failed: -128
[00:00:12.734,344] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:00:12.734,344] <inf> mqtt_simple: to topic: testing len: 7
[00:00:12.734,375] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: >> Topic size 0x00000007, Data size 0x00000023
[00:00:12.734,405] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:00:12.734,436] <err> mqtt_simple: Publish failed: -128
[00:00:12.785,095] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:00:12.785,095] <inf> mqtt_simple: to topic: testing len: 7
[00:00:12.785,095] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: >> Topic size 0x00000007, Data size 0x00000023
[00:00:12.785,125] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:00:12.785,125] <err> mqtt_simple: Publish failed: -128
[00:00:12.825,714] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:00:12.825,714] <inf> mqtt_simple: to topic: testing len: 7
[00:00:12.825,714] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: >> Topic size 0x00000007, Data size 0x00000023
[00:00:12.825,744] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:00:12.825,775] <err> mqtt_simple: Publish failed: -128
[00:00:12.936,889] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:00:12.936,889] <inf> mqtt_simple: to topic: testing len: 7
[00:00:12.936,920] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: >> Topic size 0x00000007, Data size 0x00000023
[00:00:12.936,950] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:00:12.936,950] <err> mqtt_simple: Publish failed: -128
[00:01:12.713,043] <err> mqtt_simple: ERROR: mqtt_live: -128
[00:01:12.713,043] <inf> mqtt_simple: Disconnecting MQTT client...
[00:01:12.713,073] <err> mqtt_simple: Could not disconnect MQTT client: -128
[00:01:12.713,073] <inf> mqtt_simple: Reconnecting in 60 seconds...
[00:01:12.747,802] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:01:12.747,833] <inf> mqtt_simple: to topic: testing len: 7
[00:01:12.747,833] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: >> Topic size 0x00000007, Data size 0x00000023
[00:01:12.747,863] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:01:12.747,863] <err> mqtt_simple: Publish failed: -128
[00:01:12.778,411] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:01:12.778,411] <inf> mqtt_simple: to topic: testing len: 7
[00:01:12.778,411] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: >> Topic size 0x00000007, Data size 0x00000023
[00:01:12.778,442] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:01:12.778,442] <err> mqtt_simple: Publish failed: -128
[00:01:12.808,990] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:01:12.808,990] <inf> mqtt_simple: to topic: testing len: 7
[00:01:12.808,990] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: >> Topic size 0x00000007, Data size 0x00000023
[00:01:12.809,020] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:01:12.809,020] <err> mqtt_simple: Publish failed: -128
[00:01:12.930,297] <inf> mqtt_simple: Publishing: Hello from nRF91 MQTT Simple Sample
[00:01:12.930,297] <inf> mqtt_simple: to topic: testing len: 7
[00:01:12.930,297] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: >> Topic size 0x00000007, Data size 0x00000023
[00:01:12.930,328] <dbg> net_mqtt.mqtt_publish: (0x20014b48): [CID 0x20014bf0]:[State 0x02]: << result 0xffffff80
[00:01:12.930,328] <err> mqtt_simple: Publish failed: -128
I masked the broker IP address, username and password here for the obvious reason. My understanding is that error 128 means "socket not connected".
Below 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
CONFIG_NET_LOG=y
# LTE link control
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
# Modem library
CONFIG_NRF_MODEM_LIB=y
# AT Host
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y
# MQTT
CONFIG_MQTT_LIB=y
CONFIG_MQTT_LIB_TLS=n
CONFIG_MQTT_CLEAN_SESSION=y
CONFIG_MQTT_LOG_LEVEL_DBG=y
# Application
CONFIG_MQTT_PUB_TOPIC="testing"
CONFIG_MQTT_SUB_TOPIC="testing"
CONFIG_MQTT_CLIENT_ID="my-client-id"
CONFIG_MQTT_BROKER_HOSTNAME="ec2-52-60-???-???.ca-central-1.compute.amazonaws.com"
CONFIG_MQTT_BROKER_PORT=????
# 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
And here is my Kconfig.
#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
menu "MQTT simple sample"
config MQTT_PUB_TOPIC
string "MQTT publish topic"
default "testing"
config MQTT_SUB_TOPIC
string "MQTT subscribe topic"
default "testing"
config MQTT_CLIENT_ID
string "MQTT Client ID"
help
Use a custom Client ID string. If not set, the client ID will be
generated based on IMEI number (for nRF9160 based targets) or
randomly (for other platforms).
default "my-client-id"
config MQTT_BROKER_HOSTNAME
string "MQTT broker hostname"
default "ec2-52-60-???-???.ca-central-1.compute.amazonaws.com"
config MQTT_BROKER_PORT
int "MQTT broker port"
default ????
config MQTT_MESSAGE_BUFFER_SIZE
int "MQTT message buffer size"
default 128
config MQTT_PAYLOAD_BUFFER_SIZE
int "MQTT payload buffer size"
default 128
config BUTTON_EVENT_PUBLISH_MSG
string "The message to publish on a button event"
default "Hello from nRF91 MQTT Simple Sample"
config BUTTON_EVENT_BTN_NUM
int "The button number"
default 1
config MQTT_RECONNECT_DELAY_S
int "Seconds to delay before attempting to reconnect to the broker."
default 60
config LTE_CONNECT_RETRY_DELAY_S
int "Seconds to delay before attempting to retry LTE connection."
default 120
config MQTT_TLS_SEC_TAG
int "TLS credentials security tag"
default 24
config MQTT_TLS_SESSION_CACHING
bool "Enable TLS session caching"
config MQTT_TLS_PEER_VERIFY
int "Set peer verification level"
default 2
help
Set to 0 for VERIFY_NONE, 1 for VERIFY_OPTIONAL, and 2 for
VERIFY_REQUIRED.
endmenu
menu "Zephyr Kernel"
source "Kconfig.zephyr"
endmenu
module = MQTT_SIMPLE
module-str = MQTT Simple
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
Can anyone please help me locate the problem? Your help is very much appreciated.