ImportError: no module named 'Adafruit_IO.Client'

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
CorbeauCat
 
Posts: 28
Joined: Sun May 13, 2018 7:42 pm

ImportError: no module named 'Adafruit_IO.Client'

Post by CorbeauCat »

I am trying to create an Adafruit IO feed that will receive data from an scd30 CO2 monitor. I added the adafruit_io folder in the lib in the ESP32-S3 TFT Reverse Feather, and pip installed it. I still keep getting "ImportError: no module named 'Adafruit_IO.Client'" everytime I run. I recently installed CircuitPython so I am sure it is the latest version. It's also telling me that Feed and RequestError are unused.

Here is the code:

Code: Select all

import time
import board
import busio
import adafruit_scd30
from Adafruit_IO import Client, Feed, RequestError

ADAFRUIT_IO_KEY = "aio_key"
ADAFRUIT_IO_USERNAME = "aio_username"

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
i2c = busio.I2C(board.SCL, board.SDA, frequency=50000)
scd = adafruit_scd30.SCD30(i2c)

while True:

    if scd.data_available:
        print("Data Available!")
        print("CO2: %d PPM" % scd.CO2)
    time.sleep(0.5)

CO2_data = scd.CO2

print("CO2:", CO2_data)
aio.send("scd-30-co2-monitor", CO2_data)
time.sleep(10)

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by dastels »

You code isn't using Feed or RequestError, so that's why it's complaining.

As for the import, your code doesn't jive with the code in the bundle. Where did you get it or the instructions?

Did you update your libraries as well? I suggest deleting everything in CIRCUITPY/lib, emptying trash, and copying the latest version into CIRCUITPY/lib.

Dave

User avatar
CorbeauCat
 
Posts: 28
Joined: Sun May 13, 2018 7:42 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by CorbeauCat »

I adapted the code from the Iot Pool monitor project code.

I did clean it up a bit:

Code: Select all

import time
import board
import busio
import adafruit_scd30
from Adafruit_IO import Client, Feed, RequestError

ADAFRUIT_IO_KEY = "aio_key"
ADAFRUIT_IO_USERNAME = "aio_username"

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

try: 
    CO2_data = aio.feeds("scd-30-co2-monitor")
except RequestError: 
    CO2_data = aio.create_feed(Feed(name="scd-30-co2-monitor"))

i2c = busio.I2C(board.SCL, board.SDA)

scd = adafruit_scd30.SCD30(i2c)

while True:
    if scd.data_available:
        print("Data Available!")
        print("CO2: %d PPM" % scd.CO2)
    time.sleep(0.5)

CO2_data = scd.CO2

print("CO2:", CO2_data)
aio.send("scd-30-co2-monitor", CO2_data)
time.sleep(10)
I am still getting the same error. I do have adafruit_io the folder from the CircuitPython 8 library and did pip install Adafruit_io, and also uninstalled and re-installed it. Are there some other files and folders I might be missing?

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by dastels »

Iot Pool monitor project code
And where can I find that?

The root of the problem is that the code you are writing and basing it on is for CPython, not CircuitPython. There are examples here: https://github.com/adafruit/Adafruit_Ci ... n/examples.

Dave

User avatar
CorbeauCat
 
Posts: 28
Joined: Sun May 13, 2018 7:42 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by CorbeauCat »

It wasn’t the pool monitor actually it was this one: https://learn.adafruit.com/adafruit-io- ... ython-code

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by dastels »

OK. That is for CPython (i.e. Python on Linux, MacOS, Windows, etc), not Circuitpython.

Dave

User avatar
CorbeauCat
 
Posts: 28
Joined: Sun May 13, 2018 7:42 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by CorbeauCat »

It says CircuitPython. So how would I convert it to CitcuitPython?

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by dastels »

But you say you want to run the code on a ESP32-S3 TFT Reverse Feather, not a Raspberry Pi. On the Pi you have CPython, on the Feather you have CircuitPython. Things get a bit weird on the Pi if you use Blinka whch basically pretends to sort of be CircuitPython. Short story: if you want to run on the Feather, you need to use CircuitPython and libraries from the CircuitPython bundle. See https://learn.adafruit.com/welcome-to-a ... dafruit-io and linked guides to learn more about using Adafruit IO with CircuitPython. It'll be a little different since your code will be running on an ESP32 MCU, and not using an AirLift (which is an ESP32 as a Wifi coprocessor).

Dave

User avatar
CorbeauCat
 
Posts: 28
Joined: Sun May 13, 2018 7:42 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by CorbeauCat »

I changed the code to be more like the examples:

Code: Select all

import time

# import adafruit library for SCD30 CO2 monitor.
import adafruit_scd30

# import Adafruit IO REST client.
from Adafruit_IO import Client, Feed

# Delay in-between sensor readings, in seconds.
SENSOR_READ_TIMEOUT = 5

# Set to your Adafruit IO key and username.
ADAFRUIT_IO_KEY = "YOUR_AIO_KEY"
ADAFRUIT_IO_USERNAME = "YOUR_AIO_USERNAME"

# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

# Set up SCD30 CO2 Monitor.
scd30 = adafruit_scd30.SCD30()

while True:
    if scd30.data_available:
        co2_ppm = scd30.CO2
        print("CO2: {} ppm".format(co2_ppm))
        # Send CO2 feed to Adafruit IO
        aio.send("scd-30-co2-monitor", str(co2_ppm))
    else:
        print("Failed reading, trying again in {} seconds".format(SENSOR_READ_TIMEOUT))

    time.sleep(SENSOR_READ_TIMEOUT)
But I still get the same error. I did try using the Adafruit_IO folder from Adafruit_IO_Python_master but instead I got:
File "/lib/Adafruit_IO/__init__.py", line 21, in <module>
File "/lib/Adafruit_IO/client.py", line 24, in <module>
ImportError: no module named 'platform'

The Adafruit_io folder I am using is the one from the CircuitPython 8 bundle.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by dastels »

I still think your problem is confusion between running on the Pi and running on the Feather, and having the appropriate libraries available. Get that figured out. You need to use the Pi to write the code and the Feather to run it.

Dave

User avatar
CorbeauCat
 
Posts: 28
Joined: Sun May 13, 2018 7:42 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by CorbeauCat »

I am using Mu editor.

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: ImportError: no module named 'Adafruit_IO.Client'

Post by dastels »

That's not relevant. It's just for editing the code.

The libraries are different for CPython and CircuitPython. You need to use the correct one for CircuitPython.

Dave

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”