【问题标题】:MQTT using TC3_IoT_Communication; no connection with MQTT broker but there is no error使用 TC3_IoT_Communication 的 MQTT;没有与 MQTT 代理连接,但没有错误
【发布时间】:2019-05-24 13:03:09
【问题描述】:

我的计算机上运行了一个 mqtt 代理,我可以使用 twincat 连接到它。我将 mqtt 代理移动到同一网络上的服务器。

我可以使用 Node-RED 连接它(因此主机名、主机端口、用户名和密码必须正确),但 TwinCAT 无法连接到它。这是我用来连接到我的 MQTT 代理的代码。

我的变量:

fbMqttClient    : FB_IotMqttClient; // MQTT client
bSetParameter   : BOOL := TRUE; // set parameters once at start up
bConnect    : BOOL := TRUE; // if TRUE it will trigger MQTT client cyclically

我的代码:

// set parameters once when connecting to the mqtt broker
IF bSetParameter THEN
    bSetParameter               := FALSE;
    fbMqttClient.sHostName      := '172.16.1.51';
    fbMqttClient.nHostPort      := 1883;
    fbMqttClient.sTopicPrefix   := ''; 
    fbMqttClient.sUserName      := 'User';
    fbMqttClient.sUserPassword  := 'TopSecret'; 
    fbMqttClient.ipMessageQueue := fbMessageQueue;
END_IF

// MQTT client must be triggered cyclically
fbMqttClient.Execute(bConnect);

我希望在我的代理和 TwinCAT 之间建立连接。相反,我没有连接,我从 fbMqttClient 获取这些数据:

bError = FALSE <br>
hrErrorCode = 16#00000001 <br>
eConnectionState = MQTT_ERR_NO_CONN

我希望有人可以帮助我找出问题出在哪里以及如何解决这个问题。

【问题讨论】:

  • PLC在哪里运行?
  • ...(即在您最初也运行代理的计算机上,还是在单独的计算机上)?红色节点是否与 PLC 在同一台机器上运行?您是否尝试过完全关闭 PLC 上的防火墙?

标签: mqtt twincat structured-text


【解决方案1】:

确保您的 Beckhoff 运行时已激活 mqtt 许可证和配置。

【讨论】:

  • 已激活。我与同一台计算机上的 mqtt 代理连接没有问题。
【解决方案2】:

尝试连接到public broker。如果它有效,它一定是你的服务器。

【讨论】:

  • 我将代码更改为:``` // 连接到 mqtt 代理时设置一次参数 IF bSetParameter THEN bSetParameter := FALSE; //fbMqttClient.sHostName := '172.16.1.51'; fbMqttClient.sHostName := 'broker.hivemq.com'; fbMqttClient.nHostPort := 1883; fbMqttClient.sTopicPrefix := ''; //fbMqttClient.sUserName := '用户'; //fbMqttClient.sUserPassword := 'TopSecret'; fbMqttClient.ipMessageQueue := fbMessageQueue; END_IF // MQTT 客户端必须循环触发 fbMqttClient.Execute(bConnect); ``` 结果一样 :(
【解决方案3】:

它对我有用,我正在使用您的相同代码。 仔细检查您的 mqtt 许可证并确保它没有过期。

Screenshot of my connection to public server with your code

【讨论】:

  • 如何查看我的 mqtt 许可证?
  • 在您的解决方案资源管理器中:检查系统 -> 许可证 -> 管理许可证 -> TF6701 Tc3IoT 通信并激活配置。
  • 我有这些许可证:TC3 IoT MQTT Protocol、TC3 ADS、TC3 IO、TC3 PLC、TC3 IoT Communication (MQTT)、TC3 IoT Communication (I/O)、TC3 IoT Functions 和 TC3 IoT沟通者
  • 检查系统 -> 许可证 -> 订单信息下的状态。如果当前状态为“缺失”,请重新激活配置。
  • 什么都没有,所有的许可证都被激活了
【解决方案4】:

问题是服务器上的防火墙,问题已解决。我仍然无法连接公共 MQTT 代理,但我可以连接服务器上我自己的 MQTT 代理,这正是我真正想要的 :)。

【讨论】:

    【解决方案5】:

    我的问题是由于安装了鱿鱼。我是为另一个项目安装的。也许防火墙会导致这样的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多