Question on Air Quality Project

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
robboz4
 
Posts: 69
Joined: Tue Nov 20, 2012 7:01 pm

Question on Air Quality Project

Post by robboz4 »

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!

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

Re: Question on Air Quality Project

Post by adafruit_support_carter »

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.

User avatar
robboz4
 
Posts: 69
Joined: Tue Nov 20, 2012 7:01 pm

Re: Question on Air Quality Project

Post by robboz4 »

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&p ... parm2=part"

Thanks for getting back to me so quickly.

Cheers
Dave

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

Re: Question on Air Quality Project

Post by adafruit_support_carter »

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.

User avatar
robboz4
 
Posts: 69
Joined: Tue Nov 20, 2012 7:01 pm

Re: Question on Air Quality Project

Post by robboz4 »

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

Thanks again

User avatar
robboz4
 
Posts: 69
Joined: Tue Nov 20, 2012 7:01 pm

Re: Question on Air Quality Project

Post by robboz4 »

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

User avatar
robboz4
 
Posts: 69
Joined: Tue Nov 20, 2012 7:01 pm

Re: Question on Air Quality Project

Post by robboz4 »

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

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

Re: Question on Air Quality Project

Post by adafruit_support_carter »

Error code 411 = Length Required.

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

User avatar
robboz4
 
Posts: 69
Joined: Tue Nov 20, 2012 7:01 pm

Re: Question on Air Quality Project

Post by robboz4 »

But how do I calculate it in circuitpython?

Thanks

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

Re: Question on Air Quality Project

Post by adafruit_support_carter »

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

>>> msg = "hello world"
>>> len(msg)
11

User avatar
robboz4
 
Posts: 69
Joined: Tue Nov 20, 2012 7:01 pm

Re: Question on Air Quality Project

Post by robboz4 »

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

User avatar
robboz4
 
Posts: 69
Joined: Tue Nov 20, 2012 7:01 pm

Re: Question on Air Quality Project

Post by robboz4 »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”