Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

IoT Air Quality Sensor with Adafruit IO Example Not working
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

IoT Air Quality Sensor with Adafruit IO Example Not working

by mdede on Mon Nov 23, 2020 9:24 pm

I have been trying to replicate the IoT Air Quality Sensor with Adafruit IO project and I am having issues getting the code to work. I was successful testing the PMS5003 sensor, the BME280 sensor, and the ESP32 Airlift Feather wing to operate independently however when I try to incorporate everything and use the supplied code to send data to Adafruit.IO I get this outout:

AQI: 0
Category: Good
Sampling environmental sensor...
Temperature: 76.9 F
Humidity: 25.3 %
Publishing to Adafruit IO...
Traceback (most recent call last):
File "code.py", line 198, in <module>
File "code.py", line 189, in <module>
File "adafruit_io/adafruit_io.py", line 579, in send_data
File "adafruit_io/adafruit_io.py", line 496, in _create_data
TypeError: tuple indices must be integers, not str

Code done running. Waiting for reload.

It looks like everything works up to the point it wants to publish to Adafruit.IO. Any ideas? I tried to follow everything in the design of the hardware so I am confused why the code would not just work.

Lines 189 and 198 of the code are listed below. It looks like there is an issue in the adafruit.io library, but I find that hard to believe.

188: try:
189: io.send_data(feed_aqi["key"], str(aqi), location_metadata)
190: io.send_data(feed_aqi_category["key"], aqi_category)
191: io.send_data(feed_temperature["key"], str(temperature))
192: io.send_data(feed_humidity["key"], str(humidity))
193: print("Published!")
194: except (ValueError, RuntimeError) as e:
195: print("Failed to send data to IO, retrying\n", e)
196: wifi.reset()
197: wifi.connect()
198: continue
199: # Reset timer
200: elapsed_minutes = 0
201: time.sleep(30)

Any help would be much appreciated. Thanks.

mdede
 
Posts: 9
Joined: Sat Jan 19, 2019 9:04 pm

Re: IoT Air Quality Sensor with Adafruit IO Example Not work

by millercommamatt on Tue Nov 24, 2020 4:09 pm

Is the code snippet the exact code you're using? Seeing the full code will help so that we can see what's being passed to the problematic function.

Regardless, check the data types of the inputs.

millercommamatt
 
Posts: 636
Joined: Tue Jul 31, 2018 4:57 pm

Re: IoT Air Quality Sensor with Adafruit IO Example Not work

by mdede on Wed Nov 25, 2020 5:34 pm

The full code is at https://learn.adafruit.com/pages/20830/ ... d?type=zip However, I was able to get it fixed. I am not sure how Ruiz Brothers got his project to work with the code he uploaded because of the errors I found in the code.

First in the Secrets file AIOUSERNAME was specified but the code uses AIOUSER. This was a simple fix, but still.

And line "189: io.send_data(feed_aqi["key"], str(aqi), location_metadata)" the "location_metadata" variable was causing my error. I removed it and everything works. Again I have no idea how the original project ever worked unless the wrong example code was uploaded.

Thanks for reaching out, I appreciate the effort!

mdede
 
Posts: 9
Joined: Sat Jan 19, 2019 9:04 pm

Re: IoT Air Quality Sensor with Adafruit IO Example Not work

by robboz4 on Thu Jan 14, 2021 7:45 pm

I hit the same problem. So thank you for the quick fix. However, I have a question. How do you get your long/lat passed to the dashboard? I think that was part of the learning guide, but no real information was given on how to do that. I have the map widget on the dashboard, but of course I'm not sending the data due to this error. I tried adding str around the value but that gave the same error. So somewhere in the library there is a routine that should accept the long/lat values and allow them to be posted.

I'll keep digging, but if any one knows the answer that would help.


Cheers

robboz4
 
Posts: 59
Joined: Tue Nov 20, 2012 7:01 pm

Re: IoT Air Quality Sensor with Adafruit IO Example Not work

by brubell on Mon Mar 01, 2021 1:37 pm

Hi, we've updated the Adafruit IO CircuitPython library and the library's code.

Please download the latest version of the Adafruit IO CircuitPython library:
https://github.com/adafruit/Adafruit_Ci ... O/releases


Then, replace the code.py on your CIRCUITPY drive with the updated code:
https://github.com/adafruit/Adafruit_Le ... ty/code.py

Let me know if this works for you!

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

Re: IoT Air Quality Sensor with Adafruit IO Example Not work

by robboz4 on Fri Mar 05, 2021 2:21 pm

Just wanted to let the original poster know that the new libray fixes the issue and the map widget refers the location you have in your secret file.

robboz4
 
Posts: 59
Joined: Tue Nov 20, 2012 7:01 pm

Re: IoT Air Quality Sensor with Adafruit IO Example Not work

by brubell on Mon Mar 15, 2021 9:40 am

robboz4 wrote:Just wanted to let the original poster know that the new libray fixes the issue and the map widget refers the location you have in your secret file.

Thanks for confirming!

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

Please be positive and constructive with your questions and comments.