0

Question on Air Quality Project
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Question on Air Quality Project

by robboz4 on Sun Jul 25, 2021 6:06 pm

Is there a tutorial or description of how to send the data collected in this project to my own web page for display? I'd like to share the data with the neighbors on our local website. I was thinking of sending the data as parameters and having a php file receive the data and display it. For example
my.website.com?temp=arg1&humid=arg2&part=arg3

Not sure how to encode that with the library routines. I searched through current examples I couldn't find an exact project


Thanks!

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

Re: Question on Air Quality Project

by adafruit_support_carter on Mon Jul 26, 2021 2:20 pm

Which specific project are you working with? Can you link the the guide.

In general, you'd need something that could connect to wifi and the internet. Then you could use something like MQTT to send out the data. Could also use Adafruit IO.

adafruit_support_carter
 
Posts: 21061
Joined: Tue Nov 29, 2016 2:45 pm

Re: Question on Air Quality Project

by robboz4 on Mon Jul 26, 2021 5:25 pm

Hi!

I have successful built this project:

https://learn.adafruit.com/air-quality- ... silo-house

And the the dashboard on IO reflects temp, humidity, particle and long, lat values. What I'd like to do is send those values from the feather to another site. I looked at the code in the project that help set up Wi-Fi and I wondered if added that to the code now running on the feather I could send to both sites.
In the file "first-wifi-test.py" there are a couple of "GET" requests to Adafruit. Could I use that syntax with a "PUT" to my website?
<<Code snippets>>

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
.
.
.
.
print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
<end of code snippet>>

Would using the feather with two different HTTP methods one to adafruit IO and one to http site cause issues?
for example:

TEXT_URL = "http://mysite.com/data.php?parm0=temp&parm1=humd&parm2=part"

Thanks for getting back to me so quickly.

Cheers
Dave

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

Re: Question on Air Quality Project

by adafruit_support_carter on Mon Jul 26, 2021 5:37 pm

Something like that should be doable. Look at some of the examples in the ESP32SPI library:
https://github.com/adafruit/Adafruit_Ci ... n/examples
That's the library that interfaces with the ESP32 on the AirLift FeatherWing. Checkout the TCP and UDP examples as possible approaches. You'll have to know how to set things up on the server side, on whatever is hosting your webpage.

adafruit_support_carter
 
Posts: 21061
Joined: Tue Nov 29, 2016 2:45 pm

Re: Question on Air Quality Project

by robboz4 on Mon Jul 26, 2021 5:51 pm

Thanks I'll check that out. I have the server side understood OK, it was just the sending of the data.

Thanks again

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

Re: Question on Air Quality Project

by robboz4 on Thu Jul 29, 2021 2:58 pm

Thanks the example link, that was just what I needed. I now have the values posted to my web site as well as the IO dashboard.

Thanks for the continued great support!

Cheers

Dave

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

Re: Question on Air Quality Project

by robboz4 on Mon Aug 02, 2021 5:50 pm

I get this error when I try to publish to my site hosted at Yahoo:

411
and of course data is not written to the server. Dumping out the full return code I get this:


{'_remaining': 277, '_headers': {'Server': 'ATS', 'Date': 'Mon, 02 Aug 2021 21:32:52 GMT', 'Content-Type': 'text/html', 'Content-Language': 'en', 'Connection': 'keep-alive', 'Cache-Control': 'no-store', 'Content-Length': '277'}, '_received_length': 9, '_chunked': False, '_cached': None, '_backwards_compatible': True, 'encoding': 'utf-8', 'socket': <_FakeSSLSocket object at 20008fb0>, '_session': <Session object at 200039f0>, 'status_code': 411, '_raw': None, '_receive_buffer': bytearray(b'<HTML>\n<H<HL>\n<H277\r\n\r\n<HTML>\n<H'), 'reason': bytearray(b'Content Length Required')}

Is the "Content_Length" is this message the return from Yahoo? If yes, how do I encode the content length in my outgoing message?
Is it the length of my php parameters (?temp=100 etc)? In which case I can calculate the length of the string and then append a header field containing the

headers={"Content-Length": "25"}

If not how do I work out the content length?
As I said earlier it is working on my local Pi Apache2 implementation just fine.

Thanks

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

Re: Question on Air Quality Project

by adafruit_support_carter on Mon Aug 02, 2021 6:08 pm

Error code 411 = Length Required.

You need to add "Content-Length" to the headers you're sending to Yahoo.

adafruit_support_carter
 
Posts: 21061
Joined: Tue Nov 29, 2016 2:45 pm

Re: Question on Air Quality Project

by robboz4 on Mon Aug 02, 2021 7:13 pm

But how do I calculate it in circuitpython?

Thanks

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

Re: Question on Air Quality Project

by adafruit_support_carter on Mon Aug 02, 2021 7:50 pm

It's the size of the message body in bytes. Depends on how you are building up the message body. But could maybe try len()?
Code: Select all | TOGGLE FULL SIZE
>>> msg = "hello world"
>>> len(msg)
11

adafruit_support_carter
 
Posts: 21061
Joined: Tue Nov 29, 2016 2:45 pm

Re: Question on Air Quality Project

by robboz4 on Mon Aug 02, 2021 8:50 pm

Thanks I worked that bit out :-)

But what is the message content. Is it:

1) https://mywebsite/test.php?parm=1&parm2=2

or

2) ?parm=1&parm2=2

I'm still searching through the internet to find an answer I can use.

Cheers

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

Re: Question on Air Quality Project

by robboz4 on Tue Aug 03, 2021 7:39 pm

I solved it a different way. I used

r = wifi.get("myweb_site" + payload)

The server does not do a "content_length" check on a GET only on a POST.

Cheers

Dave

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

Please be positive and constructive with your questions and comments.