Extended Android Spark Tinker App (RGB LED & RX/TX pins, configurable API server)

Thanks @zachary for open sourcing :spark: android-app.
It was a good incentive and a precious entry point for me to get my local toolchain and an Android IDE (both with Eclipse) up and running on my tablet :wink:

As a first output of this Iā€™ve extended your Spark Tinker app and the Tinker FW a bit so that the Coreā€™s RX/TX pins can be digitalRead/digitalWritten and also the RGB-LED got its dedicated controls

And this would be the required Tinker Firmware (works together with standard Tinker App, too - Android and iOS)

7 Likes

@ScruffR very cool - also loving your modified Tinker logo :slight_smile:

Thanks @zach!

If youā€™d like Iā€™d clean this up a bit and ā€œfileā€ a pull request - providing the adapted Tinker FW meets your standards and could make it into your application.cpp.

ScruffR,

I would love to see a howto on this project!

Looks awesome so far!

Canā€™t wait to see the finalized product, best of luck!

Thanks @chrisnet and @DanielBernard :wink: :blush:
Actually 99% of the credits has to go to :spark: for their own app - my humble contribution to this is that I changed the tinker_fragment.xml to accomodate the extra pins and LED symbol, to add some event listeners and tweak the analog output when selecting a color.
Together with a slightly tweaked Tinker firmware thatā€™s all it needed.

So Iā€™m not quite sure what @chrisnet more info I could give as ā€œHowToā€. If you could specify what youā€™d be interested in in particular, Iā€™d be happy to share my admittedly little insight :wink:

As for the finalized version, Iā€™m near the finishing line and would appreciate any volunteers for testing it.

Just filed a PullRequest for the android-app - hope itā€™ll be accepted.
To actually have it work with your Core, youā€™d need the provided firmware (for link see first post - filed PR for that too).

Edit: ExtTinker firmware works together with standard Tinker App, too.

Next possible extension might be to incorporate the camera of the phone to acquire some color that could get transmitted to the Core which sets the RGB-LED accordingly :wink:

1 Like

@ScruffR Thatā€™s sweet! Love the dedicated RGB LED controllerā€“brings us back to the days when Spark used to be a connected lighting company :smile:

1 Like

Cheers @will :smiley:

Obviously there must be something about light that gets peoples attention (which is true for me at least ;- ) - great job you put that RGB-LED on the Core to start with.

And what goes around comes around :wink: :wine_glass: in a positive way, too.

1 Like

Please post here if your forked Tinker App gets approved for use. As far as How to. I have very little understanding with Java / Android API but, have been developing PHP / HTML for years as well as interfacing Arduino pin control via HTML.

Is there no way to access the Spark Core except via the Cloud API ? If so, how are hardware guys going to implement Spark Core control - ā€œHire a Software Guyā€ ?

Hi @spydrop,
glad to hear that there is some interest in this little project of mine :blush:

As for controlling the Core, how did you do it with the Arduinos?
Since the :spark: firmware sports TCP & UDP classes in addition to the Cloud API you should be able to do pritty much the same things as with Arduino + WiFi shield (I guess) - despite some possible ā€œchildhoodā€ glitches :wink:
The Cloud API should actually make things easier than building your own TCP/UDP logic.

And for wired control there should be no problem what so ever.

1 Like

The Arduino ethernet library allows me to use HTML links to control pins inside a local network. Here is the code I am using on one Ethernet Shield. It is also possible with the Wireless library as well. I am just looking for a simple user interface to control pins on a spark core inside a local network for my customers to use.

https://github.com/spydrop/magicstop/blob/master/arduion_html_pin_control

Hi again,
as said in the other thread this can be done.
Have a look at TCPClient - not sure how stable this is at the moment (? @Dave, @zach, @satishgn ?)
The side effect of this would be that you loose cloud API support - unless you take care of Spark.connect()/Spark.disconnect()-ing yourself.

@spydrop The :spark: core has the TCPclient/TCPserver capabilities and your existing code can be rewritten to be used on the core.

You can PM me if you need some offline help to get it running :smiley:

Unfortunately my Pull Request didn't get pulled, since it doesn't fit :spark: design standards and would create a gap between Android and iOS app functionality *) - that's fair enough.

The other reason that it would make the app harder to understand for beginners I can't quite follow.

However, if someone likes to test the app (APK) before taking up the task of building locally, just send my a PM.


*) years later that doesn't seem to matter anymore as we now do have multiple discrepancies between iOS and Android which won't fix anytime soon.

So, from what I gather is Spark Team has no intentions to support any HTML, or Java, or PHP, or Python control of the Spark Core via the cloud. Only Android & iOS are official options ?

@spydrop, I would not say that.
As you have seen there are several threads dealing with different ways to use the cloud to communicate with the Core - and the cloud is the official way, no matter what system you use on your side.

As I understand it, the Android and iOS Tinker apps together with the standard Tinker firmware are merely a nice and easy sample application to get playing a bit - to unpack your fresh Core, plug it in and immediatel see that it works - and this via the Internet.

For me the Android app was a nice entry point into Android programing - I hadnā€™t done any real project before, just some ā€œHello Worldā€ :wink:

1 Like

@ScruffR

I agree but, maybe you can help me with curl to control more than one Digital Pin at the same time ?

Here is my real life example: with the help of others @Dave @kennethlimcp @BDub @bko & YOU as I copied code from your extended Tinker App. Using PHP & Curl to execute it from my browser.

SPARK IDE APP


#define MAGICSTOP_EVENT "MagicStopEvent";

void setup() {
	//Register all the Tinker functions

	Spark.function("digitalwrite", magicstopDigitalWrite);

}

void loop() {

}

int magicstopDigitalWrite(String command) {

	bool value = 0;

	int pinNumber = command.charAt(1) - '0';

	if (!(
	((command.startsWith("D"))
	&& 0 <= pinNumber && pinNumber <= 7)
	
	))
		return -1;

	if (command.substring(3, 7) == "HIGH")
		value = 1;
	else if (command.substring(3, 6) == "LOW")
		value = 0;
	else
		return -1;

	pinMode(pinNumber, OUTPUT);
	digitalWrite(pinNumber, value);

	return value;
}

<PHP CODE + CURL----ā€¦>


<?php

        $post_params['D7'] = 'HIGH';
        $post_params['D6'] = 'LOW';

        $ch = curl_init("https://api.spark.io/v1/devices/48ff6f065067555028091087/digitalwrite");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=my_access_token_here&params=$post_params");
        $output = curl_exec($ch);      
        curl_close($ch);
        echo $output;

___________________________________

**Above PHP Does not work - Access token not found.**

**Below PHP does work but, only one pin is controlled.**

__________________________________

<?php

        $ch = curl_init("https://api.spark.io/v1/devices/48ff6f065067555028091087/digitalwrite");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=my_access_token_here&params=D7,HIGH");
        $output = curl_exec($ch);      
        curl_close($ch);
        echo $output;

?>

I and 95% of people who use micro-controllers are not programmers but, I am trying.

Thanks,

Bobby

Hi @spydrop,

You can definitely update more than one pin at a time with a function. @ScruffR is right, and Tinker is meant to be a great starting point for your own custom applications, both on and off the Core. If youā€™re writing a PHP app, then this could also be a good time to write your own firmware for the core as well! :slight_smile:

A good starting place for controlling one or more pins from a custom function would be the controlling leds over the net example here: http://docs.spark.io/#/examples/control-leds-over-the-net

Thanks!
David

@Dave Thanks for your reply.

Do you know when the Cloud Software will be available for the community to bring up their own clouds?