mqtt 参考:

https://pypi.org/project/paho-mqtt/

https://github.com/eclipse/paho.mqtt.python

#服务端

[root@localhost ~]# cat mqtt_server.py

import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish idx = 0 #往paho/temperature 一直发送内容
while True:
print("send success")
publish.single("paho/temperature",
payload="this is message:%s"%idx,
hostname="iot.eclipse.org",
client_id="lora1",
# qos = 0,
# tls=tls,
port=1883,
protocol=mqtt.MQTTv311)
idx += 1

#客户端

[root@localhost ~]# cat mqtt_client.py

import paho.mqtt.client as mqtt

# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc)) # The callback for when a PUBLISH message is received from the server.
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.connect("iot.eclipse.org", 1883, 60) #订阅频道
client.subscribe("paho/temperature") # Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
client.loop_forever()

#启动服务端,再启动客户端

#服务端一直发送信息
[root@localhost ~]# python3 mqtt_server.py
send success
send success
send success
send success
send success
send success
send success
send success
send success
send success
send success #客户端接收信息
[root@localhost ~]# python3 mqtt_client.py
Connected with result code 0
paho/temperature b'this is message:125'
paho/temperature b'this is message:126'
paho/temperature b'this is message:127'
paho/temperature b'this is message:128'
paho/temperature b'this is message:129'
paho/temperature b'this is message:130'

备注:

MQTT服务器不负责存储数据,需要编写额外的接收客户端来接收数据、分析、入库等。

MQTT服务器用的是iot.eclipse.org,如果碰巧两个人在用同一个频道,那可能收到别人的消息哦~

搭建mqtt服务器

参考:

http://emqtt.com/docs/v2/install.html

https://blog.csdn.net/qq_37258787/article/details/79776663

二、Mosquitto安装和使用

https://lanseyujie.com/post/mosquitto-installation-and-usage.html

三、安装mqttfx(用于测试mqtt-服务器)

相当于部署一个mqtt-server

软件下载:

http://www.jensd.de/apps/mqttfx/1.7.0/

使用方法参考:

https://blog.csdn.net/nicholaszao/article/details/79211965

 

paho-mqtt的更多相关文章

  1. Paho - MQTT C Cient的实现

    来自我的CSDN博客   在前几天,我大致了解了一下Paho C项目,并对其的一些内容进行了翻译.俗话说,光说不练假把戏,今天就给大家讲一下使用Paho的客户端库文件实现MQTT C Client的过 ...

  2. [3] MQTT,mosquitto,Eclipse Paho---怎样使用 Eclipse Paho MQTT工具来发送订阅MQTT消息?

    在上两节,笔者主要介绍了 MQTT,mosquitto,Eclipse Paho的基本概念已经怎样安装mosquitto. 在这个章节我们就来看看怎样用 Eclipse Paho MQTT工具来发送接 ...

  3. vc2015编译paho.mqtt.c-1.1.0

    vc2015打开“\paho.mqtt.c-1.1.0\Windows Build\Paho C MQTT APIs.sln” 将文件“\paho.mqtt.c-1.1.0\src\VersionIn ...

  4. paho.mqtt.embedded-c MQTTPacket transport.c hacking

    /******************************************************************************* * paho.mqtt.embedde ...

  5. paho.mqtt.embedded-c MQTTPacket pub0sub1.c hacking

    /******************************************************************************* * paho.mqtt.embedde ...

  6. paho.mqtt.c打印日志

    mqtt中自身就带有日志系统Log.h和Log.c,这些日志文件是在客户端调用MQTTClient_create函数是初始化的,MQTTClient_create源码如下: int MQTTClien ...

  7. Eclipse Paho MQTT Utility

    下载地址: https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org.eclipse.paho. ...

  8. 3.MQTT paho

    一.概述 遥测传输 (MQTT) 是轻量级基于代理的发布/订阅的消息传输协议,设计思想是开放.简单.轻量.易于实现.这些特点使它适用于受限环境.例如,但不仅限于此: 网络代价昂贵,带宽低.不可靠. 在 ...

  9. Paho -物联网 MQTT C Cient的实现和详解

    概述   在文章Paho - MQTT C Cient的实现中,我介绍了如何使用Paho开源项目创建MQTTClient_pulish客户端.但只是简单的介绍了使用方法,而且客户端的结果与之前介绍的并 ...

  10. MQTT和paho(一)

    参考链接:http://blog.csdn.net/yangzl2008/article/details/8861069 一.mqtt 1.简单介绍 http://mqtt.org/software ...

随机推荐

  1. WordPress多本小说主题–WNovel主题发布,十分钟搭建小说站! 现已更新至1.2版本

    本文属于<WNovel主题操作手册>文章系列,该系列共包括以下 8 部分: WNovel主题使用手册之–主题安装及更新教程 WNovel主题使用手册之–小说管理 WNovel主题使用手册之 ...

  2. 【bzoj2694】Lcm 莫比乌斯反演+线性筛

    题目描述 求$\sum\limits_{i=1}^n\sum\limits_{j=1}^m|\mu(gcd(i,j))|lcm(i,j)$,即$gcd(i,j)$不存在平方因子的$lcm(i,j)$之 ...

  3. VMware ESXI 5.5 注册码

    VMware ESXI 5.5 注册码 ESXI 注册码0A42V-8M182-3ZZ88-R21N6-32K5H ESXi Server许可证类型产品: Mware vSphere 5 Enterp ...

  4. BZOJ 3223 Tyvj 1729 文艺平衡树 | Splay 维护序列关系

    题解: 每次reverse(l,r) 把l-1转到根,r+1变成他的右儿子,给r+1的左儿子打个标记就是一次反转操作了 每次find和dfs输出的时候下放标记,把左儿子和右儿子换一下 记得建树的时候建 ...

  5. vue虚拟dom原理

    Virual DOM是用JS对象记录一个dom节点的副本,当dom发生更改时候,先用虚拟dom进行diff,算出最小差异,然后再修改真实dom. vue的virtual dom的diff算法是基于sn ...

  6. let与const区别

    let 1. let有变量提升,但是有约束 2. 会形成暂时性死区(TDZ) 3. 同一个块级作用域内不允许声明相同变量 4. 块级变量 5. let声明的全局变量不是全局对象的属性,var会 6. ...

  7. 从零开始--Spring项目整合(1)使用maven框架搭建项目

    这些年一直在用spring的框架搭建项目,现在开始我们从零开始利用Spring框架来搭建项目,目前我能想到有Spring.SpringMVC.SpringJDBC.Mybatis.WebSockt.R ...

  8. [bzoj2111][ZJOI2010]Perm 排列计数 ——问题转换,建立数学模型

    题目大意 称一个1,2,...,N的排列P1,P2...,Pn是Magic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Magic的,答案可能很 ...

  9. android上USB Wifi调试记录

    https://wenku.baidu.com/view/cc3098c72f60ddccdb38a043.html?from=search

  10. docker 解决:Get http:///var/run/docker.sock/v1.19/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?

    docker 安装之后,通过命令查看docker相关信息时,可能会出现错误:Get http:///var/run/docker.sock/v1.19/version: dial unix /var/ ...