Partly Correct. It is not so much the "official firmware" but rather "adequate code". If you were to create a function called digitalwrite, you'd also be able to toggle it, provided your code handles it correctly. The REST API will also work with your own code, but you'll have to adjust your code/calls accordingly. If you haven't got a function digitalwrite, it becomes really hard to use it, right? All of this is described in the Tinker section of the docs, since that's the code that runs as factory firmware/reset. Over here, it explains how to Use Tinker with your own code. Here you can see examples of how to use fucntions, and call them correctly.
If you want an easy way to check what functions/ variables are available, and like to call them, you could take a look at this page I've made with the Particle JavaScript library. Just log in with your Particle credentials, and you should be good to go (I won't have access to it!) Alternatively, you could call the API directly, using this URL: api.particle.io/v1/devices/{device ID here}?access_token={access token here}
@helxsz Here is the the code to open a web page that has two buttons you can use to pass a variable to a function. You will have to substitute your function name, your device ID and your token. It works very well. If all you want to do is experiment with running a function this will do it. I’m sure you could expand the example to get variables. Thanks to @bko for this example page.
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<body>
<P><br>Toggle Digital Output Pin 0<br><br></P>
<script type="text/javascript">
var deviceID = "123YourDeviceId456";
var accessToken = "123YourAccessToken456";
var setFunc = "lightLed0"; <----- replace lightLed0 with the name referenced in particle.function
var newValue = "0";
function sparkSetLED(newValue) {
var requestURL = "https://api.spark.io/v1/devices/" +deviceID + "/" + setFunc + "/";
$.post( requestURL, { params: newValue, access_token: accessToken });
}
</script>
<button id="pushmeoff" onclick="sparkSetLED(0);">Push Me Off!</button>
<button id="pushmeon" onclick="sparkSetLED(1);">Push Me On!</button>
</body>
</html>
You are right that in a browser you cannot just type in a URL to POST to a form which is what a Particle function requires, but curl is smart about figuring out if a request should be a GET or a POST and with -d argument to curl, it will be a POST and work fine.
I’m facing the same problem. Received a Photon Wifi development kit at SOLID con last month. Trying to access the API at http://docs.particle.io/photon/tinker/#the-tinker-api-digitalwrite - get the same “function not found error”. Any idea why their own documentation isn’t working?
But, did it show the functions you were looking for, digitalwrite, and if so, were you able to call them successfully using that page? The events are irrelevant for functions/variables.
I'm not familiar with zettajs, but it appears to already support the Particle ecosystem, so there's no reason you shouldn't be able to use that, should you so desire.
Where did you try that, in a browser? Since a function call requires a POST request, that won't work, considering a browser makes GET request.
Then it is quite likely that you've got some firmware running on your device that doesn't expose any Spark.function or Spark.variable.
If you want to call digitalwrite you either have to reflash Tinker firmware, or flash your own firmware which exposes such a function, or do a factory reset, which also reverts back to Tinker.