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

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?

Hi @spydrop,

I’m hoping to start a beta for the cloud after this sprint (in April). I’m bummed that I haven’t been able to release it yet, but we had a series of changes and tools we wanted to release first to make the local cloud easier to use. (CLI, making it easier to switch servers, keys, etc) – There are more details and a beta group list forming here: https://community.spark.io/t/where-is-the-source-code-for-the-cloud/1381 :slight_smile:

Thanks!
David

Despite little interest in this topic, I’ve just added support for alternative API servers (aka local cloud) and a legacy mode to my Android ExtTinkerApp.

By default the features that require ExtTinker firmware (RGB-LED & RX/TX pins) are hidden and the app behaves just like the original.
Per pin hide/reset options have been added to the pinMode display. Hide state and pinMode are stored across sessions.

Via SignUp/Login screens you can get to an “Alter Host” screen, where you can configure API URL scheme (https, http), host server name and host port. These settings are stored across sessions.

Since I have no local server (yet), I couldn’t really test if the server config actually works :wink:
Any feedback would be much appreciated.

2 Likes

I’ll be happy to test once my local cloud spins up. :wink:

@kennethlimcp, that would be great.
If you’d like an debug APK rather than having to build it yourself for testing, I could PM you a download link, just as I did for @zachary, when fileing my first PR.

@ScruffR,

great job! The enhanced Android app is working perfect with the Local :cloud:! :clap: :clap:

Some things to note:

1.) Use HTTP by default since most people are testing their local cloud on normal hardware like a laptop

2.) The default port in Local :cloud: is 8080 instead of 443

This should help most people get up and running instead of getting error messages.

Thanks!

Excited to see more cool features in future. ^^


Just wondering what does the access to TX and RX pin do?