Arduino 无法连接到MQTT服务器
我正在使用Knollery库将Arduino UNO板连接到MQTT服务器。对于broker,我使用test.mosquitto.org(85.119.83.194),但无法连接 这是我的密码:Arduino 无法连接到MQTT服务器,arduino,mqtt,Arduino,Mqtt,我正在使用Knollery库将Arduino UNO板连接到MQTT服务器。对于broker,我使用test.mosquitto.org(85.119.83.194),但无法连接 这是我的密码: /* Basic MQTT example - connects to an MQTT server - publishes "hello world" to the topic "outTopic" - subscribes to the topic "inTopic" */
/*
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>
// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
byte server[] = { 10, 2, 63, 123};
byte ip[] = { 85, 119, 83, 194 };
void callback(char* topic, byte* payload, unsigned int length) {
// handle message arrived
Serial.println("Message received");
}
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.subscribe("/notification/turnlighton");
}
else{
Serial.println("Client not connected");
}
}
void loop()
{
client.loop();
}
作为替代,我还尝试连接到intranet中的真正简单的MessageBroker(RSMB)。但我还是收到了同样的信息
这里有人能帮忙吗
提前谢谢
SRS你把它绕错了方向
byte server[]
是mqtt服务器的ip地址,在test.mosquitto.org(85.119.83.194)中
byte ip[]
是您希望arduino在网络上拥有的静态ip地址
要检查的另一件事是,您可以使用cli客户端连接到test.mosquito.org,因为我发现它有时会关闭
看看我的温度发布代码,它可能会给你一些提示,因为它是从PubSubClient附带的原始示例修改而来的。在我的示例中,arduino正在运行DHCP。我认为您需要交换服务器和ip值,反之亦然。服务器应该是MQTT代理的IP,IP应该是您的arduino IP地址我在交换后尝试过,仍然没有成功。我成功地运行了您的代码,只是调整了IP地址。正确的MOSQUITO地址是
服务器[]={8511983194}
(截至今天)。我的arduino IP是IP[]={192168,1177}
。你的家庭网络真的是10.2.63.123吗?使用10。地址空间绝对是个大问题。确保您的路由器认为LAN端地址是10.2.0.0/16或10.2.0.0/255.255.0.0,并且您显示的内容应该运行。检查其他正在工作的计算机,查看其IP设置情况。谢谢。我现在可以连接到85.119.83.194。但现在我面临另一个问题。当我在IP为192.168.1.2的笔记本电脑上安装代理时,我无法连接。@srshawk check firewall端口在1883年打开,并发布您的mosquitto.conf
文件。
byte server[] = { 10, 2, 63, 123};