I’m using browser side Javascript. When my code calls getAttributesForAll I don’t actually get a refresh from the spark.io web server. I know this because the firebug debug console does not show a GET happening. My code - after login, etc - looks like this:
var attributesPr = spark.getAttributesForAll();
attributesPr.then(attributesPrTrue, attributesPrFalse);
What I see is that my code goes into the attributesPrTrue function immediately. The attributes are populated, but with the same data that was available after getDevices was called; there is no update.
You can see this in action at a Spark Core control panel I’ve written. It’s a simple end-to-end example of using Javascript to play with your Spark Cores. I provide a zip with all the code you need to put it on your own site. Try it out here: Spark Javascript Control Panel
The site works today, but when your Spark Core changes to expose new functions or variables you have to refresh the page and login to Spark again. That’s obviously a drag. If I could get the refresh functions to work it would be so much better.
I haven’t heard anything about this. Is it a bug? Can I supply other information that would help you understand my problem - or my mistake?
Maybe I should ask if there are any circumstances where a call to getAttributesForAll would not actually call the spark web API to get an updated answer?
Thanks for posting! I’m not sure if this is a bug or not, but I tried to summarize the issue here:
Please feel free to add any details / concerns that I’m missing, mostly I’m just referring to this thread
I’ll probably be able to take a look at this next sprint. I’m guessing as a quick workaround, if you re-listed devices, and grabbed attributes again, you should get a fresh set, something similar to:
I hope I’m not being foolish here… The code sample you posted didn’t seem to work. I’m trying to write this in browser JavaScript, not nodeJS. Googling around it seems to me that the require(‘spark’) is a nodeJS function.
So I commented that one line out. It runs and the login works. The call to listDevices also works. But I get an error on the line core.getAttributes … TypeError: core.getAttributes is not a function.
I ran into this problem when I was doing my original work and that’s why I switched to use getAttributesForAll.
Hmm, good question! I think this example would work, but it’s possible something is wrong. Can you confirm you have cores available, and you’re not getting back an empty list? ( You can check this by grabbing the CLI and logging in, and running spark list, or by logging into the build site with the same account and clicking on ‘cores’).
I think this screen shot of the debugger shows on the right that I have a core and on the left it shows that core.getAttributes is not recognized as a function.