我试图通过TLS 确保arduino pubsub客户端和mosquitto代理(在公共服务器上运行)之间的连接.
通常(在Windows等),我可以在给出证书文件的同时发布/订阅如下.(证书和密钥文件在我的工作目录中).
mosquitto_pub -h myhost.com -p 8883 -t "/test" -m "your secure message" --cafile ca.crt --cert client.crt --key client.key
mosquitto_sub -h myhost.com -p 8883 -t "/test" --cafile ca.crt --cert client.crt --key client.key
但有没有办法在arduino中做到这一点?
我的发布者和订阅者都连接到 QOS=2 的 mosquitto (paho) 代理,并通过 clean_session=false 维护持久会话。当我在订阅者连接到代理的情况下发布消息时,它成功地被订阅者接收,现在如果我断开订阅者,然后再次发布消息并连接订阅者,当我的订阅者离线时,我将能够检索这些消息。
我的问题是——
当订阅者离线时,代理中是否有任何存储空间来存储所有消息。
如果是,它可以存储多长时间或多少消息。
这种方法是否适用于实时 GPS 跟踪,其中订户可以离线很长时间(5-6 小时)约。
即使断电也能保持会话持久性。
如果我在实时 gps 跟踪中使用这种方法,它可以为可扩展应用程序处理多少流量..
我正在连接到mqtt,但收到一个无用的异常。
码
string smsTopic = ConfigurationManager.AppSettings["MQTT_SMS_Topic"];
string emailTopic = ConfigurationManager.AppSettings["MQTT_Email_Topic"];
string pushTopic = ConfigurationManager.AppSettings["MQTT_PUSH_Topic"];
string socialTopic = ConfigurationManager.AppSettings["MQTT_SOCIAL_Topic"];
client = new MqttClient("somehostname");
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
client.Subscribe(new string[] { smsTopic, emailTopic, pushTopic, socialTopic }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
Run Code Online (Sandbox Code Playgroud)
异常消息
引发了类型为'uPLibrary.Networking.M2Mqtt.Exceptions.MqttClientException'的异常
异常的堆栈跟踪
at uPLibrary.Networking.M2Mqtt.Messages.MqttMsgSubscribe.GetBytes(Byte protocolVersion) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\Messages\MqttMsgSubscribe.cs:line 187
at uPLibrary.Networking.M2Mqtt.MqttClient.Send(MqttMsgBase msg) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 1028
at uPLibrary.Networking.M2Mqtt.MqttClient.ProcessInflightThread() in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 1954
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, …Run Code Online (Sandbox Code Playgroud) 我正在为node.js使用mqtt客户端
在此链接https://blog.risingstack.com/getting-started-with-nodejs-and-mqtt/上,mqtt模块就像这样导入;
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://broker.hivemq.com')
Run Code Online (Sandbox Code Playgroud)
我进行模块导入的方式是这样的;
var mqtt = require('mqtt')
var client = mqtt.connect('mqtt://broker.hivemq.com')
Run Code Online (Sandbox Code Playgroud)
两种方式有什么区别,var和const?如果我这样导入怎么办?
let mqtt = require('mqtt')
let client = mqtt.connect('mqtt://broker.hivemq.com')
Run Code Online (Sandbox Code Playgroud)
有关系吗?哪种编程方式正确?
我正在使用node.js v6
目前,我们有一个通过MQTT控制多个设备的应用程序.每个设备都订阅一个以其设备ID命名的唯一主题.例如,设备A具有设备ID 123,因此它将订阅主题123.然后,如果应用想要将控制消息发布到设备A,则它将发布名为123的主题,这是设备A的设备ID.
通过这样做,如果我们有1000个设备,那么我们将有1000个主题.这是一个非常糟糕的设计.因此,我们可能会考虑通过设置将接收主题的客户端ID将主题发布到特定客户端,因为连接到代理的每个客户端都必须设置客户端ID.但是,我们没有找到任何允许发布到特定客户端的方法.似乎MQTT没有处理这样的事情.它只发布给订阅同一主题的客户.
那么,我们可以采取其他方式来实现一个主题,但仍然能够向特定客户发布消息吗?
谢谢!
假设我通过 MQTT 协议从许多设备接收信息,下图是一台设备块的简化版本:

device2因此,我们还假设所有其他设备都具有完全相同的图表,除了第二个设备、device3第三个设备等将更改的主题名称,如下所示:

问题是我想要一种在节点配置中更改名称的方法,而不必一个一个地进行。就像声明一个全局变量一样,它不仅可以在函数中使用,而且可以在节点本身中使用。例如,最后一张图片可以使用类似:MYVARIABLE_temperatureA和MYVARIABLE_temperatureB作为主题。
那么,是否可以使用 Node-RED 来做这样的事情呢?或者解决方案只是创建一个具有用于放置值的特定字段的自定义节点?
我最近一直在阅读有关这两个协议的内容,但不太明白为什么当我们有 MODBUS 时要使用 MQTT(反之亦然)。
因为,MODBUS 用于在低带宽下通过 PLC 之间的串行通信传输数据,但据我了解,MQTT 使用其发布/订阅方法执行相同的操作(我知道 MQTT 使用代理而 MODBUS 不使用,但事实并非如此)点)。
有人可以明确区分它们吗?
以下是我的代码,当我评论 statements-2 时,它符合罚款要求,但当我取消注释时,它会给出 Compile Time Error "Unreachable Code"。
我明白为什么我在取消注释后收到错误,但我的问题是,即使我注释它仍然bad()无法访问,因为我是throwing一个异常,那么为什么它没有给出错误?
class Varr
{
public static void main(String[] args) throws Exception
{
System.out.println("Main");
try {
good();
} catch (Exception e) {
System.out.println("Main catch");
//**Statement 1**
throw new RuntimeException("RE");
} finally {
System.out.println("Main Finally");
// **Statement 2**
throw new RuntimeException("RE2");
}
bad();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 TLS1.2 使用 Lets 加密证书来设置 mosquitto MQTT 服务器。
我已经安装了 mosquitto 并设置了 Let encrpypt。我的 /etc/mosquitto/conf.d/default.conf 是
listener 1883 localhost
listener 8883
certfile /etc/letsencrypt/live/mqtt.atom.net/cert.pem
cafile /etc/letsencrypt/live/mqtt.atom.net/chain.pem
keyfile /etc/letsencrypt/live/mqtt.atom.net/privkey.pem
Run Code Online (Sandbox Code Playgroud)
在服务器上运行 mosquitto 我可以成功发布和订阅消息
Sub
mosquitto_sub -h localhost -t test
hello
Pub
mosquitto_pub -h mqtt.atom.net -t test -m "hello" -p 8883 --capath /etc/ssl/certs/
Run Code Online (Sandbox Code Playgroud)
从互联网上的另一个系统(或 ESP32) - 尝试建立 TLS 连接时出现错误
mosquitto_pub -h mqtt.atom.net -t test -m "hello again" -p 8883
Error: The connection was lost.
Run Code Online (Sandbox Code Playgroud)
我需要将哪些文件/证书传递给 mosquitto_pub?