Creating IO feeds programmatically to specific group

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
wsquared58
 
Posts: 229
Joined: Sun Jun 09, 2019 9:13 pm

Creating IO feeds programmatically to specific group

Post by wsquared58 »

Is there a tutorial on how to make feeds go to a specific group vs "default?
I used a tutorial created by BRubell to make and send data to IO and it works fine except that I want to target the feeds to a particular group. Whenever I run the program the feeds get created but they get targeted to what is the default group, named default.

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Creating IO feeds programmatically to specific group

Post by brubell »

Hi wsquared58,

Could you post the example code you're using?

User avatar
wsquared58
 
Posts: 229
Joined: Sun Jun 09, 2019 9:13 pm

Re: Creating IO feeds programmatically to specific group

Post by wsquared58 »

It is this, from your "Build an environmental Monitor for Feather or Raspberry Pi. I'm in middle of redoing some stuff but this is what I will base it off of. I've run it seeral times even creating a group called "Weather" but every time I run the code it creates the feeds under "default".
I assume I need to explicitly tell it what group but I have not seen anything that addresses that. Since this is my first project it is somewhat moot but if I do other things with sensors that are unrelated I would put them in a different group. I see a group as akin to a folder and the feeds as files in that folder.
Also, don't worry about the sensors as in your code. I'm changing some of them and adding some others so that is different but I understand the creation part, just not the targeting to a specific group idea.

Code: Select all

try: # if we already have the feeds, assign them.
    tvoc_feed = aio.feeds('tvoc')
    eCO2_feed = aio.feeds('eco2')
    uv_feed = aio.feeds('uv')
    temperature_feed = aio.feeds('temperature')
    humidity_feed = aio.feeds('humidity')
    pressure_feed = aio.feeds('pressure')
    altitude_feed = aio.feeds('altitude')
except RequestError: # if we don't, create and assign them.
    tvoc_feed = aio.create_feed(Feed(name='tvoc'))
    eCO2_feed = aio.create_feed(Feed(name='eco2'))
    uv_feed = aio.create_feed(Feed(name='uv'))
    temperature_feed = aio.create_feed(Feed(name='temperature'))
    humidity_feed = aio.create_feed(Feed(name='humidity'))
    pressure_feed = aio.create_feed(Feed(name='pressure'))
    altitude_feed = aio.create_feed(Feed(name='altitude'))
 

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Creating IO feeds programmatically to specific group

Post by brubell »

Instead of using create_feed, there's some group functionality in Adafruit IO Python's HTTP Client:

https://github.com/adafruit/Adafruit_IO ... nt.py#L290

However, there's a chance that the `.feeds.` method may need to be modified to take in a group so a call would be something like:

Code: Select all

pressure_feed = aio.feeds('pressure', group='weatherstation')
I use the above method call in Adafruit IO CircuitPython which was developed after Adafruit IO Python - AIO Python may not have the updated methods.

If you're interested in adding (or I can add) this type of feature - please file an issue for a feature here: https://github.com/adafruit/Adafruit_IO_Python/issues

User avatar
wsquared58
 
Posts: 229
Joined: Sun Jun 09, 2019 9:13 pm

Re: Creating IO feeds programmatically to specific group

Post by wsquared58 »

Code: Select all

pressure_feed = aio.feeds('pressure')


then becomes

Code: Select all

pressure_feed = aio.feeds('pressure', group='weatherstation')

Code: Select all

pressure_feed = aio.create_feed(Feed(name='pressure'))
then becomes??

Code: Select all

pressure_feed = aio.create_feed((Feed(name='pressure')), group='weatherstation')
That's my likely horrible attempt at creating a feed and parking it in the weatherstation group.

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Creating IO feeds programmatically to specific group

Post by brubell »

I added an issue for the Python library and will patch/release this week:
https://github.com/adafruit/Adafruit_IO ... issues/104

User avatar
wsquared58
 
Posts: 229
Joined: Sun Jun 09, 2019 9:13 pm

Re: Creating IO feeds programmatically to specific group

Post by wsquared58 »

Thank You very much.

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Creating IO feeds programmatically to specific group

Post by brubell »


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”