mqtt

Python MQTT connection to Azure Iot Hub

假如想象 提交于 2019-11-28 06:19:32
问题 I want to connect to Azure Iot Hub, with Python MQTT. An username and SAS token is required by Iot Hub. This is my code: import paho.mqtt.client as mqtt def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) client.subscribe("$SYS/#") def on_message(client, userdata, msg): print(msg.topic+" "+str(msg.payload)) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.username_pw_set("myHub.azure-devices.net/device1",

How to Find Connected MQTT Client Details

我是研究僧i 提交于 2019-11-28 06:02:31
Is there any way we can find about all the connected client details(IP & name) from another client? I know there is a topic "$SYS/broker/clients/active" which gives the number of currently connected clients but if I want to know more about each connected client, is there any way? I'm developing a solution where number of client will be connected (using Wireless network) to MQTT broker located on a server. I will also have another client running on the same machine and connected to the broker which will observe if any new client connected with the broker or for a gets disconnected client. I can

基于 PostgreSQL 的 EMQ X Auth & ACL

一曲冷凌霜 提交于 2019-11-28 05:40:32
在阅读本教程之前,假定你已经了解 MQTT 、 MQTT 5 以及 EMQ X 的简单知识。 emqx-auth-pgsql 它通过检查每个终端接入的 username 和 password 是否与用户指定 的 PostgreSQL 数据库中存储的信息一致来实现对终端的访问控制。其功能逻辑如下: 本文假设 PostgreSQL 已经安装在您的机器上,并且您可以连接到 PostgreSQL 服务器。 插件配置项说明 配置项 说明 auth.pgsql.server 配置需要连接的 PostgreSQL Server 的 host 与 port,格式为:host[:port],省略后面的 port 时表示使用默认的 5432 端口 auth.pgsql.username 用于登录 PostgreSQL 的用户名 auth.pgsql.password 用于登录 PostgreSQL 的密码 auth.pgsql.database 配置要访问的数据库 auth.pgsql.ssl 配置是否使用 SSL 连接数据库,默认为否 auth.pgsql.auth_query 配置从数据库中查找用户名对应密码的 SQL 语句 auth.pgsql.password_hash 表示存储在数据表中的 encrypted password 使用的加密算法和加盐方式 auth.pgsql.super

Read .db file in Mosquitto

好久不见. 提交于 2019-11-28 04:46:08
问题 I'm using Mosquitto Project (http://mosquitto.org), this is my mosquitto.conf persistence_file mosquitto.db persistence_location C:/var/lib/mosquitto/ After running, I have got mosquitto.db, but I can't open it. I'm trying open with Microsoft Excel, sqlitebrowser_200_b1_win but it's not working. Please help me. Thanks in advance 回答1: I just answered this same question on the mosquitto answers tracker: https://answers.launchpad.net/mosquitto/+question/217523 The mosquitto.db file holds

Is there a way to store Mosquitto payload into an MySQL database for history purpose?

廉价感情. 提交于 2019-11-28 01:25:29
I am using Mosquitto MQTT broker and I would like to store every published message into a MySQL database without creating a client and subscribing to # wildcard. I found this https://github.com/jpmens/mosquitto-auth-plug but my english is not good enough to understand it thoroughly... I think it is only to store persistent message for the broker to resend them later. Am I right ? Thanks The mosquitto-auth-plugin uses the database to store username/password and ACL information, not message content. Writing some code to store messages in a database from any MQTT broker is relatively simple.

Python实现MQTT接收订阅数据

*爱你&永不变心* 提交于 2019-11-28 01:11:45
一、背景 目前MQTT的标准组织官网: http://www.mqtt.org ,里面列出了很多支持的软件相关资源。 一个轻量级的MQTT服务器是: http://www.mosquitto.org ,可以运行ARM/MIPS的嵌入式linux系统上。 物联网常使用 “消息队列遥测传输(Message Queuing Telemetry Transport, MQTT)” 协议订阅数据,这里用Python实现从MQTT服务器订阅数据。 首先和TCP协议比较 首先TCP是传输层协议,实现了一个双向的通信链路。 MQTT是基于TCP的应用层协议。(当然中间可能多一层,websocket) 两者不在一个层级,比较谁比谁好是没有意义的。 我们用raw TCP 也可以实现数据通信,比如发送传感器数据到服务器。为什么要用到MQTT呢 ? 假设现在有一个物联网的应用,题主当然可以直接用TCP socket 做通信,实际上不少人也是这么做的。然后你就会发现: 需要自己写确认重传的机制,因为TCP 连接说不定就断了。 如果有很多个传感器(生产者),又要写代码管理这么多TCP连接呢。 如果同时又有多个地方需要用到这些数据,还得写一个转发的逻辑。 如果系统很复杂,参与人或公司很多,那通信格式要怎么定,怎么改,沟通成本就很大了。 这些东西这么麻烦,又不想加班写代码,那有没有办法简便地解决呢?当然有

MQTT协议(一)

旧时模样 提交于 2019-11-27 18:44:09
一、 MQTT 简介 MQTT 协议( Message Queuing Telemetry Transport )(消息队列遥测传输)是一种基于发布 / 订阅 模式 的 “轻量级”消息协议,是 IBM 公司于 1999 年提出的,由 Andy Stanford-Clark ( IBM )和 Arlen Nipper ( Eurotech ,现为 Cirrus Link )于 1999 年开发 。 MQTT 是一个基于 TCP 的发布订阅协议,设计的初始目的是为了 适用于极有限的内存设备和低带宽的不可靠网络 通信,非常适合物联网通信。 MQTT 协议目前在 IoT ( Internet of things ,物联网)、小型设备应用、移动应用等方面有较广泛的应用。 二、协议原理 与 HTTP 及其请求 / 响应范例相比, MQTT 协议使用发布 / 订阅体系结构。发布 / 订阅是事件驱动的,可以将消息推送到客户端。中央通信点是 MQTT 代理,它负责调度发送者和合法接收者之间的所有消息。向代理发布消息的每个客户端都在消息中包含一个主题。主题是代理的路由信息。每个想要接收消息的客户端都订阅某个主题,并且代理将具有匹配主题的所有消息传递给客户端。 MQTT 协议提供一对多的消息发布,可以解除应用程序耦合,信息冗余小。该协议需要客户端和服务端,而协议中主要有三种身份:发布者(

mosquitto MQTT broker and Java client with SSL / TLS

心已入冬 提交于 2019-11-27 14:15:28
问题 I'm using mosquitto and the Eclipse PAHO Java client. Everything is working fine on plain TCP sockets. but now I want to use SSL for athentication (encryption not necessarily needed). first I followed the instructions from http://mosquitto.org/man/mosquitto-tls-7.html in mosquitto client I can not publish my message without the --insecure option, means i have to mosquitto_pub -h <server-ip> -p <port> -t "/topic1/test" -m "testmsg" --cafile ca_cert.pem --cert client.crt --key client_priv.key -

自己动手实现MQTT协议

ぃ、小莉子 提交于 2019-11-27 10:50:41
写在前面 前段时间弄IoT相关的东西,系统学习了一下 MQTT 协议,在此分享出来。 本文先是对 MQTT 协议做了简单的介绍;接着是对 MQTT协议的内容做了较为全面的解读;最后使用 Python 语言去实现一个简单的 MQTT 客户端和服务器。 简介 MQTT 全称是 Message Queue Telemetry Transport,翻译成中文意思是“遥测传输协议”。它最先是由IBM提出,是一种基于 TCP 协议,具有简单、轻量等优点,特别适合于受限环境(带宽低、网络延迟高、网络通信不稳定)的消息分发。MQTT 协议有 3.x, 5.x 等多个版本,目前最常用的版本是 v3.1.1 ,本文也是对此版本的协议进行的解读。MQTT 协议已纳入ISO标准 (ISO/IEC PRF 20922),现今主流的 IoT 平台都支持该协议。 PS: 更详细的信息可参考 Wikipedia 和 MQTT 官网 快速开始 MQTT 是一种 发布-订阅 协议,这意味着: 客户端(Client) 可以向 服务端(Broker) 订阅(Subscribe) 自己感兴趣的 主题(Topic) ; 客户端还可以向服务端 发布(Publish) 关于某个主题的信息(主题不需要提前创建,发布消息时指定即可); 服务端在收到客户端发布的消息后,会将该消息转发给订阅了该主题的其他客户端。

从零开始实现一个IDL+RPC框架

别来无恙 提交于 2019-11-27 10:21:43
一、RPC是什么 在很久之前的单机时代,一台电脑中跑着多个进程,进程之间没有交流各干各的,就这样过了很多年。突然有一天有了新需求,A进程需要实现一个画图的功能,恰好邻居B进程已经有了这个功能,偷懒的程序员C想出了一个办法:A进程调B进程的画图功能。于是出现了IPC(Inter-process communication,进程间通信)。就这样程序员C愉快的去吃早餐去了! 又过了几年,到了互联网时代,每个电脑都实现了互联互通。这时候雇主又有了新需求,当时还没挂的A进程需要实现使用tensorflow识别出笑脸 >_< 。说巧不巧,远在几千里的一台快速运行的电脑上已经实现了这个功能,睡眼惺忪的程序媛D接手了这个A进程后借鉴之前IPC的实现,把IPC扩展到了互联网上,这就是RPC(Remote Procedure Call,远程过程调用)。RPC其实就是一台电脑上的进程调用另外一台电脑上的进程的工具。成熟的RPC方案大多数会具备服务注册、服务发现、熔断降级和限流等机制。目前市面上的RPC已经有很多成熟的了,比如Facebook家的Thrift、Google家的gRPC、阿里家的Dubbo和蚂蚁家的SOFA。 二、接口定义语言 接口定义语言,简称IDL,是实现端对端之间可靠通讯的一套编码方案。这里有涉及到传输数据的序列化和反序列化,我们常用的http的请求一般用json当做序列化工具