Tasker Control of Spark Core for Automation of Electronic Devices

Hi everybody, so I have been using Tasker and my Spark Core for a while, but I only recently realized the HTTP POST task in Tasker meant I could send a message from my phone to my Core.

In short, set up a profile event/state/location/etc. to trigger an HTTP POST task. Then enter:

Server:Port
https://api.spark.io
Path
/v1/devices/your_device_ID/params?access_token=your_access_token
Data/File
a=whatever_string_your_firmware_expects_exposed_function_to_see_less_than_char_max
Leave other fields as default unless a special need arises.

Right now I have a Neopixel strip wired to my Core and can turn the LEDs off when I turn my phone display off in a specific orientation, and can turn it back on by waving the phone back and forth with the display on. In the future I’d like to add a widget to my phone to control things “directly”, like selecting one of a few modes or brightness levels. I’d also like to add a shimmering light effect that is dependent on the magnetic sensor output from the phone, or one of the other sensors.

This should work for any device/peripheral that can talk to the Core, either OTA or over wires.

Thanks to users Rehaan, kennethlimcp, bko, and hypnopompia for helping me finally get this up and running.

6 Likes

Awesome!, thanks for sharing @Elijah.

Would you provide a link to the app please? Thanks!

@Bdub, please find the links.

Google Play link https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm,
Home Page: http://tasker.dinglisch.net/

2 Likes

Yes, it is the app from dinglisch.net and it is $5 from the Google app store (if I remember correctly).

Also, a huge huge huge thanks to everyone on the Spark team and who has worked with them to make the Spark Core. I’m kind of blown away how easy it is to get things to talk to each other!

4 Likes

So here is a gif of the lamp I’ve got going on, (or there would be, but the site is telling me my 1,394kB gif is above the 2,048kB limit) Instead it’s here on imgur.

It takes the magnetic field reading from my phone as a random seed for the animation. The Core calculates a random set of brightness values for the LEDs and then a 2D smoothing convolution is run over the numbers a couple of times. I set the colors to be complementary and animate linearly from current state to the next state.

Next up will be to attach a spectrum analyzer shield to use frequency data to drive the animation (also to provide interactivity with a mic attached), more fine grained control using my phone and browser, and ideally a way to stream animations directly to the core to free up memory and allow for more complex rendering before display.

Cheers!

1 Like

Thanks for sharing this post. I am using sinc e 2 years Tasker. I have a lot task in tasker.

  1. When i came to home my computer and desk automaticly open.
  2. When i came to work it is sen sms automaticly my wife.
  3. Also i have nfc tag useing with trigger and task.

Nice to see someone use tasker. :)))

2 Likes

this is a great idea! i use tasker for a bunch of stuff. great thought to tie in a spark controlled device. might have to tie some cool BLE beacons into the mix…

@Elijah
Have been meaning to get more into tasker, this is cool.

Do you have code that you are willing to share so we can see examples how everything is handled?

Thanks!

The Tasker UI is fully graphical and I imagine you could make some really interesting apps that interact with real world objects with Android scripting! Here are some screen shots that illustrate the context and tasks I set up to toggle presets when I raise and lower my phone twice.

Here I added a “Gesture” event context and named it “Toggle Colorsll”


Tapping on this event context brings up an edit menu where I can add a name as well as the gesture itself. The orange circle brings up a menu with ‘preferences’.


In the preferences menu are a number of options for the accelerometer, including a calibration sequence. You’ll probably need to do this at least once to get settings that allow for simple gestures that don’t get confused with other motions.


In the first image you can see two green arrows pointing at two tasks named “Increment Colors” and “Spark On”. Tapping on "Increment colors brings up the Task Edit screen where I can add sub-tasks, like Popup (pops up a window), and Variable Set.


Editing the Variable Set task allows me to change the value of a variable (all variable names have ‘%’ character preceding them) according to logical conditions. Tapping the ‘=’ sign will bring up options like ‘greater than’, tapping the gray ‘Or’ will bring up options like ‘And’, and ‘Xor’. Checking the ‘do maths’ box tells Tasker to add 1 to the value stored in %Col_sel, rather than setting it equal to the string “%Col_sel + 1”.


Finally, the HTTP Post task. Set the server:port to https://api.spark.io (default port is fine). Then set the path to “your_exposed_function_hook?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”. Then set the Data/File part to “a=string_formatted_as_your_function_expects”. Note that the ‘a=’ part is nearly any short string, like args=, params=, xyz=.

And that’s it! Now when I lower my phone and raise it up a couple times it sets the col_sel variable and sends the new variable to my Spark Core with HTTP Post and my Neopixels go into a different preset.

One caveat, at least for me, sending HTTP POST through Tasker is slower than sending it say with javascript on a webpage, so don’t be surprised if it’s not quite like flipping a light switch.

1 Like

Do you know if it is possible to publish from the spark core to your Tasker app.

Lets say you had a temperature sensor on your spark core and you wanted tasker to pop up a reminder on your phone when the temperature got too hot?

Hi @gberm,

It is possible, the tricky part will be getting the HTTP GET request to format properly in Tasker.

Check out the section “Reading data from the core” here: http://docs.spark.io/api/

Thank you for your response.

For now I am trying to get your example above working with an instructable project I am adapting(still learning) http://www.instructables.com/id/SparkCore-Fireplace-Lighting/?ALLSTEPS

Two things I am trying to figure out is what to use for params and what to put in the Data file.

Lets say I have
Spark.function(“setColor”, setColor);
Spark.function(“setMode”, setMode);
Spark.variable(“mode”, &mode, STRING);
Spark.variable(“red”, &red, INT);

Which would be the params and what should be put in the Data/File line

In tasker I keep getting input/output error and Java.io file not found exception.

Any help would be really appreciated.

Alright I think I figured it out

Path
/v1/devices/your_device_ID/setMode?access_token=your_access_token
Data/File
mode=chase

Now is it possible to set multiple functions at once? Or can each post only use one Spark.function() at a time.

Out of Curiosity does anyone know if Tasker will allow you to retrieve the access token from particle.io if the post fails due to wrong access token and update automatically and renew access by signon information perhaps. I would like to create a way for mostly continuous operation with minimal input. Thanks

Since accesstokens don’t expire anymore (by default), there should be no reason to renew them.

Really? When did that happen? I missed that info. I’ve been busy trying to brush up on programming. Well thats great news for me. I imagine that we can reset our access token whenever we would like to - is that correct?

Thanks So Much!!

It’s been quite a while since that change. It’s actually mentioned in the web IDE when you check your access token. There’s a little exclamation mark.

1 Like