Hi Support team,
The communication of my net-core of nRF5340 is working well, and I want to try mqtt subscription, but it always fails, could you help give me some hints?
I try to do the subscription in the event handler of MQTT_EVT_CONNACK:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define SPARKPLUGB_NCMD "spBv1.0/BDS/NCMD/Node1/#"
#define SPARKPLUGB_DCMD "spBv1.0/BDS/DCMD/Node1/#"
int sparkb_sub_cmd(struct mqtt_client *const client)
{
struct mqtt_topic cmdTopic[2];
cmdTopic[0].topic.utf8 = (uint8_t *)SPARKPLUGB_NCMD;
cmdTopic[0].topic.size = strlen(SPARKPLUGB_NCMD);
cmdTopic[0].qos = MQTT_QOS_0_AT_MOST_ONCE;
cmdTopic[1].topic.utf8 = (uint8_t *)SPARKPLUGB_DCMD;
cmdTopic[1].topic.size = strlen(SPARKPLUGB_DCMD);
cmdTopic[1].qos = MQTT_QOS_0_AT_MOST_ONCE;
struct mqtt_subscription_list sub_param = {
.list = cmdTopic,
.list_count = 2,
.message_id = 0U
};
return mqtt_subscribe(client, &sub_param);
}
The MQTT connection succeded, but the subscription is failed, the error code is -22 (#define EINVAL 22 /* Invalid argument */), the trace as below:
Fullscreen
1
2
3
4
5
[00:00:25.672,332] <inf> main: modem_test() successful!
[00:00:25.905,395] <inf> mqtttest: mqtt_connect OK, rc is 0
[00:00:26.146,850] <inf> mqtttest: do zsock_poll() 2s, ret = 1
[00:00:26.146,972] <inf> mqtttest: -----[MQTT_EVT_CONNACK] MQTT client connected!
[00:00:26.147,003] <err> mqtttest: -----[MQTT_EVT_CONNACK] Failed to subscribe sparkplug NCMD and DCMD: -22
The published two topics "spBv1.0/BDS/NCMD/Node1/#" and "spBv1.0/BDS/DCMD/Node1/#" by other mqtt clients, so these two topics have existed on the MQTT server.
Could you help have a look and give some hints as to why subscriptions always fail? Thank you very much.
Best regards,
Yanpeng Wu