pimoroni / EnviroPlus-FeatherWing

CircuitPython library for the Enviro+ FeatherWing
https://shop.pimoroni.com/products/enviro-plus-featherwing
MIT License
10 stars 11 forks source link

Adafruit IO Integration #13

Closed dedSyn4ps3 closed 3 years ago

dedSyn4ps3 commented 3 years ago

### I've been meaning to share this forever!!!

For the Enviro Plus Python repo, I know instead of approving the pull request, you guys just added the link to my repository on the README page. I would very much like to add my contribution for the featherwing version as well if at all possible. I love these little guys!

I feel like there are many more individuals out there who would like to get use from the display locally, and still be able to monitor and log their data remotely while anywhere else. After finally getting the change to add the files to my repo, I just wanted to share them with anyone that may have been looking for this type of example!

Gadgetoid commented 3 years ago

This is great, thank you!

Is there any documented precedent set for using secrets.py in lieu of setting environment variables or requesting some out-of-tree setup? I ask because keeping secrets in a source-controlled file is guaranteed to trip someone up and cause them to accidentally check in their private API data sooner or later.

Every method I think to make setting up secrets.py easier for end-users without this trap wouldn't translate well to CircuitPython...

I guess the sensible approach is to:

  1. add some info to the import trap telling people to explicitly create secrets.py
  2. add some comments at the top of tempdisplay_aio.py explaining the secrets.py format.
  3. add secrets.py to .gitignore
dedSyn4ps3 commented 3 years ago

Thank you for the quick feedback, much appreciated! I've went ahead and added the secrets.py file to .gitignore and added instructions in tempdisplay_aio.py for users to create their own secrets file locally with the format to do so. All changes have been committed and pushed!

dglaude commented 3 years ago

Sorry, I am unable to test this as I could not locate my AirLift FeatherWing...

I believe this kind of example could be transformed into a learn guide on Adafruit system, in that case the code and ressource would be put into this repository: https://github.com/adafruit/Adafruit_Learning_System_Guides or it could be on a separate repository too (I don't know what is the policy about complex example that require multiple board) sometime such example have a dedicate sub-folder with their own readme and all the file they need, just to avoid frustration when discovering you need more hardware for those.

The benefit of the learn guide is to reuse the page explaining Adafruit IO, how to deal with the secret.py file and so one.

There is a caveat in that your code does not use the particule sensor... because it is pin incompatible with the AirLift FeatherWing. I hope that can be lifted in the future when ESP32S2 board will be available in Feather format.

Also doing quick read, I figured that you may not want to refresh every second on the AdafruitIO side, the free version is limited in the number of data you update per period of time. I can think of a system where the screen as update every second, but the cloud as an update every 10 seconds or every minute... not sure if it need to be an average or the instantaneous value.

Anyway, you should be warned that there is a lot of work going on with the Circuit Python driver, and maybe some API would change just a little... but this kind of piece of code would celebrate the collaborative work between Pimoroni and Adafruit. So if you wish I would lobby to have this as a learn guide, you could do it, or we can convince someone from Adafruit to do it, or I could volonteer to do that too.

Anyway, thank your for your code.

But first I need to find my Feather Wing AirLift.

Full Disclosure: I am not working for Adafruit, nor am I working for Pimoroni... I am just a customer.

dedSyn4ps3 commented 3 years ago

Having a learning guide would certainly be awesome! They have always been a first go-to whenever I have gotten a new board of theirs, or an idea to try something out. The same can be said for Pimoroni's tutorials that I have read through as well, especially in regards to both Enviro+ boards. I think a lot of makers would benefit from something like that for sure! I work two jobs and am in the process of finishing two different degrees, so needless to say I'm rather busy to write a guide myself. That being said, if there was some way of getting it done I would greatly appreciate the group effort!

I realized from the start that this was a rather gigantic (or feather-gigantic?) project, mainly because of the incorporation of multiple boards all at once. I still at least wanted to try and share my project with everyone after working on it for some time and getting it to consistently run well. As for the sensor read timing, I did run into rate-limiting on my free AIO account when I first started testing versions of the code. I guess I chose the somewhat lazy route by just increasing the sleep time in the main loop, which ends up allowing it to run non-stop with no rate limiting for a free-tier account.

Gadgetoid commented 3 years ago

A subfolder plus a separate README.md would certainly be a good idea for this particular example @dglaude

I think it's this complexity which prevented a similar example being merged into the Enviro+ repository- however I think we can merge this and handle moving it and adding the supporting text while the Enviro+ FeatherWing repo is being reshuffled and reworked (since there will, no doubt, be other code changes required and if we don't merge and take responsibility for those, this code will very quickly go stale).

I'm all for an Adafruit learning example that combines out products! But I think it's worth having this code merged here, too, so it's discoverable.

@dedSyn4ps3 thank you for making the requested changes!

Gadgetoid commented 3 years ago

Tested and working!

For some reason I ran into a "SCK in use" error until I power cycled the board. I guess this is a CircuitPython issue and not an example issue.

code.py output:
Traceback (most recent call last):
  File "code.py", line 88, in <module>
ValueError: SCK in use

Looks like I have data feeding into Adafruit IO, and it wasn't too difficult.

Honestly the biggest hurdle seems to be finding the correct library files in the huge library bundle. It's really fiddly! I wonder if there's an easier way. I'll aim to document them either way.

Thanks all! I'll merge and we can go from there!

Gadgetoid commented 3 years ago

I have moved this code into a contrib folder and included a README documenting the setup- https://github.com/pimoroni/EnviroPlus-FeatherWing/tree/master/examples/contrib/adafruit_io

dedSyn4ps3 commented 3 years ago

Awesome thank you! The SCK issue seems to have something to do with initializing everything and is something I rarely encountered at first. Like you noted, its easily solved with a quick power cycle. Hope others can use the code well!

On Tue, Aug 18, 2020, 8:34 AM Philip Howard notifications@github.com wrote:

I have moved this code into a contrib folder and included a README documenting the setup- https://github.com/pimoroni/EnviroPlus-FeatherWing/tree/master/examples/contrib/adafruit_io

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pimoroni/EnviroPlus-FeatherWing/pull/13#issuecomment-675451265, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL4DF425SWSSWXGJZJ6HYSTSBJYO7ANCNFSM4P7CD36Q .