0

MQTT Ban
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MQTT Ban

by noelportugal on Thu Feb 22, 2018 12:40 am

First I started using the AdafruitIO Arduino library, and was getting "Network disconnected" almos immediately after connecting...Then I change to MQTT lib and now getting this:

Connecting to MQTT... You have been banned from connecting. Please contact the MQTT server administrator for more details.


help?

noelportugal
 
Posts: 8
Joined: Wed Nov 11, 2009 1:08 am

Re: MQTT Ban

by hansoloqwertzui on Sun Feb 25, 2018 5:26 pm

I have the same issue for some days now. Couldn't find an answer either. I don't exceed any limitations of my plan.

hansoloqwertzui
 
Posts: 4
Joined: Sat Feb 24, 2018 8:43 am

Re: MQTT Ban

by hansoloqwertzui on Tue Mar 27, 2018 8:39 am

Still have this problem, any suggestions?

hansoloqwertzui
 
Posts: 4
Joined: Sat Feb 24, 2018 8:43 am

Re: MQTT Ban

by adafruit_support_carter on Tue Mar 27, 2018 1:01 pm

Post the complete code for the sketch your are using that causes this.

adafruit_support_carter
 
Posts: 5628
Joined: Tue Nov 29, 2016 2:45 pm

Re: MQTT Ban

by hansoloqwertzui on Wed Mar 28, 2018 5:51 pm

Here my code. The thread basically publishs every 15 seconds a data point to the feeds "temperature", "humidity", "light", "water", "water_1", "water_2".

Code: Select all | TOGGLE FULL SIZE
import serial
import time
from threading import Thread
import logging
from Adafruit_IO import *
import datetime
import numpy as np


class MyThread(Thread):

    def __init__(self, val, client):
        ''' Constructor. '''
        Thread.__init__(self)
        self.val = val
        self.client = client
        self.values = ["temperature", "humidity", "light",
                       "water", "water_1", "water_2"] # add light test feed
        self.running = True
        self.my_dict = {}

    def run(self):
        while self.running:
            try:
                self.client.loop(5)
                if not self.client.is_connected():
                    self.client.connect()
                for tmp in self.values:
                    if tmp in self.my_dict:
                        y = self.my_dict[tmp]
                        y = float(y)
                        print(tmp + ": " + str(y))
                        self.client.publish(tmp, y)
                time.sleep(self.val)
            except Exception as e:
                x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
                logging.debug("MyThread: " + x + ":" + str(e))

    def set_run(self, running):
        self.running = running

    def set_dict_value(self, key, value):
        if key in self.values:
            self.my_dict[key] = value



# Define callback functions which will be called when certain events happen.
def connected(client):
    x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    # Connected function will be called when the client is connected to Adafruit IO.
    #logging.debug(x + ': Connected to Adafruit IO!')

def disconnected(client):
    x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    # Disconnected function will be called when the client disconnects.
    #logging.debug(x + ': Disconnected from Adafruit IO!')


logging.basicConfig(filename='/home/pi/plant_monitor.log', level=logging.DEBUG)

values = ["temperature", "humidity", "light", "water", "water_1", "water_2"]
client = MQTTClient('xxxxxx', 'xxxxxx')
client.on_connect = connected
client.on_disconnect = disconnected

client.connect()
#client.loop_background()
myThread = MyThread(15, client)


lightOn = True
line = ""
runLoop = True

# serial connection
ser = None

temps = [0 for x in range(60)]

# connect serial arduino
try:
    ser = serial.Serial('/dev/ttyACM0', 9600)
    myThread.start()
except Exception as e:
    x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    logging.debug(x + ":" + "Serial connection broken!" + str(e))
    runLoop = False

k = 0
meanTemp = 0.0
turnedOn = False

