0

adafruit IO : python mqtt_time.py Example
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

adafruit IO : python mqtt_time.py Example

by mikec on Tue Mar 05, 2019 2:47 pm

I have not be able to get this to work , no time messages received .
No problem with other python rest and mqtt examples.
No problem with adafruitio_17_time.py REST example.

mikec
 
Posts: 9
Joined: Tue Aug 07, 2012 12:52 pm

Re: adafruit IO : python mqtt_time.py Example

by brubell on Tue Mar 05, 2019 3:11 pm

Can you post the output from your terminal when running this example?

brubell
 
Posts: 282
Joined: Fri Jul 17, 2015 10:33 pm

Re: adafruit IO : python mqtt_time.py Example

by mikec on Tue Mar 05, 2019 3:22 pm

The output observed is from the code print statements indicating client.scribe action :
* Subscribing to /time/seconds
* Subscribing to /time/millis
* Subscribing to iso-8601
...
repeats forever

mikec
 
Posts: 9
Joined: Tue Aug 07, 2012 12:52 pm

Re: adafruit IO : python mqtt_time.py Example

by brubell on Tue Mar 05, 2019 6:12 pm

mikec wrote:The output observed is from the code print statements indicating client.scribe action :
* Subscribing to /time/seconds
* Subscribing to /time/millis
* Subscribing to iso-8601
...
repeats forever


Can you post your code (even if it's our example)

brubell
 
Posts: 282
Joined: Fri Jul 17, 2015 10:33 pm

Re: adafruit IO : python mqtt_time.py Example

by mikec on Tue Mar 05, 2019 6:48 pm

ok ... see below:

"""
mqtt_time.py
============================================
example of utilizing MQTT time topics to grab
the time from the Adafruit IO server.

Author: Brent Rubell
"""

# Import standard python modules.
import sys
import time

# Import Adafruit IO MQTT client.
from Adafruit_IO import MQTTClient

ADAFRUIT_IO_KEY = 'key'
ADAFRUIT_IO_USERNAME = 'name'

def disconnected(client):
# Disconnected function will be called when the client disconnects.
print('Disconnected from Adafruit IO!')
sys.exit(1)

def message(client, feed_id, payload):
# Message function will be called when a subscribed feed has a new value.
# The feed_id parameter identifies the feed, and the payload parameter has
# the new value.
print('\t Feed {0} received new value: {1}'.format(feed_id, payload))


# Create a SECURE MQTT client instance
# Note: This client will default to secure, an optional parameter can be added
# to make it insecure, comment out the below line
# client = MQTTClient(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY, secure=False)
client = MQTTClient(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

# Setup the callback functions defined above.
client.on_disconnect = disconnected
client.on_message = message

# Connect to the Adafruit IO server.
client.connect()

# time per loop
loop_time = 2

client.loop_background()
while True:
print('* Subscribing to /time/seconds')
client.subscribe_time('seconds')
time.sleep(loop_time)
print('* Subscribing to /time/millis')
client.subscribe_time('millis')
time.sleep(loop_time)
print('* Subscribing to iso-8601')
client.subscribe_time('iso')
time.sleep(loop_time)

mikec
 
Posts: 9
Joined: Tue Aug 07, 2012 12:52 pm

Re: adafruit IO : python mqtt_time.py Example

by brubell on Fri Mar 08, 2019 12:35 pm

Thank you for the output log - I noticed a bug within mqtt_client and the time example and fixed both of them this morning (https://github.com/adafruit/Adafruit_IO_Python/pull/95)

Please reinstall (or upgrade) the library to v2.3.1 (https://github.com/adafruit/Adafruit_IO ... /tag/2.3.1) and run the new example code (https://github.com/adafruit/Adafruit_IO ... tt_time.py).

brubell
 
Posts: 282
Joined: Fri Jul 17, 2015 10:33 pm

Re: adafruit IO : python mqtt_time.py Example

by mikec on Fri Mar 08, 2019 5:45 pm

yes thank .. working now...

mike c

mikec
 
Posts: 9
Joined: Tue Aug 07, 2012 12:52 pm

Please be positive and constructive with your questions and comments.