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. 【bzoj1195】[HNOI2006]最短母串 AC自动机+状态压缩+BFS最短路

    原文地址:http://www.cnblogs.com/GXZlegend/p/6825226.html 题目描述 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串 ...

  2. easyui中的依赖关系

    参考自:http://www.easyui.info/archives/765.html 在使用easyui的过程中发现各个组件直接存在依赖关系,也就是上层的复杂组件依赖于一个或者多个简单组件,复杂组 ...

  3. POJ2417 Discrete Logging | A,C互质的bsgs算法

    题目: 给出A,B,C 求最小的x使得Ax=B  (mod C) 题解: bsgs算法的模板题 bsgs 全称:Baby-step giant-step 把这种问题的规模降低到了sqrt(n)级别 首 ...

  4. 【POJ 2406 Power Strings】

    Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...

  5. .net yield return

    yield在迭代器块中用于向枚举数对象提供值或发出迭代结束信号.它的形式为下列之一: yield return <expression>; yield break; 计算表达式并以枚举数对 ...

  6. CString和string在unicode与非unicode下的相互转换(转)

    原文转自 http://blog.csdn.net/u014303844/article/details/51397556 CString和string在unicode与非unicode下的相互转换 ...

  7. Linux内核中的中断栈与内核栈的补充说明【转】

    转自:http://blog.chinaunix.net/uid-12461657-id-3487463.html 原文地址:Linux内核中的中断栈与内核栈的补充说明 作者:MagicBoy2010 ...

  8. 包嗅探和包回放简介-tcpdump,tcpreplay

    一.  嗅探 1.1  嗅探技术简介 1.1.1  目标 嗅探的目标:获取在网络上传输的各种有价值信息:账号.密码.非公开协议 1.1.2  原理 嗅探的原理:大多数嗅探都是在以太网内,利用数据链路层 ...

  9. zabbix ssh登录ip监控,登录ip归属地查询

    #!/usr/local/zabbix/scripts/src/bin/python # -*- coding: UTF-8 -*- from bs4 import BeautifulSoup as ...

  10. 7.添加OpenStack计算服务

    添加计算服务 安装和配置控制器节点 创建数据库 mysql -uroot -ptoyo123 CREATE DATABASE nova; GRANT ALL PRIVILEGES ON nova.* ...