Skip to content

Commit 4b6b47e

Browse files
authored
Merge pull request #16 from JaquerEspeis/python3_prints
Add parenthesis to the prints so they work on python3 also.
2 parents 4d092e7 + bc8856f commit 4b6b47e

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

examples/mqtt_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ def connected(client):
2222
# This is a good place to subscribe to feed changes. The client parameter
2323
# passed to this function is the Adafruit IO MQTT client so you can make
2424
# calls against it easily.
25-
print 'Connected to Adafruit IO! Listening for DemoFeed changes...'
25+
print('Connected to Adafruit IO! Listening for DemoFeed changes...')
2626
# Subscribe to changes on a feed named DemoFeed.
2727
client.subscribe('DemoFeed')
2828

2929
def disconnected(client):
3030
# Disconnected function will be called when the client disconnects.
31-
print 'Disconnected from Adafruit IO!'
31+
print('Disconnected from Adafruit IO!')
3232
sys.exit(1)
3333

3434
def message(client, feed_id, payload):
3535
# Message function will be called when a subscribed feed has a new value.
3636
# The feed_id parameter identifies the feed, and the payload parameter has
3737
# the new value.
38-
print 'Feed {0} received new value: {1}'.format(feed_id, payload)
38+
print('Feed {0} received new value: {1}'.format(feed_id, payload))
3939

4040

4141
# Create an MQTT client instance.
@@ -51,16 +51,16 @@ def message(client, feed_id, payload):
5151

5252
# Now the program needs to use a client loop function to ensure messages are
5353
# sent and received. There are a few options for driving the message loop,
54-
# depending on what your program needs to do.
54+
# depending on what your program needs to do.
5555

5656
# The first option is to run a thread in the background so you can continue
5757
# doing things in your program.
5858
client.loop_background()
5959
# Now send new values every 10 seconds.
60-
print 'Publishing a new message every 10 seconds (press Ctrl-C to quit)...'
60+
print('Publishing a new message every 10 seconds (press Ctrl-C to quit)...')
6161
while True:
6262
value = random.randint(0, 100)
63-
print 'Publishing {0} to DemoFeed.'.format(value)
63+
print('Publishing {0} to DemoFeed.'.format(value))
6464
client.publish('DemoFeed', value)
6565
time.sleep(10)
6666

@@ -70,14 +70,14 @@ def message(client, feed_id, payload):
7070
# good option if you don't want to or can't have a thread pumping the message
7171
# loop in the background.
7272
#last = 0
73-
#print 'Publishing a new message every 10 seconds (press Ctrl-C to quit)...'
73+
#print('Publishing a new message every 10 seconds (press Ctrl-C to quit)...')
7474
#while True:
7575
# # Explicitly pump the message loop.
7676
# client.loop()
7777
# # Send a new message every 10 seconds.
7878
# if (time.time() - last) >= 10.0:
7979
# value = random.randint(0, 100)
80-
# print 'Publishing {0} to DemoFeed.'.format(value)
80+
# print('Publishing {0} to DemoFeed.'.format(value))
8181
# client.publish('DemoFeed', value)
8282
# last = time.time()
8383

examples/mqtt_subscribe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ def connected(client):
2424
# This is a good place to subscribe to feed changes. The client parameter
2525
# passed to this function is the Adafruit IO MQTT client so you can make
2626
# calls against it easily.
27-
print 'Connected to Adafruit IO! Listening for {0} changes...'.format(FEED_ID)
27+
print('Connected to Adafruit IO! Listening for {0} changes...'.format(FEED_ID))
2828
# Subscribe to changes on a feed named DemoFeed.
2929
client.subscribe(FEED_ID)
3030

3131
def disconnected(client):
3232
# Disconnected function will be called when the client disconnects.
33-
print 'Disconnected from Adafruit IO!'
33+
print('Disconnected from Adafruit IO!')
3434
sys.exit(1)
3535

3636
def message(client, feed_id, payload):
3737
# Message function will be called when a subscribed feed has a new value.
3838
# The feed_id parameter identifies the feed, and the payload parameter has
3939
# the new value.
40-
print 'Feed {0} received new value: {1}'.format(feed_id, payload)
40+
print('Feed {0} received new value: {1}'.format(feed_id, payload))
4141

4242

4343
# Create an MQTT client instance.

examples/mqtt_viewall.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# message published for an account on AIO. Useful for debugging when other
33
# devices are writing to AIO for an account.
44
#
5-
# Copyright (c) 2014 Adafruit Industries
5+
# Copyright (c) 2014, 2016 Adafruit Industries
66
# Author: Tony DiCola
77

88
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -43,15 +43,15 @@
4343

4444
# Setup message handlers for connect, disconnect and message received.
4545
def on_connect(client, userdata, flags, rc):
46-
print 'Connected!'
46+
print('Connected!')
4747
client.subscribe(PATH)
48-
print 'Subscribed to path {0}!'.format(PATH)
48+
print('Subscribed to path {0}!'.format(PATH))
4949

5050
def on_disconnect(client, userdata, rc):
51-
print 'Disconnected!'
51+
print('Disconnected!')
5252

5353
def on_message(client, userdata, msg):
54-
print 'Received on {0}: {1}'.format(msg.topic, msg.payload.decode('utf-8'))
54+
print('Received on {0}: {1}'.format(msg.topic, msg.payload.decode('utf-8')))
5555

5656

5757
# Create MQTT client and connect to Adafruit IO.
@@ -62,5 +62,5 @@ def on_message(client, userdata, msg):
6262
client.on_message = on_message
6363
client.connect(SERVER, port=PORT, keepalive=KEEPALIVE)
6464

65-
print 'Press Ctrl-C to quit.'
65+
print('Press Ctrl-C to quit.')
6666
client.loop_forever()

0 commit comments

Comments
 (0)