Subscription to Throttle and Errors topics not working
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.

Subscription to Throttle and Errors topics not working

by MacaquimVerde on Wed Sep 15, 2021 12:01 pm

I am using Python Adafruit_IO MQTT library and everything looks fine, except for that I am not succeeding in subscribing to throttle and errors topic.
I realize, by looking at the code on Github, that the platform requires different string formations depending on the type of subscription you need. And the functions or modules are specifically coded to form that kind of string. For regular feeds the subscribe module will get the feed Id and combine with username to create a string like " "{username}/feeds/{feed_id}". The subscribe_group requires "{username}/groups/{group_id}". The subscribe_time module will do some logic to form the string like "time/{type of time}. And so on.
As the errors and throttle topics string are {username}/errors and {username}/throttle, respectively. I guess an specific module or function is missing.
I intentionally went above publishing maximum threshold to test using another client I have running where I would like to add throttle control based on the warnings. I see the throttle warning on monitor, but no message, if I subscribe using the regular feed module.
I tried to create function in another client to accomplish with the subscription, copying and adapting the subscribe_time module, but it gives errors when a message should be coming. Maybe this is not possible or I did it wrong.

What am I missing or misunderstanding? Please help !

Here is my function code.
def subscribe_throttle(self):
"""Subscribe to throttle topic on the Adafruit IO"""

# Create an MQTT client instance.
# Setup the callback functions defined above.
client.on_connect = connected
client.on_disconnect = disconnected
client.on_message = message
client.on_subscribe = subscribed

# Connect to the Adafruit IO server.

# piece of code
# piece of code
while ...
# piece of code

When the throttle warnings start to appear I get the errors:

Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9__...\lib\threading.py", line 973, in _bootstrap_inner
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_...\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\paho\mqtt\client.py", line 3452, in _thread_main
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\paho\mqtt\client.py", line 1779, in loop_forever
rc = self.loop(timeout, max_packets)
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\paho\mqtt\client.py", line 1181, in loop
rc = self.loop_read(max_packets)
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\paho\mqtt\client.py", line 1572, in loop_read
rc = self._packet_read()
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\paho\mqtt\client.py", line 2310, in _packet_read
rc = self._packet_handle()
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\paho\mqtt\client.py", line 2936, in _packet_handle
return self._handle_publish()
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\paho\mqtt\client.py", line 3216, in _handle_publish
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\paho\mqtt\client.py", line 3444, in _handle_on_message
self.on_message(self, self._userdata, message)
File "C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9__...\LocalCache\local-packages\Python39\site-packages\Adafruit_IO\mqtt_client.py", line 121, in _mqtt_message
elif parsed_topic[2] == 'weather':
IndexError: list index out of range

Posts: 1
Joined: Wed Mar 25, 2020 9:44 pm

Re: Subscription to Throttle and Errors topics not working

by brubell on Fri Sep 17, 2021 10:13 am

This looks like a bug with parsing the throttle topic. Please file an issue on the library repository here: https://github.com/adafruit/Adafruit_IO_Python/issues

Posts: 1520
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.