Issue Description
The application starts successfully,
initializes the modem library,
connects to the LTE network,
resolves the MQTT broker's address, and establishes an MQTT connection.
It's seem I can reach to the mqtt server but unable to publish message and return -128 error code.
Environment Details
-
nRF Connect SDK version: v2.8.0
-
Zephyr OS version: v3.7.99-0bc3393fb112
-
Hardware: Nordic nRF9151 DK
-
Application: Lesson 4 Exercise 1 from Nordic tutorials
- Windows 11
- Vietnam
- Viettel Network
Log Extract (Key Sections):
<inf> net_mqtt: Connect completed
<inf> Lesson4_Exercise1: Publishing: Hi from nRF91 Series device
<inf> Lesson4_Exercise1: to topic: devacademy/publish/topic len: 24
<inf> Lesson4_Exercise1: Failed to send message, -128
<err> Lesson4_Exercise1: Error in mqtt_live: -128
<err> Lesson4_Exercise1: Could not disconnect MQTT client: -128
*** Booting nRF Connect SDK v2.8.0-a2386bfc8401 ***
*** Using Zephyr OS v3.7.99-0bc3393fb112 ***
[00:00:00.290,252] <inf> Lesson4_Exercise1: Starting Lesson 4 Exercise 1
[00:00:00.290,313] <inf> Lesson4_Exercise1: Initializing modem library
[00:00:00.290,344] <inf> nrf_modem: Initializing libmodem 2.8.0-cellular-5a5ee934d77d
[00:00:00.290,771] <dbg> nrf_modem: Control region at 0x20008000 (0x4e8 bytes)
[00:00:00.290,802] <dbg> nrf_modem: TX region at 0x200084e8 (0x2000 bytes)
[00:00:00.290,832] <dbg> nrf_modem: RX region at 0x2000a568 (0x2000 bytes)
[00:00:00.290,863] <dbg> nrf_modem: Trace region at 0x0 (0x0 bytes)
[00:00:00.549,438] <dbg> nrf_modem: Handshake completed
[00:00:00.549,499] <dbg> nrf_modem: Modem data list size: 32
[00:00:00.549,530] <dbg> nrf_modem: Modem control list size: 16
[00:00:00.549,560] <inf> nrf_modem: RPC ready
[00:00:00.549,987] <dbg> nrf_modem: nrf_modem_lib_init: Modem init callback: 0xe629
[00:00:00.550,018] <dbg> nrf_modem: nrf_modem_lib_init: Modem init callback: 0x10311
[00:00:00.550,140] <dbg> nrf_modem: AT%XCOEX0=1,1,1565,1586
[00:00:00.556,976] <dbg> nrf_modem: OK
[00:00:00.557,067] <dbg> nrf_modem: nrf_modem_lib_init: Modem init callback: 0xf869
[00:00:00.557,220] <dbg> nrf_modem: AT%XSYSTEMMODE=0,1,0,0
[00:00:00.563,751] <dbg> nrf_modem: OK
[00:00:00.563,812] <dbg> lte_lc: xsystemmode_mode_set: System mode set to 2, preference 0
[00:00:00.563,964] <dbg> nrf_modem: AT%FEACONF=0,3,1
[00:00:00.564,544] <dbg> nrf_modem: OK
[00:00:00.564,636] <inf> Lesson4_Exercise1: Connecting to LTE network
[00:00:00.564,636] <dbg> lte_lc: lte_lc_connect_async: Connecting asynchronously
[00:00:00.564,727] <dbg> nrf_modem: AT+CEREG?
[00:00:00.565,002] <dbg> nrf_modem: +CEREG: 0,4
[00:00:00.565,185] <dbg> nrf_modem: AT+CFUN?
[00:00:00.571,777] <dbg> nrf_modem: +CFUN: 0
[00:00:00.571,960] <dbg> nrf_modem: AT+CEREG=5
[00:00:00.578,186] <dbg> nrf_modem: OK
[00:00:00.578,338] <dbg> nrf_modem: AT+CSCON=1
[00:00:00.578,613] <dbg> nrf_modem: OK
[00:00:00.578,765] <dbg> nrf_modem: AT+CFUN=1
[00:00:00.603,332] <dbg> nrf_modem: OK
[00:00:00.603,393] <dbg> nrf_modem: cfun_callback: CFUN callback 0xf7ed
[00:00:00.603,424] <dbg> lte_lc: cfun_mode_set: Functional mode set to 1
[00:00:02.891,967] <dbg> nrf_modem: +CEREG: 2,"B052","090D4016",9
+CEREG: 2,"B052","090D4016",9
[00:00:02.892,181] <dbg> lte_lc: at_handler_cereg: +CEREG notification: +CEREG: 2,"B052","090D4016",9
[00:00:02.892,242] <dbg> lte_lc: parse_cereg: Network registration status: 2
[00:00:02.892,364] <dbg> lte_lc: parse_cereg: LTE mode: 9
[00:00:02.892,395] <dbg> lte_lc: event_handler_list_dispatch: Dispatching event: type=0
[00:00:02.892,425] <dbg> lte_lc: event_handler_list_dispatch: - handler=0x000088F9
[00:00:02.892,425] <dbg> lte_lc: event_handler_list_dispatch: Done
[00:00:02.892,456] <dbg> lte_lc: event_handler_list_dispatch: Dispatching event: type=4
[00:00:02.892,456] <dbg> lte_lc: event_handler_list_dispatch: - handler=0x000088F9
[00:00:02.892,486] <dbg> lte_lc: event_handler_list_dispatch: Done
[00:00:02.892,486] <dbg> lte_lc: event_handler_list_dispatch: Dispatching event: type=5
[00:00:02.892,517] <dbg> lte_lc: event_handler_list_dispatch: - handler=0x000088F9
[00:00:02.892,517] <dbg> lte_lc: event_handler_list_dispatch: Done
[00:00:03.290,618] <dbg> nrf_modem: +CSCON: 1
+CSCON: 1
[00:00:03.290,771] <dbg> lte_lc: at_handler_cscon: +CSCON notification
[00:00:03.290,832] <dbg> lte_lc: event_handler_list_dispatch: Dispatching event: type=3
[00:00:03.290,863] <dbg> lte_lc: event_handler_list_dispatch: - handler=0x000088F9
[00:00:03.290,863] <inf> Lesson4_Exercise1: RRC mode: Connected
[00:00:03.290,893] <dbg> lte_lc: event_handler_list_dispatch: Done
[00:00:04.625,457] <dbg> nrf_modem: +CEREG: 1,"B052","090D4016",9,,,"11100000","11100000"
+CEREG: 1,"B052","090D4016",9,,,"11100000","11100000"
[00:00:04.625,671] <dbg> lte_lc: at_handler_cereg: +CEREG notification: +CEREG: 1,"B052","090D4016",9,,,"11100000","11100000"
[00:00:04.625,732] <dbg> lte_lc: parse_cereg: Network registration status: 1
[00:00:04.625,915] <dbg> lte_lc: parse_cereg: LTE mode: 9
[00:00:04.625,946] <dbg> lte_lc: event_handler_list_dispatch: Dispatching event: type=0
[00:00:04.625,976] <dbg> lte_lc: event_handler_list_dispatch: - handler=0x000088F9
[00:00:04.626,007] <inf> Lesson4_Exercise1: Network registration status: Connected - home network
[00:00:04.626,037] <dbg> lte_lc: event_handler_list_dispatch: Done
[00:00:04.626,281] <inf> nrf_modem: getaddrinfo() fam: 0x1, type 0x1, proto 0x6
[00:00:05.010,589] <inf> nrf_modem: RPC_IP_GETADDRINFO_RES, result RPC_IP_ERR_OK
[00:00:05.010,772] <inf> nrf_modem: getaddrinfo() resolved 20.82.16.164
[00:00:05.010,925] <inf> Lesson4_Exercise1: IPv4 Address found 20.82.16.164
[00:00:05.011,016] <dbg> nrf_modem: AT+CGSN
[00:00:05.011,535] <dbg> nrf_modem: 359404230010788
[00:00:05.011,657] <inf> nrf_modem: socket() fam 0x1, type 0x1, proto 0x6 (0x2000d798)
[00:00:05.011,901] <inf> nrf_modem: RPC_IP_OPEN_RES result RPC_IP_ERR_OK
[00:00:05.011,962] <dbg> nrf_modem: socket() 0x2000d798 has fd 0x0
[00:00:05.011,993] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (0x2000d068): Created socket 0
[00:00:05.012,054] <inf> nrf_modem: connect() fd 0x0, family 0x1, port 1883
[00:00:05.335,540] <inf> nrf_modem: RPC_IP_CONNECT_RES fd 0x0, result RPC_IP_ERR_OK
[00:00:05.335,632] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (0x2000d068): Connect completed
[00:00:05.335,662] <dbg> net_mqtt_enc: connect_request_encode: Encoding Protocol Description.
4d 51 54 54 |MQTT
[00:00:05.335,693] <dbg> net_mqtt_enc: pack_utf8_str: (0x2000d068): >> str_size:00000006 cur:0x2000dc15, end:0x2000dc90
[00:00:05.335,693] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:0004 cur:0x2000dc15, end:0x2000dc90
[00:00:05.335,723] <dbg> net_mqtt_enc: connect_request_encode: (0x2000d068): Encoding Protocol Version 04.
[00:00:05.335,723] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:04 cur:0x2000dc1b, end:0x2000dc90
[00:00:05.335,754] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:00 cur:0x2000dc1c, end:0x2000dc90
[00:00:05.335,754] <dbg> net_mqtt_enc: connect_request_encode: (0x2000d068): Encoding Keep Alive Time 001e.
[00:00:05.335,784] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:001e cur:0x2000dc1d, end:0x2000dc90
[00:00:05.335,815] <dbg> net_mqtt_enc: connect_request_encode: Encoding Client Id.
6e 72 66 2d 33 35 39 34 30 34 32 33 30 30 31 30 |nrf-3594 04230010
37 38 38 |788
[00:00:05.335,815] <dbg> net_mqtt_enc: pack_utf8_str: (0x2000d068): >> str_size:00000015 cur:0x2000dc1f, end:0x2000dc90
[00:00:05.335,845] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:0013 cur:0x2000dc1f, end:0x2000dc90
[00:00:05.335,876] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (0x2000d068): << msg type:0x10 length:0x0000001f
[00:00:05.335,876] <dbg> net_mqtt_enc: packet_length_encode: (0x2000d068): >> length:0x0000001f cur:(nil), end:(nil)
[00:00:05.335,906] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (0x2000d068): Fixed header length = 02
[00:00:05.335,906] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:10 cur:0x2000dc13, end:0x2000dc90
[00:00:05.335,906] <dbg> net_mqtt_enc: packet_length_encode: (0x2000d068): >> length:0x0000001f cur:0x2000dc14, end:0x2000dc90
[00:00:05.335,968] <inf> nrf_modem: send() fd 0x0, len 33, flags 0x0 (blocking)
[00:00:05.336,761] <inf> nrf_modem: RPC_IP_SEND_RES fd 0x0, result RPC_IP_ERR_OK
[00:00:05.336,853] <inf> nrf_modem: send() fd 0x0, 33 bytes sent
[00:00:05.336,853] <inf> net_mqtt: Connect completed
[00:00:13.004,760] <inf> Lesson4_Exercise1: Publishing: Hi from nRF91 Series device
[00:00:13.004,821] <inf> Lesson4_Exercise1: to topic: devacademy/publish/topic len: 24
[00:00:13.004,852] <dbg> net_mqtt: mqtt_publish: (0x2000d0f0): [CID 0x2000d248]:[State 0x02]: >> Topic size 0x00000018, Data size 0x00
00001b
[00:00:13.004,882] <dbg> net_mqtt: mqtt_publish: (0x2000d0f0): [CID 0x2000d248]:[State 0x02]: << result 0xffffff80
[00:00:13.004,882] <inf> Lesson4_Exercise1: Failed to send message, -128
[00:00:35.336,975] <err> Lesson4_Exercise1: Error in mqtt_live: -128
[00:00:35.337,005] <inf> Lesson4_Exercise1: Disconnecting MQTT client
[00:00:35.337,036] <err> Lesson4_Exercise1: Could not disconnect MQTT client: -128
[00:00:35.337,036] <inf> Lesson4_Exercise1: Reconnecting in 60 seconds...
[00:01:05.030,395] <dbg> nrf_modem: +CSCON: 0
+CSCON: 0
[00:01:05.030,578] <dbg> lte_lc: at_handler_cscon: +CSCON notification
[00:01:05.030,609] <dbg> lte_lc: event_handler_list_dispatch: Dispatching event: type=3
[00:01:05.030,639] <dbg> lte_lc: event_handler_list_dispatch: - handler=0x000088F9
[00:01:05.030,670] <inf> Lesson4_Exercise1: RRC mode: Idle
[00:01:05.030,670] <dbg> lte_lc: event_handler_list_dispatch: Done
[00:01:06.002,868] <dbg> nrf_modem: +CSCON: 1
+CSCON: 1
[00:01:06.002,990] <dbg> lte_lc: at_handler_cscon: +CSCON notification
[00:01:06.003,082] <dbg> lte_lc: event_handler_list_dispatch: Dispatching event: type=3
[00:01:06.003,082] <dbg> lte_lc: event_handler_list_dispatch: - handler=0x000088F9
[00:01:06.003,112] <inf> Lesson4_Exercise1: RRC mode: Connected
[00:01:06.003,112] <dbg> lte_lc: event_handler_list_dispatch: Done
[00:01:35.337,402] <inf> nrf_modem: RPC_IP_OPEN_RES result RPC_IP_ERR_OK
--- 4 messages dropped ---
[00:01:35.992,767] <inf> nrf_modem: RPC_IP_CONNECT_RES fd 0x1, result RPC_IP_ERR_OK
[00:01:35.992,828] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (0x2000d068): Connect completed
[00:01:35.992,889] <dbg> net_mqtt_enc: connect_request_encode: Encoding Protocol Description.
4d 51 54 54 |MQTT
[00:01:35.992,889] <dbg> net_mqtt_enc: pack_utf8_str: (0x2000d068): >> str_size:00000006 cur:0x2000dc15, end:0x2000dc90
[00:01:35.992,919] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:0004 cur:0x2000dc15, end:0x2000dc90
[00:01:35.992,950] <dbg> net_mqtt_enc: connect_request_encode: (0x2000d068): Encoding Protocol Version 04.
[00:01:35.992,950] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:04 cur:0x2000dc1b, end:0x2000dc90
[00:01:35.992,980] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:00 cur:0x2000dc1c, end:0x2000dc90
[00:01:35.992,980] <dbg> net_mqtt_enc: connect_request_encode: (0x2000d068): Encoding Keep Alive Time 001e.
[00:01:35.993,011] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:001e cur:0x2000dc1d, end:0x2000dc90
[00:01:35.993,011] <dbg> net_mqtt_enc: connect_request_encode: Encoding Client Id.
6e 72 66 2d 33 35 39 34 30 34 32 33 30 30 31 30 |nrf-3594 04230010
37 38 38 |788
[00:01:35.993,041] <dbg> net_mqtt_enc: pack_utf8_str: (0x2000d068): >> str_size:00000015 cur:0x2000dc1f, end:0x2000dc90
[00:01:35.993,041] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:0013 cur:0x2000dc1f, end:0x2000dc90
[00:01:35.993,072] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (0x2000d068): << msg type:0x10 length:0x0000001f
[00:01:35.993,072] <dbg> net_mqtt_enc: packet_length_encode: (0x2000d068): >> length:0x0000001f cur:(nil), end:(nil)
[00:01:35.993,103] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (0x2000d068): Fixed header length = 02
[00:01:35.993,103] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:10 cur:0x2000dc13, end:0x2000dc90
[00:01:35.993,133] <dbg> net_mqtt_enc: packet_length_encode: (0x2000d068): >> length:0x0000001f cur:0x2000dc14, end:0x2000dc90
[00:01:35.993,194] <inf> nrf_modem: send() fd 0x1, len 33, flags 0x0 (blocking)
[00:01:35.993,988] <inf> nrf_modem: RPC_IP_SEND_RES fd 0x1, result RPC_IP_ERR_OK
[00:01:35.994,079] <inf> nrf_modem: send() fd 0x1, 33 bytes sent
[00:01:35.994,110] <inf> net_mqtt: Connect completed
[00:02:05.994,262] <err> Lesson4_Exercise1: Error in mqtt_live: -128
[00:02:05.994,293] <inf> Lesson4_Exercise1: Disconnecting MQTT client
[00:02:05.994,323] <err> Lesson4_Exercise1: Could not disconnect MQTT client: -128
[00:02:05.994,354] <inf> Lesson4_Exercise1: Reconnecting in 60 seconds...
[00:03:05.994,689] <inf> nrf_modem: RPC_IP_OPEN_RES result RPC_IP_ERR_OK
--- 3 messages dropped ---
[00:03:05.994,842] <inf> nrf_modem: connect() fd 0x2, family 0x1, port 1883
[00:03:06.557,006] <inf> nrf_modem: RPC_IP_CONNECT_RES fd 0x2, result RPC_IP_ERR_OK
[00:03:06.557,067] <dbg> net_mqtt_sock_tcp: mqtt_client_tcp_connect: (0x2000d068): Connect completed
[00:03:06.557,098] <dbg> net_mqtt_enc: connect_request_encode: Encoding Protocol Description.
4d 51 54 54 |MQTT
[00:03:06.557,098] <dbg> net_mqtt_enc: pack_utf8_str: (0x2000d068): >> str_size:00000006 cur:0x2000dc15, end:0x2000dc90
[00:03:06.557,128] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:0004 cur:0x2000dc15, end:0x2000dc90
[00:03:06.557,159] <dbg> net_mqtt_enc: connect_request_encode: (0x2000d068): Encoding Protocol Version 04.
[00:03:06.557,159] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:04 cur:0x2000dc1b, end:0x2000dc90
[00:03:06.557,189] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:00 cur:0x2000dc1c, end:0x2000dc90
[00:03:06.557,189] <dbg> net_mqtt_enc: connect_request_encode: (0x2000d068): Encoding Keep Alive Time 001e.
[00:03:06.557,220] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:001e cur:0x2000dc1d, end:0x2000dc90
[00:03:06.557,220] <dbg> net_mqtt_enc: connect_request_encode: Encoding Client Id.
6e 72 66 2d 33 35 39 34 30 34 32 33 30 30 31 30 |nrf-3594 04230010
37 38 38 |788
[00:03:06.557,250] <dbg> net_mqtt_enc: pack_utf8_str: (0x2000d068): >> str_size:00000015 cur:0x2000dc1f, end:0x2000dc90
[00:03:06.557,250] <dbg> net_mqtt_enc: pack_uint16: (0x2000d068): >> val:0013 cur:0x2000dc1f, end:0x2000dc90
[00:03:06.557,281] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (0x2000d068): << msg type:0x10 length:0x0000001f
[00:03:06.557,281] <dbg> net_mqtt_enc: packet_length_encode: (0x2000d068): >> length:0x0000001f cur:(nil), end:(nil)
[00:03:06.557,312] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (0x2000d068): Fixed header length = 02
[00:03:06.557,312] <dbg> net_mqtt_enc: pack_uint8: (0x2000d068): >> val:10 cur:0x2000dc13, end:0x2000dc90
[00:03:06.557,342] <dbg> net_mqtt_enc: packet_length_encode: (0x2000d068): >> length:0x0000001f cur:0x2000dc14, end:0x2000dc90
[00:03:06.557,403] <inf> nrf_modem: send() fd 0x2, len 33, flags 0x0 (blocking)
[00:03:06.558,197] <inf> nrf_modem: RPC_IP_SEND_RES fd 0x2, result RPC_IP_ERR_OK
[00:03:06.558,288] <inf> nrf_modem: send() fd 0x2, 33 bytes sent
[00:03:06.558,319] <inf> net_mqtt: Connect completed
[00:03:36.558,441] <err> Lesson4_Exercise1: Error in mqtt_live: -128
[00:03:36.558,471] <inf> Lesson4_Exercise1: Disconnecting MQTT client
[00:03:36.558,502] <err> Lesson4_Exercise1: Could not disconnect MQTT client: -128
[00:03:36.558,532] <inf> Lesson4_Exercise1: Reconnecting in 60 seconds...
[00:03:40.402,160] <inf> Lesson4_Exercise1: Publishing: Hi from nRF91 Series device
[00:03:40.402,221] <inf> Lesson4_Exercise1: to topic: devacademy/publish/topic len: 24
[00:03:40.402,252] <dbg> net_mqtt: mqtt_publish: (0x2000d0f0): [CID 0x2000d248]:[State 0x02]: >> Topic size 0x00000018, Data size 0x00
00001b
[00:03:40.402,282] <dbg> net_mqtt: mqtt_publish: (0x2000d0f0): [CID 0x2000d248]:[State 0x02]: << result 0xffffff80
[00:03:40.402,282] <inf> Lesson4_Exercise1: Failed to send message, -128