Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.

Unreliable connection
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Unreliable connection

by krambriw on Sat Feb 20, 2016 10:52 am


I experience frequently that it is unreliable to connect. The Python script below verifies that several retries sometimes are needed to get a successful connection

Kind regards, Walter

Code: Select all | TOGGLE FULL SIZE
from Adafruit_IO import MQTTClient
import time

def connected(client):
    print client.is_connected()
    global started
    global cntr
    started = True
    cntr = 0

def disconnected(client):
    print client.is_connected()
    del client

def message(client, feed_id, payload):
    msg = feed_id
    pl = payload
    print msg, pl

def goConnect():
    # Create a MQTT client instance.
    client = MQTTClient(adafruitUser, adafruitIOkey)

    # Setup the callback functions defined above.
    client.on_connect    = connected
    client.on_disconnect = disconnected
    client.on_message    = message
    # Connect to the Adafruit IO server and start subscribing.
    return client

adafruitUser = 'user'
adafruitIOkey = 'iokey'
adafruitFeedId = 'mytest'
cntr = 0
started = False

while not started:
    client = goConnect()
    if cntr > 0:
        print 'Retry: ', cntr
    cntr += 1

Posts: 22
Joined: Fri Feb 19, 2016 6:07 pm

Please be positive and constructive with your questions and comments.