Remote Spark Web App

This is it so far...

Weather Station

2 Likes

I know this thread has somewhat died, but I am all of a sudden having trouble with this web app. It was correctly working for me last Sunday, but for some reason is no longer working and I cannot seem to figure out why. I am using it for something simple and very similar to @PaulRB’s Weather Station; just using it to call some Spark.variable()s, which should be simple enough. The Remote-Spark code is generally unchanged, except for substituting my access token, my coreID, and variables that I am trying to retrieve. And, like I previously mentioned, this was working for me last weekend, but is not now. Is anyone else (that is using this code) experiencing similar problems?

FWIW, the Spark-Helper app is working just fine to call my Spark.variable()s, so I am totally stumped as to why Spark-Helper works but Remote-Spark does not. Any direction would be greatly appreciated.

Hi @kherman,

If you’re having trouble using an API helper, or the web IDE, make sure your access token hasn’t changed since the last time you used it. Sometimes it’s also helpful to refresh the web IDE page, or log out and back in.

Otherwise, what kind of errors are you seeing? We also removed “TEMPORARY_allTypes” from the variable return format, so it’s possible this code is expecting that to be present.

Thanks!
David

Hi @Dave

I did make sure that my access token had not changed; I even re-copy/pasted it directly from the Spark IDE as part of my troubleshooting. I have refreshed the page, restarted, and even tried 3 different browsers (IE, Chrome, and Comodo Dragon), in both Remote-Spark and Spark-Helper.

I don’t receive any errors at all from Remote-Spark API, just ‘—’ in the respective variable boxes (which I believe means that it’s not getting anything back).

I think you just identified the issue with the “TEMPORARY_allTypes” because, yes, the Remote-Spark code does use it. See below. I suppose I should try to hack the Spark-Helper API then, unless you have another workaround? The web app is rather important to my intended application (and web development is definitely not my strong area), so it’s kind of a requirement to use a website based API.

        function getVariable(variable, callback) {
      var url = baseURL + coreID + "/" + variable + "?access_token=" + accessToken;
      $.ajax({
        url: url,
        dataType: "json"
      }).success(function(obj) {
        console.log(obj);
        (obj.coreInfo.deviceID && obj.coreInfo.deviceID == coreID) ? onMethodSuccess() : onMethodFailure((obj.error)?obj.error:"");
        callback(obj.TEMPORARY_allTypes.number);
      }).fail(function(obj) {
        onMethodFailure();
      });
    }
1 Like

Yeah sorry about that! It’s on my backlog list to update my repos, honest!

1 Like

In the meantime it's just a matter of replacing:

obj.TEMPORARY_allTypes.number

with something like:

obj.result

Thanks @BDub! Sorry we didn't give more notice about that change!

1 Like

@BDub awesome! You already rock for putting up your Remote-Spark so we can all benefit from it in each of our projects! Your efforts are already GREATLY appreciated. At least I know now I’m not going crazy…

@Dave thanks for the quick solution. I will replace while also try to explore the reasoning. I’m in the process of trying to add jQuery to my toolchest of knowledge, so I’m sure that understanding will be helpful to me in the future.

1 Like

Thanks! You’re welcome @kherman

and… Remote-Spark repo updated. However I think there is a problem with reading variables right now, so I can’t confirm it’s working. @Dave do you see this as well? Functions seem to work fine, but no joy on variables. I’m getting:

{
  cmd: "VarReturn"
  name: "read"
  error: {
    error: "Variable not found"
  }
  coreInfo: {
    last_app: ""
    last_heard: "2014-01-24T22:29:17.530Z"
    connected: true
    deviceID: "xxxxxxxx"
  }
}

Hey @BDub,

Hmm, that error message is something new we added, but it should only show up when that variable isn’t available. Can you check your core’s info page and see what it returns?

https://api.spark.io/v1/devices/your_device_id?access_token=your_access_token

Thanks!
David

Here’s the code I’m running (which has been known good up til now):

And here’s the info page output:

{
  "id": "xxxxxx",
  "name": "Technobly1",
  "variables": [],
  "functions": [
    "start",
    "trunk",
    "lock",
    "unlock"
  ]
}

However, if I run this program:

// Create a variable that will store the temperature value
int temperature = 0;
bool state = 0;

void setup()
{
  // Register a Spark variable here
  Spark.variable("temp", &temperature, INT);
  Spark.function("toggle", toggleLED);

  // Connect the temperature sensor to A0 and configure it
  // to be an input
  pinMode(A0, INPUT);
  pinMode(D7, OUTPUT);
}

void loop()
{
  // Keep reading the temperature so when we make an API
  // call to read its value, we have the latest one
  temperature = analogRead(A0);
}

int toggleLED (String args) {
    state = !state;
    digitalWrite(D7,state);
}

Variables are working and I get this on my info page:

{
  "id": "xxxxx",
  "name": "Technobly1",
  "variables": {
    "temp": "int32"
  },
  "functions": [
    "toggle"
  ]
}

Hmm, I just flashed your code to a Core with no changes, and here’s my output:

{
  "id": "50ff70065067545628100587",
  "name": "second-run",
  "variables": {
    "startstate": "int32",
    "trunkstate": "int32",
    "lockstate": "int32"
  },
  "functions": [
    "start",
    "trunk",
    "lock",
    "unlock"
  ]
}

so it looks like it’s working for me… are you sure yours flashed correctly?

No, I’m not sure! :smile: But it did flash, and reboot and connect to the cloud again. So it either worked, or it didn’t and reverted supposedly? I’ll try it at home here now and report back.

EDIT: Of course it’s working now… -_- Not sure what went wrong or how to correct it though. :confounded:

BTW:

{
  "btw": "234523457545628100587",
  "don\'t": "aaaaaaaa",
  "think": {
    "i": "int32",
    "didn\'t"": "int32",
    "notice": "int32"
  },
  "your": [
    "fancy",
    "syntax",
    "highlighting"
  ]
}

Damn straight. I guess we’ll just pretend this little bug never happened, then…

:wink: let us know if you run into it again

Thanks @Dave, that woked for my Weather Station page (updated).

1 Like

Hi,

Does anyone have a clue about how to get the data from an slider out of the HTML type=“range” to the spark code analogWrite in THIS example?

Thanks,

Max

1 Like

@Max2 I would think you just need to bind a hook to the Mouse Up state to read your slider value, and if it’s different than the last call, send the new value to the Spark. You don’t want to be sending values as soon as they change because it would send way to many requests to the Cloud at once.

Just for Reference:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_input_type_range

Mouse Up:
http://api.jquery.com/mouseup/

There are probably even a million ways to do this with JQuery UI type stuff, but I kind of like the simplicity of the Range element. Let us know how it works out for you!

1 Like

Hello,

I want to do a better visualization of the measured temperature. For it would be great to use these gauges.
ww.justgage.com
Does anyone know how to integrate these gauge in the application?
I want instead of the text-box to display the value in these gauges.
Does anybody can write a simple example?

1 Like

Those are cool gauges @developer_bt :slight_smile: They are just simple javascript arc type stuff… the example HTML files that it comes with shows you how to use them if you look at the code in the HTML files. I’m currently creating an example with the Remote Spark app to use the gauges. We’ll see how it turns out!

3 Likes

Hello @BDub!
It’s really excellent!
:smiley:

I got something going, just working out the bugs… and the Sparkulator is particularly slow today… so that’s not helping.