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. mssql 格式化字符串 /时间 年月日时分秒

    比如:1 想格式化 000001,100 格式化为000100: 思路是这样的 1000000 +格式化的数字 取后6位: select   right(cast(power(10,6) as var ...

  2. Axios & fetch api & Promise & POST

    Axios & fetch api & Promise & POST https://github.com/axios/axios https://appdividend.co ...

  3. apache+mysql+php实现最大负载的方法

    1. 生成静态html页面,squid反向代理,apache,MySQL的负载均衡. 2. 可以采取数据缓存的方法,我们通常在统计数据的时候,需要在原始数据的基础上经过计算等一系列操作,才会得到最终的 ...

  4. 《c程序设计语言》-3.1 判断语句多少影响时间

    #include <stdio.h> #define Num 1000000 /* int binsearch(int x,int v[],int n) { int low,high,mi ...

  5. js中哪些语句在if语句中默认为真

    结论:js中有一个函数是:Boolean(value)这个函数把一个value值转换成相应的boolean值. 当value为以下值是为true:1.任意的非空字符串 .2.任意的非0数字 而当val ...

  6. Windows转移FSMO角色

    转移 FSMO 角色若要使用 Ntdsutil 实用工具转移 FSMO 角色,请按照下列步骤操作:1.登录到基于 Windows 2000 Server 或基于 Windows Server 2003 ...

  7. [Usaco2005 dec]Layout

    题目描述 当排队等候喂食时,奶牛喜欢和它们的朋友站得靠近些.FJ有N(2<=N<=1000)头奶牛,编号从1到N,沿一条直线站着等候喂食.奶牛排在队伍中的顺序和它们的编号是相同的.因为奶牛 ...

  8. BeeUISignal详解

    https://github.com/i5ting/Bee_Tutorial/wiki/BeeUISignal%E8%AF%A6%E8%A7%A3 BeeUISignal是beeframework的核 ...

  9. 1.Centos-Docker安装和使用

    1.安装docker yum install -y epel-release yum install -y docker-io 如果需要安装最新的docker,最好将系统升级到最新版 yum inst ...

  10. PHP 时间获取本周 本月 本季度用法

    <?php        $week_begin = mktime(0, 0, 0,date("m"),date("d")-date("w&qu ...