FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
intelligent-objects/python/python_mqtt.py at master · areaofeffect/intelligent-objects · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
areaofeffect
/
intelligent-objects
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
intelligent-objects
/
python
/
python_mqtt.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (31 loc) · 1.25 KB
Breadcrumbs
intelligent-objects
/
python
/
python_mqtt.py
Copy path
File metadata and controls
42 lines (31 loc) · 1.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import
paho
.
mqtt
.
client
as
mqtt
import
RPi
.
GPIO
as
GPIO
import
time
GPIO
.
setwarnings
(
False
)
GPIO
.
setmode
(
GPIO
.
BOARD
)
GPIO
.
setup
(
18
,
GPIO
.
OUT
)
#Define pin 18 as an output pin
# 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
))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client
.
subscribe
(
"light"
)
# The callback for when a PUBLISH message is received from the server.
def
on_message
(
client
,
userdata
,
msg
):
if
str
(
msg
.
payload
)
==
"on"
:
GPIO
.
output
(
18
,
1
)
time
.
sleep
(
1
)
#Time delay of 1 second
if
str
(
msg
.
payload
)
==
"off"
:
GPIO
.
output
(
18
,
0
)
time
.
sleep
(
1
)
#Time delay of 1 second
#Outputs digital HIGH signal (5V) on pin 3
print
(
msg
.
topic
+
" "
+
str
(
msg
.
payload
))
client
=
mqtt
.
Client
()
client
.
on_connect
=
on_connect
client
.
on_message
=
on_message
client
.
connect
(
"23.21.151.236"
,
1883
,
60
)
# 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
()
Back
|
FazBrowse Home
|
New Git URL