particle-iot / android-app

Spark Android App
https://www.spark.io/
Other
91 stars 60 forks source link

example of calling a function and a variable #8

Open RolfHut opened 9 years ago

RolfHut commented 9 years ago

I am trying to change the app to not work with the tinker firmware, but with my own firmware, which has different functions and variables made available to the cloud. However: in the app, the whole idea that this works towards tinker, and the idea of working with pins is very hard (for me...) to separate from the clean API.

Can anyone give me a short tutorial / example on how to: -add a button on the main screen that calls a function on my core. (I got this working, but hacked a lot to get there, not a "clean" solution. -add a button that, when clicked, gets a variable (String in my case) from the Core and displays it. This is the hard part for me: how to configure the different Receivers etc.

mind you: this is my first android app that I am working on, so don't be to harsh... thanks

Rolf

blackcj commented 9 years ago

I'd recommend interfacing directly with the Spark Core Rest API rather than trying to use this project as a base. You could use a library like Retrofit to quickly build out the API interface for Android.

http://square.github.io/retrofit/ http://docs.spark.io/api/

I've been meaning to do something similar for one of my own projects. I'll post code to my GitHub account when I get something up and running.

RolfHut commented 9 years ago

Hi blackcj,

I use this app as a base for two reasons:

My main concern (after another night of hacking, learning and searching on stackOverFlow) is that ApiFacade.java is really geared toward the tinker firmware running on the Core. I would like for that to change into two files: one with the general ApiFacade and one with all the tinker implementation. I am working on that, but since I am not a pro-andriod dev, I guess my ducttape-y solution will not be up to standard to merge into this repo. Will publish whatever I did though. Any help is much appreciated, mainly in handling the receiver side.

RolfHut commented 9 years ago

Hi all,

I made two versions of this app:

  1. an empty version. I removed everything that points to the tinker-app and to pins from the central fragment and activities, except for the name "fragment_tinker" (I did leave some stuff in the supporting files). I added stuff to the ApiFacade which makes it (a lot) easier to do api call from the central fragment.
  2. a version that implements a thermostat app. It assumes a specific firmware running on your core. This is build on the version I mention above.

I have two questions:

  1. How to share this with the world? I would really like to publish it in the play-store, can I do that? (legally?) It would be a great example that you can build a business model on the spark, including the app, without having to build a lot yourself. Furthermore, I would like to share the code, but 99% is equal to the original app. I could only publish the changed files on my github account, or the entire app. I do not think a pull-request would be a good idea: that would create diversion between the iOS and Android app.
  2. Can anyone explain me how to change the reflash function in the ApiFacade such that it uploads a file that is part of the app? (Can I even do that? I believe I have to make a file-pointer in the args-bundle, but have no clue how to...)

If questioning why I'm going to such lengths: I write a monthly column in a dutch national Newspaper (De Volkskrant) on technology you can apply in your own home. I wrote a piece on the sprak before and wanted to delve a bit deeper for my piece on oktober 18th.

thanks in advance

Rolf

towynlin commented 9 years ago

Hi Rolf,

Thanks so much for creating this proof of concept! I look forward to your column—please let us know when it's published.

You can see in the LICENSE file that this repository is distributed under the Apache License, Version 2.0. Here's the full text of the license, and here's the TL;DR version. The license of an open source project is always the official source for what you can and can't do; the Apache 2 license allows a great deal of freedom. :wink:

You can (if you otherwise satisfy the license) distribute your app in the Play Store. I think the best way to distribute the source is to create an open source github fork repository—not for the purposes of creating pull requests, but simply as an easy way to show where the code came from and what you changed.

Cheers!

RolfHut commented 9 years ago

Hi Zach,

thanks for your clarification! release date for the article in the newspaper is october 18th. Will be all in Dutch though... (I may ask a native speaker friend of mine to make a nice translation and put that on my website).

I uploaded my version of the code to https://github.com/RolfHut/SCAT. I will be uploading never versions as I clean stuff up, but this is the version I got working and also pushed to the play store. Please contact me if there are any issues that I need to change, I have done everything in good faith, but legal is not my strong point (let alone US legal...)

with respect to my second question: any idea how I can flash firmware from within the app, where the firmware is hosted in the app, not in the cloud? The API has support for this, but I have no clue as to how to link to a file in an argument bundle (if that is even possible).

thanks again,

Rolf Hut

towynlin commented 9 years ago

As you say, the API supports flashing a binary. Docs here: http://docs.spark.io/api/#verifying-and-flashing-new-firmware-flash-a-core-with-a-pre-compiled-binary

I just did a quick Google search for "android http upload file" and got this example as the first search result: http://androidexample.com/Upload_File_To_Server_-_Android_Example/index.php?view=article_discription&aid=83&aaid=106

pedropombeiro commented 9 years ago

Hi @RolfHut. I too am building my first Android app in order to control the Spark Core. In case you're still interested in ways to control it using REST, I've implemented a Retrofit interface for it. It makes the API very easy and concise. You can see it in a blog post of mine, and look at the full source on my GitHub repo.

RolfHut commented 9 years ago

Hi @PombeirP

looks interesting! I will check it out!

Rolf

kretes commented 9 years ago

This would be really great if app has additional screen for 'variables', 'events' and 'functions' that one could operate on. I want to use this app as a simple mission control for my spark-enabled thing, and as a workaround I am going to connect D1 to D2 with a wire, digitalWrite to D1 with this app, read D2 on the core to give myself control over the logic with this app.