Air quality Sensor - Adafruit request failed

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.
Locked
User avatar
Teamplay
 
Posts: 3
Joined: Wed Jun 15, 2022 8:25 pm

Air quality Sensor - Adafruit request failed

Post by Teamplay »

Hey,
I'm a complete newbie to the programming universe and I want to create a air quality sensor with the following code.

Code: Select all

import serial, time 
from Adafruit_IO import Client
aio = Client('Teamplay','aio_abcdefghik')

ser = serial.Serial('/dev/ttyUSB0')


while True:
        data= []
        for index in range (0,10):
                datum = ser.read()
                data.append(datum)

        pmtwofive = int.from_bytes(b''.join(data[2:4]), byteorder='little') / 10
        aio.send('python3-airquality.py', pmtwofive)
        pmten = int.from_bytes(b''.join(data[4:6]), byteorder='little') / 10
        aio.send('airquality1.py', pmten)
        time.sleep (10)
But now I get the error:

Code: Select all

Traceback (most recent call last):
  File "/home/teamplazer/kingswoodten.py", line 15, in <module>
    aio.send('kingswoodtwofive', pmtwofive)
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_IO/client.py", line 167, in send_data
    return self.create_data(feed, payload)
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_IO/client.py", line 313, in create_data
    return Data.from_dict(self._post(path, data._asdict()))
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_IO/client.py", line 139, in _post
    self._handle_error(response)
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_IO/client.py", line 117, in _handle_error
    raise RequestError(response)
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 404 Not Found - not found - API documentation can be found at https://io.adafruit.com/api/docs
What can I do to solve this error?
Thank you for your kindness and your time!
Last edited by adafruit_support_carter on Fri Jun 17, 2022 1:41 pm, edited 1 time in total.
Reason: added [code] tags

User avatar
tepalia02
 
Posts: 104
Joined: Sun Apr 24, 2022 6:53 am

Re: Air quality Sensor - Adafruit request failed

Post by tepalia02 »

Hi, the Adafruit_IO import Client library must be installed first. Have you done that without any problem?

User avatar
Teamplay
 
Posts: 3
Joined: Wed Jun 15, 2022 8:25 pm

Re: Air quality Sensor - Adafruit request failed

Post by Teamplay »

Hey, thank you for your help I installed the library succesfully and I changed the code to create a feed:

Code: Select all

import serial, time
from Adafruit_IO import Client, Feed, RequestError
import requests

ADAFRUIT_IO_KEY = 'aio_abcdefgh'
ADAFRUIT_IO_USERNAME = 'Teamplay'
aio = Client('Teamplay','aio_abcdefgh')

DASHBOARD_URL = 'https://io.adafruit.com/Teamplay/dashboards/airquality-dot-py'

ser = serial.Serial('/dev/ttyUSB0')

try:
    airquality = aio.feeds('airquality')
except RequestError:
    feed = Feed(name="airquality")
    airquality = aio.create_feed(feed)

while True:
        data= []
        for index in range (0,10):
                datum = ser.read()
                data.append(datum)

        pmtwofive = int.from_bytes(b''.join(data[2:4]), byteorder='little') / 10
        aio.send('python3-airquality.py', pmtwofive)
        pmten = int.from_bytes(b''.join(data[4:6]), byteorder='little') / 10
        aio.send('airquality1.py', pmten)
        time.sleep (10)

But I still get the following error:

Code: Select all

Traceback (most recent call last):
  File "/home/teamplazer/airquality.py", line 26, in <module>
    aio.send('python3-airquality.py', pmtwofive)
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_IO/client.py", line 167, in send_data
    return self.create_data(feed, payload)
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_IO/client.py", line 313, in create_data
    return Data.from_dict(self._post(path, data._asdict()))
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_IO/client.py", line 139, in _post
    self._handle_error(response)
  File "/usr/local/lib/python3.9/dist-packages/Adafruit_IO/client.py", line 117, in _handle_error
    raise RequestError(response)
Adafruit_IO.errors.RequestError: Adafruit IO request failed: 404 Not Found - not found - There is no feed with the key ''. You can create one using the feed creation API https://io.adafruit.com/api/docs/#create-feed or at https://io.adafruit.com/Teamplay/feeds
What did I do wrong?
Thank your for your answers!
Last edited by adafruit_support_carter on Fri Jun 17, 2022 1:42 pm, edited 1 time in total.
Reason: added [code] tags

User avatar
eherrada
 
Posts: 161
Joined: Thu Jan 04, 2018 4:59 pm

Re: Air quality Sensor - Adafruit request failed

Post by eherrada »

Hey! It seems like you may not have created the feed yet. To do this, go to io.adafruit.com, click on the feeds tab, and create a new feed with the same name as the name you're publishing to in your code.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Air quality Sensor - Adafruit request failed

Post by adafruit_support_carter »

Here are a couple of projects that are doing something very similar:
https://learn.adafruit.com/diy-air-qual ... r/overview
https://learn.adafruit.com/adafruit-io- ... ty-monitor

Can take a look at those for the required setup on the Adafruit IO side of things.

User avatar
Teamplay
 
Posts: 3
Joined: Wed Jun 15, 2022 8:25 pm

Re: Air quality Sensor - Adafruit request failed

Post by Teamplay »

I'm sorry but what exactly should be the name and the key of the feed be?
I know how to create a feed and name them etc. but I have no idea what the name of the feed in my text is.

User avatar
eherrada
 
Posts: 161
Joined: Thu Jan 04, 2018 4:59 pm

Re: Air quality Sensor - Adafruit request failed

Post by eherrada »

You need to change this line

Code: Select all

aio.send('python3-airquality.py', pmtwofive)
to

Code: Select all

aio.send(first_feed.key, pmtwofive)
and this line

Code: Select all

aio.send('airquality1.py', pmten)
to

Code: Select all

aio.send(second_feed.key, pmten)
where first_feed and second_feed are two feeds you created in this block

Code: Select all

try:
    first_feed = aio.feeds('first_feed')
except RequestError:
    feed = Feed(name="first_feed")
    first_feed = aio.create_feed(feed)

try:
    second_feed = aio.feeds('second_feed')
except RequestError:
    feed = Feed(name="second_feed")
    second_feed = aio.create_feed(feed)
You can call the variables what you want, just make sure that they're correctly re-named throughout the file.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”