adafruit / Adafruit_CircuitPython_PyPortal

CircuitPython driver for Adafruit PyPortal.
MIT License
45 stars 56 forks source link

Added ability to pass ESP and SPI objects. #33

Closed ChewyTurtle closed 5 years ago

ChewyTurtle commented 5 years ago

I needed the ability to use the wifi connection before calling adafruit_pyportal.py to do required Application authorization for Twitter's API. Their API requires an access token from a POST request which I get so I can send adafruit_pyportal.py the GET url with the correct access token in the headers.

I'm here with you guys at pycon if that helps.

ladyada commented 5 years ago

hiya please update to remvoe the version-change, that line is autogenned :)

@brentru wanna take a look?

On Wed, May 8, 2019 at 11:50 AM Zach Heshelman notifications@github.com wrote:

I needed the ability to use the wifi connection before calling adafruit_pyportal.py to do required Application authorization for Twitter's API. Their API requires an access token from a POST request which I get so I can send adafruit_pyportal.py the GET url with the correct access token in the headers.

I'm here with you guys at pycon if that helps.

You can view, comment on, or merge this pull request online at:

https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/pull/33 Commit Summary

  • Added ability to pass ESP and SPI objects. Needed to use Wifi before calling pyportal to do required qpplication authorization for twitters API

File Changes

Patch Links:

- https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/pull/33.patch

https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/pull/33.diff

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/pull/33, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJINULTROSCP2C2C7EIYWTPULZDJANCNFSM4HLS7GOA .

ChewyTurtle commented 5 years ago

I tried to fix the version. I hope I did it right.

ladyada commented 5 years ago

do you ever use spi? i think you just need to pass in the esp!

ChewyTurtle commented 5 years ago

Yeah, at least I think so. I used spi to define esp before calling the pyportal object. I tried doing it without passing spi but the script failed when it tried to look for the SD card.

ladyada commented 5 years ago

oh right yah its used for SD access

brentru commented 5 years ago

@ChewyTurtle Heya, the build is failing, see the travis log for details - let me know if you have any Q's: https://travis-ci.com/adafruit/Adafruit_CircuitPython_PyPortal/builds/111126972#L293

ChewyTurtle commented 5 years ago

@brentru I think I fixed the issues from the build failing. I haven't seen that format before but it looked like it was mostly spacing issues. I removed the extra white space and fixed the indentation level. Hopefully that is what was needed. Let me know if it's something else!

brentru commented 5 years ago

Looks good, merging in!

ChewyTurtle commented 5 years ago

Twitter required a specific keyword be in the body. I defined the keyword and it’s value as a string and then passed it with in the get function with the data keyword.

You’ll see my Authorization is in the same format as your example.

POST_DATA = 'grant_type=client_credentials' TWITTER_POST_URL = 'https://api.twitter.com/oauth2/token' HEADERS_POST = {
'Host' : 'api.twitter.com', 'User-Agent' : 'PyPortal Twitter Application', 'Authorization' : 'Basic ' + secrets['encode_api_key_secret'], 'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8', 'Accept-Encoding' : 'none',
}

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp32, secrets, status_light)

response = wifi.post(TWITTER_POST_URL, data=POST_DATA, headers=HEADERS_POST)

I’ll be posting my script so far on my GitHub shortly. I’m wanting to make a library, but now that I’m back in the real world I have less time. Hopefully I can work on the library more this weekend.

I hope this helps

Zach

Sent from Mail for Windows 10

From: Ari Braginsky Sent: Tuesday, May 14, 2019 12:33 PM To: adafruit/Adafruit_CircuitPython_PyPortal Cc: Zach Heshelman; Mention Subject: Re: [adafruit/Adafruit_CircuitPython_PyPortal] Added ability to passESP and SPI objects. (#33)

@ChewyTurtle I had a similar requirement where I needed to be able to pass a basic authorization header for my image URL. Is the format of the headers parameter expecting something like the following? HEADERS = {"Authorization":"Basic "} — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.