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. NetScaler Active-Active模式

    NetScaler Active-Active模式 NetScaler Active-Active模式 (此文档基于版本:NS9.3: Build 55.6 nc) By ShingTan Activ ...

  2. bzoj2178:圆的面积并

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=2178 sol  :是谁.......是谁往题里下毒...... 辛普森积分,每次判断左边+右边 ...

  3. java.net.BindException: Address already in use: JVM_Bind <null>:8080错误

    今天打开myeclipse出现java.net.BindException: Address already in use: JVM_Bind <null>:8080错误 从网上搜了一下大 ...

  4. font-family 定义的最后为什么要加一句sans-serif

    定义font-family时,最好在最后加一个sans-serif,这样如果所列出的字体都不能用,则默认的sans-serif字体能保证调用; W3C建议字体定义的时候,最后以一个类别的字体结束,例如 ...

  5. PriorityQueue详解(一)

    在Java SE 5.0中,引入了一些新的Collection API,PriorityQueue就是其中的一个.今天由于机缘巧合,花了一个小时看了一下这个类的内部实现,代码很有点意思,所以写下来跟大 ...

  6. 厌倦了ListBox打印消息,使用RichTextBox试试吧

    背景 Winform打印后台线程运行时消息,习惯用ListBox,有时候某行消息过长,设置个Tooltip控件提示全部信息.后来无意中看到同事使用RichTextBox打印消息,然后在不同的消息类别上 ...

  7. 网站开发只需数小时?Meteor 说这才是未来

    原文: http://www.geekpark.net/topics/211573/ 那个想要挑战过去数十年沿用至今的网站开发模式的新势力来了. Meteor 是从 YC 孵化而出的现代网站开发平台, ...

  8. chanme的博客搬家了!

    一直以来都想自己租一台服务器,买个域名做一个自己的博客,但是由于时间和知识的关系,以前还不太知道怎么搭一个博客.终于我在上个礼拜成功的迈出了建站的第一步,然后陆陆续续的也将一些后续的步骤做好了.所以今 ...

  9. appium+python自动化24-滑动方法封装(swipe)【转载】

    swipe介绍 1.查看源码语法,起点和终点四个坐标参数,duration是滑动屏幕持续的时间,时间越短速度越快.默认为None可不填,一般设置500-1000毫秒比较合适. swipe(self, ...

  10. Jquery实现下拉列表左右选择

    知识点: jquery  的 click dbclick  事件  appendTo方法 <!DOCTYPE html> <html> <head> <met ...