paho-mqtt
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的更多相关文章
- Paho - MQTT C Cient的实现
来自我的CSDN博客 在前几天,我大致了解了一下Paho C项目,并对其的一些内容进行了翻译.俗话说,光说不练假把戏,今天就给大家讲一下使用Paho的客户端库文件实现MQTT C Client的过 ...
- [3] MQTT,mosquitto,Eclipse Paho---怎样使用 Eclipse Paho MQTT工具来发送订阅MQTT消息?
在上两节,笔者主要介绍了 MQTT,mosquitto,Eclipse Paho的基本概念已经怎样安装mosquitto. 在这个章节我们就来看看怎样用 Eclipse Paho MQTT工具来发送接 ...
- 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 ...
- paho.mqtt.embedded-c MQTTPacket transport.c hacking
/******************************************************************************* * paho.mqtt.embedde ...
- paho.mqtt.embedded-c MQTTPacket pub0sub1.c hacking
/******************************************************************************* * paho.mqtt.embedde ...
- paho.mqtt.c打印日志
mqtt中自身就带有日志系统Log.h和Log.c,这些日志文件是在客户端调用MQTTClient_create函数是初始化的,MQTTClient_create源码如下: int MQTTClien ...
- Eclipse Paho MQTT Utility
下载地址: https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org.eclipse.paho. ...
- 3.MQTT paho
一.概述 遥测传输 (MQTT) 是轻量级基于代理的发布/订阅的消息传输协议,设计思想是开放.简单.轻量.易于实现.这些特点使它适用于受限环境.例如,但不仅限于此: 网络代价昂贵,带宽低.不可靠. 在 ...
- Paho -物联网 MQTT C Cient的实现和详解
概述 在文章Paho - MQTT C Cient的实现中,我介绍了如何使用Paho开源项目创建MQTTClient_pulish客户端.但只是简单的介绍了使用方法,而且客户端的结果与之前介绍的并 ...
- MQTT和paho(一)
参考链接:http://blog.csdn.net/yangzl2008/article/details/8861069 一.mqtt 1.简单介绍 http://mqtt.org/software ...
随机推荐
- javascript replace 替换全部字符
$("#pageNote").html($("#note3").val().replace(/ /g, "").replace(/<b ...
- 利用VS2013 XSLT对 XML进行转换
1.打开VS2013 2.文件-->新建-->文件-->XML文件 3.文件-->新建-->文件-->XSLT文件 4.CTRL+SHIFT+S 保存2个文件位置 ...
- [hdu6428]Problem C. Calculate
题目大意:有$T(1\leqslant T\leqslant 10)$组数据,每组数据给你$A,B,C(0<A,B,C\leqslant 10^7)$,求$\sum\limits_{i=1}^A ...
- 真·APIO2018滚粗记
有人说只有大佬才会说滚粗啊爆零啊…… 然而我真滚粗真爆零啊…… D1: 听课,然后夏眠. 咦折纸……哦好吧太神仙了. 咦AI……好妙啊好妙啊. 咦二分……哇还有wqs二分这种神奇操作,学学学. (我是 ...
- 《R语言实战》读书笔记--第三章 图形初阶(一)
3.1使用图形 可以使用pdf等函数将图形直接保存在文件中.在运用attach和detach函数的使用中经常出现错误,比如命名重复的问题,所以,应该尽量避免使用这两个函数. plot是一般的画图函数, ...
- CSU 2130~湖南多校对抗第八场 C
2130: Permutations Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: ...
- 适配器模式 & 装饰器模式
一.适配器模式:简单来讲,就是为了方便使用,完成从 一个接口 到 另一个接口 的 转换,这个负责转换的就是 适配器例如:Reader ——> InputStreamReader 通过类内部组合 ...
- 使用 WideCharToMultiByte Unicode 与 UTF-8互转
1.简述 最近在发送网络请求时遇到了中文字符乱码的问题,在代码中调试字符正常,用抓包工具抓的包中文字符显示正常,就是发送到服务器就显示乱码了,那就要将客户端和服务器设置统一的编码(UTF-8),而我们 ...
- 【linux高级程序设计】(第十一章)System V进程间通信 2
消息队列 消息队列是消息的链式队列,模型如下: 包括两种数据结构: msqid_ds消息队列数据结构 msg消息队列数据结构 struct msg_msg{ struct list_head m_li ...
- The Problem to Slow Down You(Palindromic Tree)
题目链接:http://codeforces.com/gym/100548 今天晚上突然有了些兴致去学习一下数据结构,然后就各种无意中看到了Palindrome Tree的数据结构,据说是2014年新 ...