0

Problem with IO feed from Raspberry Pi
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Problem with IO feed from Raspberry Pi

by wmilamjr on Sun May 05, 2019 6:18 pm

I am incurring an interesting problem with my IO feed using Python 3.5.3 on my Raspberry Pi. If I save and run the program the first time, it runs like a champ. But, shut down and restart the program, it errors. it will keep erring until I delete all the feeds and start from scratch. This is very annoying. I need advise.
This is message that I get:

Traceback (most recent call last):
File "/home/pi/Python_3/WeatherPi-io-tk.py", line 36, in <module>
direction_feed = aio.feeds('wind_direction')
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 274, in feeds
return Feed.from_dict(self._get(path))
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 118, in _get
self._handle_error(response)
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 108, in _handle_error
raise RequestError(response)
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 404 Not Found - not found - that is an invalid URL, please check the API documentation at https://io.adafruit.com/api/docs to make sure your URL is correct

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/Python_3/WeatherPi-io-tk.py", line 41, in <module>
temperature_feed = aio.create_feed(Feed(name='temperature'))
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 281, in create_feed
return Feed.from_dict(self._post(path, {"feed": feed._asdict()}))
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 127, in _post
self._handle_error(response)
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 105, in _handle_error
raise RequestError(response)
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 400 Bad Request - ['Name must be unique within the selected group', 'Name must not match an existing key within the selected group', 'Key must be unique within the selected group', 'Group feeds is invalid']
>>>.

Here is the Code I used

Code: Select all | TOGGLE FULL SIZE
from Adafruit_IO import Client, Feed, RequestError

ADAFRUIT_IO_USERNAME = '???'

ADAFRUIT_IO_KEY = '???'

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

#set up feed

try: # if we already have the feeds, assign them.
    temperature_feed = aio.feeds('temperature')
    humidity_feed = aio.feeds('humidity')
    pressure_feed = aio.feeds('pascals')
    rain_feed = aio.feeds('rain')
    wind_feed = aio.feeds('wind')
    direction_feed = aio.feeds('wind_direction')
    power_feed = aio.feeds('power')
   

except RequestError: # if we don't, create and assign them.
    temperature_feed = aio.create_feed(Feed(name='temperature'))
    humidity_feed = aio.create_feed(Feed(name='humidity'))
    pressure_feed = aio.create_feed(Feed(name='pascals'))
    rain_feed = aio.create_feed(Feed(name='rain'))
    wind_feed = aio.create_feed(Feed(name='wind'))
    direction_feed = aio.create_feed(Feed(name='wind_direction'))
    power_feed = aio.create_feed(Feed(name='power'))
 
"""
====================================================================
IN MAIN
"""

            if IO_count == 10:
           
               # Send to feed
                aio.send(temperature_feed.key, Temp)
                aio.send(humidity_feed.key, int(humidity))
                aio.send(pressure_feed.key, int(hectopascals))
                aio.send(rain_feed.key, wet)
                aio.send(wind_feed.key,windspeed)
                aio.send(direction_feed.key,values)
                aio.send(power_feed.key,amps)

                IO_count = 0
 
            else:
                IO_count = IO_count +1

wmilamjr
 
Posts: 7
Joined: Sun Feb 05, 2017 9:10 pm

Re: Problem with IO feed from Raspberry Pi

by brubell on Thu May 09, 2019 9:30 am

Are the feeds provided feed keys, not feed names?

Could you run the following code, twice, and paste the output? I'm interested in seeing where the failure is, within the try/except:
Code: Select all | TOGGLE FULL SIZE
from Adafruit_IO import Client, Feed, RequestError

ADAFRUIT_IO_USERNAME = '???'

ADAFRUIT_IO_KEY = '???'

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

#set up feed

try: # if we already have the feeds, assign them.
    print('assigning feeds...')
    temperature_feed = aio.feeds('temperature')
    humidity_feed = aio.feeds('humidity')
    pressure_feed = aio.feeds('pascals')
    rain_feed = aio.feeds('rain')
    wind_feed = aio.feeds('wind')
    direction_feed = aio.feeds('wind_direction')
    power_feed = aio.feeds('power')
