【问题标题】:mqtt broker windows with arduino client带有 arduino 客户端的 mqtt 代理窗口
【发布时间】:2015-05-13 13:58:08
【问题描述】:

大家好,我有一个问题,我无法通过以太网屏蔽与 arduino-uno 客户端在我的计算机(windows 7 x64)上通信 MQTT 代理(mosquitto),我已经从 knolleary 安装了 PubSubClient 库并导入它到我的 arduino IDE,这是我的代码源:

 /*
  Basic MQTT example

  - connects to an MQTT server
  - publishes "hello world" to the topic "outTopic"
  - subscribes to the topic "inTopic"
 */


 #include <SPI.h>
 #include <Ethernet.h>
 #include <PubSubClient.h>

 int ledPin = 5;


// Update these with values suitable for your network.
byte mac[]    = { 0x74,0xD0,0x2B,0xEC,0xC3,0xEE };
//@ mac of the arduino in my computer
byte server[] = {192,168,1,4};
//the ip @ of the broker installed in mylocalhost
byte ip[] = {192.168.1.25};
//ip @ of the arduino in my computer



void callback(char* topic, byte* payload, unsigned int length) {
// handle message arrived
Serial.print(topic);

}


EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);


void setup()
{
Ethernet.begin(mac,ip);
Serial.begin(9600);
Serial.println("Ethernet Begin");
if (client.connect("arduinoClient")) {
Serial.println("Client connected");
//client.publish("outTopic","hello world");
//client.subscribe("inTopic");
}
else{
      Serial.println("Client not connected"); 
}
}


void loop()
 {
  client.loop();
 }

运行此代码后,显示“Ethernet Begin”和“Client not connected”,我不知道问题出在哪里以及如何解决。 提前致谢;

【问题讨论】:

  • 您的 Arduino 和 Win 计算机真的在不同的子网上吗?导致服务器和 Arduino IP 看起来很奇怪。
  • 你能从 Win 电脑 PING 你的 Arduino 吗?
  • 嗨@MichalFoksa,问题是通过更改我的arduino 的id 地址来解决的,但是arduino 客户端上的mqtt 库中的当前问题,因为发布方法很好,但订阅没有你有关于这个的想法??
  • 这个问题中提到的代码已经解决了stackoverflow.com/questions/29740560/…,除了我的回答中解决的网络问题。尝试结合它。
  • 嗨@MichalFoksa,这并不能解决我的问题,我想在我的arduino上订阅主题并从安装在树莓派上的蚊子经纪人那里收到消息,但它仍然是错误的,我想在其中运行此指令我的覆盆子: mosquitto_pub -t inTopic -m test -h 192.168.1.25 (这是arduino的IP地址)。所以我运行这个后没有结果只是“错误:连接超时”,请问是什么问题

标签: ethernet mqtt arduino-uno mosquitto


【解决方案1】:

没有和 Ardino 合作过,但是 您是否关闭了运行代理的 Win7 计算机上的防火墙,它可能拒绝端口 1883。

https://github.com/francoisvdm/TT3 是一个很好的 mqtt 客户端,用于测试代理是否在另一台 windows 计算机上工作。

【讨论】:

  • 问题是通过更改我的arduino 的id 地址来解决的,但是arduino 客户端上的mqtt 库中的当前问题,因为发布方法很好但是订阅没有你对此有什么想法吗? ?
【解决方案2】:

问题已解决,因为当我使用我的 arduino 客户端连接到代理时,我打开了与安装在我的树莓派上的代理的会话,因此发布到 arduino 订阅的主题非常简单,只需像这样在代理中运行此命令: mosquitto_pub -t inTopic -m 测试;没有 -h 192.168.1.25 并且效果很好,最后非常感谢@Michal Foska

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 2018-10-18
    相关资源
    最近更新 更多