Python module to access your Spark Core with the Spark Cloud API and requests package

Hi there,

To test and prototype my dooropener using a Spark Core I wrote a little Python module to access the Spark Cloud API functions. I hope you like it:

Have fun and thanks for your feedback, I’m new to programming and pyhon and happy if you find misstakes or have an idea to make this module better!

News on my dooropener will come the next week(s)!

6 Likes

Hi @beklein

almost month before your SparkCloudAPI module, @Lexa made Spyrk using Hammock.

I’ve updated it a bit and came up with idea that maybe three of us could focus on one module to have full featured one? What do you think about that?
Also this is question to @Lexa if he’s up to it :slight_smile:

1 Like

Hi @suda

sounds good for me. Great contribution by the way it works fine and is easy to use (same goes to @Lexa)
I’ll link to your project in the readme file.

Thank you guys.

1 Like

Awesome! Now we just need @Lexa’s opinion :slight_smile:

Hi guys,

It’s great to see more interest into accessing a Spark core with python :).

I am totally for collaborative work on this! I did not focused much on Spyrk and the core lately, but both are still in my visor. Especially since I will start using the core for bigger projects soon :).

Fork&pull-request away! :smiley:

1 Like

Hi @beklein and @suda,
I am an Electrical Engineer at SDstate.edu, but I also love coding. I am very interested in using the library you created for python. I might join as a contributor as well.

My plan is to run python on my Raspberry Pi or on my old Android phone and then control my spark or my photons (yes, I bought two :smile:).

Let me know what you think
-Nate

Hi, Im using a photon, how different would the code look for that?

The APIs existing back then haven’t changed (or not much anyway) since then, so it should work as is IMO.
But if you find issues, it’s always best to state them as exact as possible to get help for exactly that.

import requests
import json


r = requests.post('https://api.particle.io/v1/devices/0123456789abcdef01234567/brew', data = {'access_token':'<yourAccessToken>'})
print (r.content)

OUTPUT:

runfile('H:/SKIRIPSIE/GUI CODE/fancytext.py', wdir='H:/SKIRIPSIE/GUI CODE')
b'{\n  "error": "Permission Denied",\n  "info": "I didn\'t recognize that device name or ID, try opening https://api.particle.io/v1/devices?access_token=<yourAccessToken>"\n}'

So im not accessing my photon properly?

Have you adapted the device ID for your own device and added your own access token?
0123456789abcdef01234567 is not a valid device ID, and I guess the access token you had there (before I removed it, since that should be kept secret) wasn’t yours either.