while runLoop:
    try:
        if ser.is_open:
            line = ser.readline().decode().strip('\r').strip('\n').strip()
        else:
            ser = serial.Serial('/dev/ttyACM0', 9600)
    except Exception as e:
        x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
        logging.debug(x + ":" + "Serial connection broken!" + str(e))
        myThread.set_run(False)
        break
    try:
        key = line[:line.find("=")]

        # check if key in values
        if key in values:
            # substring value
            value = line[line.find("=")+1:]

            if len(value) < 7:
                myThread.set_dict_value(key, value)
            if key == values[0]:
                if k < 60:
                    temps[k] = float(value)
                    k += 1
                    #smooth signal
                    myThread.set_dict_value(key, np.median(temps))
                if k == 60:
                    medianTemp = np.median(temps)
                    myThread.set_dict_value(key, medianTemp)
                    k = 0
                    now = datetime.datetime.now()
                    is_night = now.hour >= 18 or now.hour <= 6

                    if medianTemp < 22.0 and not turnedOn and not is_night:
                        ser.write('1'.encode())
                        turnedOn = True
                    if medianTemp < 19.0 and not turnedOn and is_night:
                        ser.write('1'.encode())
                        turnedOn = True
                    if medianTemp >= 22.0 and not is_night:
                        ser.write('0'.encode())
                    if medianTemp >= 19.0 and is_night:
                        ser.write('0'.encode())
                    if medianTemp <= 18.0:
                        turnedOn = False
        time.sleep(1)
    except Exception as e:
        x = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
        logging.debug("Dict and Temperature Exception: " + x + ":" + str(e))

hansoloqwertzui
 
Posts: 4
Joined: Sat Feb 24, 2018 8:43 am

Re: MQTT Ban

by abachman on Wed Apr 04, 2018 3:00 pm

Hi all,


There are two different bans happening here.

noelportugal, we added your account to a permanent MQTT ban list about 2 years ago, it looks like. Your account was hitting the MQTT server attempting authentication a few times per second, 24 hours a day. Enough that it was hard to tell the difference between an intentional and unintentional denial-of-service attack :( We've updated our throttling / temporary-ban logic and changed the way the MQTT broker handles invalid subscription topics (which may have been the cause) so that a runaway script or device won't be as likely or as dramatic. I've cleared the permanent ban so you should be able to reconnect to the MQTT service now.

hansoloqwertzui, if I'm reading this correctly, you're publishing 6 data points 4 times per minute which, if you're on the free plan, should always be permitted. Are you running any other clients or anything subscribing to IO? Our previous method of handling invalid subscription topics on the MQTT broker was to disconnect the client on invalid or unauthorized subscriptions, which lead in some cases to the runaway authentication problem if clients didn't pause between reconnection attempts. Unfortunately, if one client attempts to authenticate on your account too many times (20 attempts per minute) it will temporarily ban you from re-authenticating. We deployed a change last Friday that changed that behavior over to dropping the subscription request and publishing an error message to your {username}/errors topic. It's not clear if that's your issue, however.

In the meantime, I reset your rate limits to see if that helps with your problem. That would only fix the issue if you've exceeded the limit and haven't stopped attempting to publish or sign in for more than a minute. After 60 seconds all the rate-limiting will automatically clear on its own.


- adam b.

abachman
 
Posts: 214
Joined: Mon Feb 01, 2010 12:48 pm

Re: MQTT Ban

by hansoloqwertzui on Sun Apr 15, 2018 7:04 am

Thanks for the detailed reply! Yes, I'm sending 24 data points per minute. I am not running any other clients or subscriptions, only this script.

I still have this problem. After some time the connection drops and when trying to reconnect I get the following error message: "Error connecting to Adafruit IO with rc: 7".
As stated in my script I'm trying to reconnect every 15 seconds after the connection drops.

hansoloqwertzui
 
Posts: 4
Joined: Sat Feb 24, 2018 8:43 am

Re: MQTT Ban

by homemonitoringsystem on Mon Apr 23, 2018 3:05 pm

i have the same problem, saying that "you have been banned from connecting. Please contact the MQTT server administrator for more details".

homemonitoringsystem
 
Posts: 1
Joined: Mon Apr 23, 2018 3:01 pm

Re: MQTT Ban

by joaco_123 on Wed Jun 20, 2018 5:51 pm

I have been banned, saying that "you have been banned from connecting. Please contact the MQTT server administrator for more details".
please help me!

joaco_123
 
Posts: 1
Joined: Mon Jun 18, 2018 8:57 pm

Please be positive and constructive with your questions and comments.