Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Eclipse Foundation
paho.mqtt.python
提交
33b7c95d
P
paho.mqtt.python
项目概览
镜像
/
Eclipse Foundation
/
paho.mqtt.python
11 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
paho.mqtt.python
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
33b7c95d
编写于
9月 09, 2016
作者:
J
James Myatt
提交者:
Roger Light
9月 09, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update examples added since PR#98 (#109)
Signed-off-by:
N
James Myatt
<
james@jamesmyatt.co.uk
>
上级
79331252
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
61 deletion
+32
-61
examples/client_logger.py
examples/client_logger.py
+7
-21
examples/client_pub-wait.py
examples/client_pub-wait.py
+15
-22
examples/client_session_present.py
examples/client_session_present.py
+10
-18
未找到文件。
examples/logger.py
→
examples/
client_
logger.py
浏览文件 @
33b7c95d
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2016 James Myatt <james@jamesmyatt.co.uk>
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Distribution License v1.0
# which accompanies this distribution.
# which accompanies this distribution.
#
# The Eclipse Distribution License is available at
# The Eclipse Distribution License is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# Contributors:
# James Myatt - initial implementation
# This shows a simple example of standard logging with an MQTT subscriber.
# This shows a simple example of standard logging with an MQTT subscriber
client
.
import
sys
import
logging
try
:
import
paho.mqtt.client
as
mqtt
except
ImportError
:
# This part is only required to run the example from within the examples
# directory when the module itself is not installed.
#
# If you have the module installed, just use "import paho.mqtt.client"
import
os
import
inspect
cmd_subfolder
=
os
.
path
.
realpath
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
split
(
inspect
.
getfile
(
inspect
.
currentframe
()))[
0
],
"../src"
)))
if
cmd_subfolder
not
in
sys
.
path
:
sys
.
path
.
insert
(
0
,
cmd_subfolder
)
import
paho.mqtt.client
as
mqtt
import
context
# Ensures paho is in PYTHONPATH
import
paho.mqtt.client
as
mqtt
import
logging
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# If you want to use a specific client id, use
...
...
examples/client_pub-wait.py
浏览文件 @
33b7c95d
...
...
@@ -15,40 +15,33 @@
# Copyright (c) 2010,2011 Roger Light <roger@atchoo.org>
# All rights reserved.
# This shows a simple example of an MQTT subscriber.
import
sys
import
time
try
:
import
paho.mqtt.client
as
mqtt
except
ImportError
:
# This part is only required to run the example from within the examples
# directory when the module itself is not installed.
#
# If you have the module installed, just use "import paho.mqtt.client"
import
os
import
inspect
cmd_subfolder
=
os
.
path
.
realpath
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
split
(
inspect
.
getfile
(
inspect
.
currentframe
()
))[
0
],
"../src"
)))
if
cmd_subfolder
not
in
sys
.
path
:
sys
.
path
.
insert
(
0
,
cmd_subfolder
)
import
paho.mqtt.client
as
mqtt
# This shows a simple example of waiting for a message to be published.
import
context
# Ensures paho is in PYTHONPATH
import
paho.mqtt.client
as
mqtt
def
on_connect
(
mqttc
,
obj
,
flags
,
rc
):
print
(
"rc: "
+
str
(
rc
))
print
(
"rc: "
+
str
(
rc
))
def
on_message
(
mqttc
,
obj
,
msg
):
print
(
msg
.
topic
+
" "
+
str
(
msg
.
qos
)
+
" "
+
str
(
msg
.
payload
))
print
(
msg
.
topic
+
" "
+
str
(
msg
.
qos
)
+
" "
+
str
(
msg
.
payload
))
def
on_publish
(
mqttc
,
obj
,
mid
):
print
(
"mid: "
+
str
(
mid
))
print
(
"mid: "
+
str
(
mid
))
pass
def
on_subscribe
(
mqttc
,
obj
,
mid
,
granted_qos
):
print
(
"Subscribed: "
+
str
(
mid
)
+
" "
+
str
(
granted_qos
))
print
(
"Subscribed: "
+
str
(
mid
)
+
" "
+
str
(
granted_qos
))
def
on_log
(
mqttc
,
obj
,
level
,
string
):
print
(
string
)
# If you want to use a specific client id, use
# mqttc = mqtt.Client("client-id")
# but note that the client id must be unique on the broker. Leaving the client
...
...
@@ -59,7 +52,7 @@ mqttc.on_connect = on_connect
mqttc
.
on_publish
=
on_publish
mqttc
.
on_subscribe
=
on_subscribe
# Uncomment to enable debug messages
#mqttc.on_log = on_log
#
mqttc.on_log = on_log
mqttc
.
connect
(
"localhost"
,
1883
,
60
)
mqttc
.
loop_start
()
...
...
examples/client_session_present.py
浏览文件 @
33b7c95d
...
...
@@ -17,20 +17,9 @@
# This demonstrates the session present flag when connecting.
import
sys
try
:
import
paho.mqtt.client
as
mqtt
except
ImportError
:
# This part is only required to run the example from within the examples
# directory when the module itself is not installed.
#
# If you have the module installed, just use "import paho.mqtt.client"
import
os
import
inspect
cmd_subfolder
=
os
.
path
.
realpath
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
split
(
inspect
.
getfile
(
inspect
.
currentframe
()
))[
0
],
"../src"
)))
if
cmd_subfolder
not
in
sys
.
path
:
sys
.
path
.
insert
(
0
,
cmd_subfolder
)
import
paho.mqtt.client
as
mqtt
import
context
# Ensures paho is in PYTHONPATH
import
paho.mqtt.client
as
mqtt
def
on_connect
(
mqttc
,
obj
,
flags
,
rc
):
if
obj
==
0
:
...
...
@@ -39,23 +28,26 @@ def on_connect(mqttc, obj, flags, rc):
print
(
"Second connection:"
)
elif
obj
==
2
:
print
(
"Third connection (with clean session=True):"
)
print
(
" Session present: "
+
str
(
flags
[
'session present'
]))
print
(
" Connection result: "
+
str
(
rc
))
print
(
" Session present: "
+
str
(
flags
[
'session present'
]))
print
(
" Connection result: "
+
str
(
rc
))
mqttc
.
disconnect
()
def
on_disconnect
(
mqttc
,
obj
,
rc
):
mqttc
.
user_data_set
(
obj
+
1
)
mqttc
.
user_data_set
(
obj
+
1
)
if
obj
==
0
:
mqttc
.
reconnect
()
def
on_log
(
mqttc
,
obj
,
level
,
string
):
print
(
string
)
mqttc
=
mqtt
.
Client
(
client_id
=
"asdfj"
,
clean_session
=
False
)
mqttc
.
on_connect
=
on_connect
mqttc
.
on_disconnect
=
on_disconnect
# Uncomment to enable debug messages
#mqttc.on_log = on_log
#
mqttc.on_log = on_log
mqttc
.
user_data_set
(
0
)
mqttc
.
connect
(
"test.mosquitto.org"
,
1883
,
60
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录