导航:首页 > IDC知识 > mqtt服务器

mqtt服务器

发布时间:2020-09-08 14:47:45

1、mqtt服务器用哪一个好

^

2、怎么将消息发送到mqtt代理服务器

通过Cocoa Pods添加MQTTKit

MQTTKit在github上链接https://github.com/NormanLeeIOS/MQTTKit#send-a-message,down下来。

cd到工程目录,输入pod install,用xcode打开工程的打开xcworkspace扩展名的文件。

如果不是MQTTKit存在更新的版本,则输入pod update。

新建一个MQTT的服务请求

NSString *clientID = ...
MQTTClient *client = [[MQTTClient alloc] initWithClientId:clientID];

发送消息,每次发送消息包括目标host和本地MQTT消息.具体MQTT格式消息见代码。这里Host可以是Server的IP,不需要host表解析。

// connect to the MQTT server
[self.client connectToHost:@"iot.eclipse.org"
completionHandler:^(NSUInteger code) {
if (code == ConnectionAccepted) {
// when the client is connected, send a MQTT message
[self.client publishString:@"Hello, MQTT"
toTopic:@"/MQTTKit/example"
withQos:AtMostOnce
retain:NO
completionHandler:^(int mid) {
NSLog(@"message has been delivered");
}];
}
}];

订阅主题并接受MQTT格式的消息,这部分在viewdidload中实现。

// define the handler that will be called when MQTT messages are received by the client
[self.client setMessageHandler:^(MQTTMessage *message) {
NSString *text = [message.payloadString];
NSLog(@"received message %@", text);
}];

// connect the MQTT client
[self.client connectToHost:@"iot.eclipse.org"
completionHandler:^(MQTTConnectionReturnCode code) {
if (code == ConnectionAccepted) {
// when the client is connected, subscribe to the topic to receive message.
[self.client subscribe:@"/MQTTKit/example"
withCompletionHandler:nil];
}
}];

断开连接

[self.client :^(NSUInteger code) {
// The client is disconnected when this completion handler is called
NSLog(@"MQTT client is disconnected");
}];

整个连接建立、发送消息、接受消息、断开连接都是通过Block的消息机制来实现,因此需要对block有很好地理解。

3、嵌入式终端可以作为 MQTT服务器 吗

可以,但是你需要一个公网IP,一般终端是没有公网IP的,除非当成二道贩子,用公网IP服务器进行转发

4、php适合做MQTT服务器吗

Apache-Apollo:一个代理服务器,在ActiveMQ基础上发展而来,可以支持STOMP、AMQP、MQTT、Openwire、SSL和WebSockets等多种协议,并且Apollo提供后台管理页面,方便开发者管理和调试。
EMQ:EMQ 2.0,号称百万级开源MQTT消息服务器,基于Erlang/OTP语言平台开发,支持大规模连接和分布式集群,发布订阅模式的开源MQTT消息服务器。
HiveMQ:一个企业级的MQTT代理,主要用于企业和新兴的机器到机器M2M通讯和内部传输,最大程度的满足可伸缩性、易管理和安全特性,提供免费的个人版。HiveMQ提供了开源的插件开发包。
Mosquitto:一款实现了消息推送协议MQTT v3.1的开源消息代理软件,提供轻量级的、支持可发布/可订阅的消息推送模式。

5、如何判断mqtt服务器是否正常

windows的平台 由于有32位的 也有64位的 所以 去下一个和自己的电脑 相区配的。
下载后直接双击安装就行 之后 进入安装目录 最好用命令行的方式 启动mosquitto.exe 然后就是 编写 android 客户端代码 mqtt 是订阅/发布的方式 eoeandroid 安卓开发社区上有详细的教程,你自己可以找一下。。

6、设备将数据发送到MQTT服务器,那服务器怎么数据转发到后台系统?

网上有很多的实际案例,多看几个就明白了,比如这个:

7、如何设置mqtt服务器的账号密码

Mosquitto用户认证配置
前言:基于Mosquitto服务器已经搭建成功,大部分都是采用默认的是允许匿名用户登录模式,正式上线的系统需要进行用户认证。
1.用户参数说明
Mosquitto服务器的配置文件为/etc/mosquitto/mosquitto.conf,关于用户认证的方式和读取的配置都在这个文件中进行配置。
allow_anonymous允许匿名
password_file密码文件
acl_file访问控制列表

# 不允许匿名
allow_anonymous false

# 配置用户密码文件
password_file /etc/mosquitto/pwfile

# 配置topic和用户
acl_file /etc/mosquitto/acl

2.添加用户信息
添加用户'chisj'密码’chisj‘,
#mosquitto_passwd -c /etc/mosquitto/pwfile chisj

3.添加Topic和用户的关系

4.用户认证测试
重启Mosquitto
通过Ctrl+C关闭mosquitto,然后通过下面命令启动Mosquitto
# mosquitto-c /etc/mosquitto/mosquitto.conf

(订阅端)客户端启动:

#mosquitto_sub -h 192.168.1.100 -t mtopic -u chisj -P chisj

(发布者)客户端启动:
#mosquitto_pub -h 192.168.1.100 -t mtopic -u chisj -P chisj -m "test"

与mqtt服务器相关的知识