Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
stm32f4发现上的lwIP mqtt连接错误_Mqtt_Stm32_Mosquitto_Lwip - Fatal编程技术网

stm32f4发现上的lwIP mqtt连接错误

stm32f4发现上的lwIP mqtt连接错误,mqtt,stm32,mosquitto,lwip,Mqtt,Stm32,Mosquitto,Lwip,我正在尝试将lwIP用于客户端,它将数据发送到stm32f407 discovery上的mosquitto代理 Mqtt应用程序在lwIP上实现。我只是在初始化之后在main中这样使用它们。 mqtt_客户端\u t静态客户端 然后,通过USART中断,我调用 示例\u do\u connect(&static\u客户端);示例发布(静态客户端(&U),0) 它调用这些函数: { struct mqtt_connect_client_info_t ci; err_t err; /*

我正在尝试将lwIP用于客户端,它将数据发送到stm32f407 discovery上的mosquitto代理

Mqtt应用程序在lwIP上实现。我只是在初始化之后在main中这样使用它们。
mqtt_客户端\u t静态客户端

然后,通过USART中断,我调用
示例\u do\u connect(&static\u客户端);示例发布(静态客户端(&U),0)

它调用这些函数:

{
  struct mqtt_connect_client_info_t ci;
  err_t err;

  /* Setup an empty client info structure */
  memset(&ci, 0, sizeof(ci));

  /* Minimal amount of information required is client identifier, so set it here */
  ci.client_id = "lwip_test";
    ci.client_user = NULL;
    ci.client_pass = NULL;

  /* Initiate client and connect to server, if this fails immediately an error code is returned
     otherwise mqtt_connection_cb will be called with connection result after attempting
     to establish a connection with the server.
     For now MQTT version 3.1.1 is always used */

  err = mqtt_client_connect(client, &serverIp, MQTT_PORT, mqtt_connection_cb, 0, &ci);

  /* For now just print the result code if something goes wrong*/
  if(err != ERR_OK) {

  }
}

我能够ping板,我的IP地址主要通过使用
IP_ADDR4(&serverIp,192168,2,97)分配

我已经使用了所有需要的函数,比如MX_LWIP_Init()、MX_LWIP_Process(),实际上我甚至能够实现一个TCP客户端,它工作得很好。所以互联网连接很好,但我想,我在mqttclient中遗漏了一点。Erik Anderssen的指南也提供了回调功能

当我尝试使用MOSQUITO订阅board的IP时,出现错误:无法建立连接,因为目标主动拒绝它。如果你注意到我遗漏了什么或有什么想法,请告诉我


感谢您的帮助。

我遇到了一个类似的问题,当QoS(服务质量)设置为2时,服务器拒绝连接,但服务器需要它为0。尝试将连接回调中的行中的参数qos更改为0或1:

err=mqtt_subscribe(mqtt.client,“topic”,qos,MqttApp_SubscribeRequestCallback,arg)

这同样适用于发布函数中的参数qos:

更改
u8\u t qos=2
u8\u t qos=0(或1-服务器需要的任何代码)

希望能有帮助。干杯


void example_publish(mqtt_client_t *client, void *arg)
{
  const char *pub_payload= "stm32_test";
  err_t err;
  u8_t qos = 2; /* 0 1 or 2, see MQTT specification */
  u8_t retain = 0; /* No don't retain such crappy payload... */
  err = mqtt_publish(client, "pub_topic", pub_payload, strlen(pub_payload), qos, retain, mqtt_pub_request_cb, arg);
  if(err != ERR_OK) {
  //  printf("Publish err: %d\n", err);
    err = ERR_OK;
  }
}

/* Called when publish is complete either with sucess or failure */
static void mqtt_pub_request_cb(void *arg, err_t result)
{
  if(result != ERR_OK) {
  //  printf("Publish result: %d\n", result);
  }
}