except RequestError: # if we don't, create and assign them.
    print('creating feeds...')
    temperature_feed = aio.create_feed(Feed(name='temperature'))
    humidity_feed = aio.create_feed(Feed(name='humidity'))
    pressure_feed = aio.create_feed(Feed(name='pascals'))
    rain_feed = aio.create_feed(Feed(name='rain'))
    wind_feed = aio.create_feed(Feed(name='wind'))
    direction_feed = aio.create_feed(Feed(name='wind_direction'))
    power_feed = aio.create_feed(Feed(name='power'))
 
"""
====================================================================
IN MAIN
"""

            if IO_count == 10:
           
               # Send to feed
                aio.send(temperature_feed.key, Temp)
                aio.send(humidity_feed.key, int(humidity))
                aio.send(pressure_feed.key, int(hectopascals))
                aio.send(rain_feed.key, wet)
                aio.send(wind_feed.key,windspeed)
                aio.send(direction_feed.key,values)
                aio.send(power_feed.key,amps)

                IO_count = 0
 
            else:
                IO_count = IO_count +1

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

Re: Problem with IO feed from Raspberry Pi

by wmilamjr on Fri May 10, 2019 6:36 pm

I added the extra code and saved it. I also removed the existing feeds so it will run with a clean slate. The first start ran the way it should. The seconded start failed. What are your thoughts.

See the following:


Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "copyright", "credits" or "license()" for more information.
>>>
=============== RESTART: /home/pi/Python_3/WeatherPi-io-tk.py ===============
assigning feeds...
creating feeds...
05-10-19 at 18:08:49
>>>
=============== RESTART: /home/pi/Python_3/WeatherPi-io-tk.py ===============
assigning feeds...
creating feeds...
Traceback (most recent call last):
File "/home/pi/Python_3/WeatherPi-io-tk.py", line 37, in <module>
direction_feed = aio.feeds('wind_direction')
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 274, in feeds
return Feed.from_dict(self._get(path))
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 118, in _get
self._handle_error(response)
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 108, in _handle_error
raise RequestError(response)
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 404 Not Found - not found - that is an invalid URL, please check the API documentation at https://io.adafruit.com/api/docs to make sure your URL is correct

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/Python_3/WeatherPi-io-tk.py", line 43, in <module>
temperature_feed = aio.create_feed(Feed(name='temperature'))
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 281, in create_feed
return Feed.from_dict(self._post(path, {"feed": feed._asdict()}))
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 127, in _post
self._handle_error(response)
File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_IO/client.py", line 105, in _handle_error
raise RequestError(response)
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 400 Bad Request - ['Name must be unique within the selected group', 'Name must not match an existing key within the selected group', 'Key must be unique within the selected group', 'Group feeds is invalid']
>>>

wmilamjr
 
Posts: 7
Joined: Sun Feb 05, 2017 9:10 pm

Re: Problem with IO feed from Raspberry Pi

by wmilamjr on Mon May 13, 2019 5:08 pm

I now have the answer to this problem. After talking to my son-in-law, a programmer, about my problem, he found it in less than 5 minutes. So here it is:

When the following code is ran, something odd happens.

except RequestError: # if we don't, create and assign them.
temperature_feed = aio.create_feed(Feed(name='temperature'))
humidity_feed = aio.create_feed(Feed(name='humidity'))
pressure_feed = aio.create_feed(Feed(name='pascals'))
rain_feed = aio.create_feed(Feed(name='rain'))
wind_feed = aio.create_feed(Feed(name='wind'))
direction_feed = aio.create_feed(Feed(name='wind_direction'))
power_feed = aio.create_feed(Feed(name='power'))

The line
direction_feed = aio.create_feed(Feed(name='wind_direction'))

created a feed key 'wind-direction' instead of 'wind_direction' . This didn't match my feed key. So everything comes to a grinding halt. So the solution is to never use an underscore "__" in your feed names.

I hope this helps someone else.

wmilamjr
 
Posts: 7
Joined: Sun Feb 05, 2017 9:10 pm

Please be positive and constructive with your questions and comments.