SCRIPTs in the SPARK world

I am new to the SPARK core and so far I have found it an interesting module to use. I have followed and implemented many of the tutorials and various threads and my SPARK is happily sending temperature information from a DS18B20 to a WEB page. I am competent to dangerous with the C. I am familiar with HTML coding via a text editor but scripting languages (python, java, perl) and the use of special procedures like JSON are my weakness. It appears that to make full use of the SPARK capabilities I need to master the WEB side of the project. Gathering the data is the easy part ( a few lines of C), displaying/using the data is much more difficult for me.

Does the collective have suggestions as to where I should start reading? Is there a “SPARK and the WEB for dummies” that would allow me to read and understand what the WEB/HTML/Script portion of the tutorials are doing (almost all code published is without imbedded comments). If you were teaching a C programmer how to write scripts to interface with the SPARK how or where would you start? I realize that this is like asking how do I build a bridge but friendly pointers and suggestions are appreciated.

-Phil-

2 Likes

Hi Phil, Glad to see others who are interested in HTML/Web access and/or control of Spark Core, HOWEVER, as you search the forum you will see my many posts that request the very things you suggest.

I suggested a Dummies for Spark Core and immediately informed that a very component technical writer is working on a Spark Core book (Not a Dummies book like I want to see).

I requested the support of a Web - HTML interface and I was told best to use the officially supported method. Java API. I was told its not safe to place your access_token in a webpage. So I figured out how to place the access_token (actual) in the core IDE firmware and use a variable in an webpage but, still no support for html control of spark core. (read this thread)

@BDub has a great htlm/java web application interface called remote start you should take a look at:

The collective feels that a lot of money was invested by the “Community” to use the official way of API (Java - Android).

If a HTML web interface is used it is suggested that a PHP Proxy service be employed to conceal the access_token in curl get and post requests.

But, if you really want to get a feeling of how HTML will not be supported here read this whole topic thread:

I would be happy to collaborate with someone in developing a HTML Web Interface. I have done some work on this using HTML / Jquery → Access_token hidden in IDE Core Firmware → External java variable but, I am not a programmer of any type. I just know HTML, some css, some very basic java.

I am trying to locate some files that I was working on for another person. Let me know if you are interested in seeing my approach.

Bobby

1 Like

Hi @PKeller,

The magic keywords you need are REST API (not Java API). Any web framework or current programming language will have tutorials / libraries / support / guides for building web apps that interact with our REST Api. :slight_smile:

We are actually working on wrappers and tutorials for a bunch of popular languages, but in the meantime, the web is full of awesome tutorials.

Here’s an awesome guide @bko posted: Tutorial: Spark Variable and Function on One Web Page - Tutorials - Particle

:smile:

Thanks,
David

3 Likes

Hi Bobby,

A couple of factual inaccuracies in your statement that I’d like to point out. First, the scripts that you reference are Javascript, not Java. This is an important distinction; they are two completely separate languages, and Javascript is what basically every website uses.

It sounds like you believe that it’s odd that we don’t support plain HTML and only support Javascript, but this is a false choice; Javascript is part of the web, and just about any interaction that you have with a website these days will include Javascript. It’s simply a way to script behaviors based on your interaction with the website.

In addition, there are in fact some simple HTML interfaces, such as the ones that @Dave referenced in his articles, that have been created by the community.

Regarding concealing the access token, perhaps I should clarify here. Spark is a secure web service, and uses access tokens (like many APIs) to manage that security. These access tokens are essentially passwords to your account.

Therefore, if your application requires security, it’s important that you don’t expose your access token.

However, if your application doesn’t require any security, and you don’t mind exposing your secure credentials, then you can go ahead and share your access token. This would basically amount to treating Spark like an unsecured service. I don’t mean to sound judgey about that, for many applications it’s totally fine to use an unsecured service, and if the security is more annoying than it is helpful, then you can basically ignore it by using the access token wherever you want.

2 Likes

@spydrop I deleted your most recent post because it was confrontational and did not comply with the Spark code of conduct.

You’re welcome to re-post the same content in a more constructive manner.

Hi @PKeller,

Annnnnnywaaaaaaaay… :slight_smile: Welcome to the community! We’re here to help!

I would recommend you starting on a web development tutorial, I have been enjoying Node.js lately, but everyone has their favorites. I would try one of those tutorials I linked earlier. :slight_smile:

Thanks,
David

1 Like

Hi @PKeller

I would try this tutorial for reading a Spark variable with Javascript on web page–it is pretty easy! The key is using the jquery Javascript library to do the heavy lifting for you.

1 Like

@bko I have used your tutorials with great success. They are appreciated. The ‘problem’ I have is that the WEB side of the solution contains a lot of functionality that I do not, yet, understand. The :spark: code I understand, what and why it is doing what it is doing. The HTML code is magic. I am looking for information of how to do what you easily do. I started to read the JavaScript tutorial from W3Schools.com but life got in the way so I wont get back to that until the weekend.

@Dave I hope to also take a look at node.js and see what that does as well. Thanks.

2 Likes

@PKeller A fantastic way to learn HTML/CSS/Javascript is Codecademy!

If you like to learn by doing, they have fantastic tutorials. You can get familiar with Javascript through Codecademy because it’s used as a front-end language (to do things like define what buttons do on a website), but it’s also used as a back-end language (that’s Node.js), so it’s extremely versatile. Great place to start.

2 Likes

@zach I give them a try. Thanks.

1 Like