"Function not found" [SOLVED]

Hi guys i am new in this Spark and facing problem to call Tinker API functions
using curl in web

i am following the same example as in documentation
curl https://api.spark.io/v1/devices/0123456789abcdef/digitalwrite \ -d access_token=123412341234 -d params=D0,HIGH
replacing with my own access token and device id
it’s returning me

{   "ok": false,   "error": "Function digitalread not found" }

in response
any help will be appreciated…

Is your core running the tinker firmware?

You could also try discovering what your core is running with a GET request like this:

curl "https://api.spark.io/v1/devices/1234123412341234?access_token=1234123412341234123412341234123412341234"

This should return a structure like this:

{
  "id": "1234123412341234",
  "name": "your_core_name",
  "connected": true,
  "variables": {
    "variable_name_1": "var_type_like_double_etc"
  },
  "functions": ["function1"],
  "cc3000_patch_version": "1.28",
  "last_heard": "2015-05-12T00:00:00.000Z"
}

Tinker has no variables and four functions.

1 Like

it’s returning me the same structure but no variables

{
  "id": "54ff70066672524846591267",
  "name": "keyless_project",
  "connected": true,
  "variables": {},
  "functions": [],
  "cc3000_patch_version": "1.29",
  "last_heard": "2015-05-11T21:00:40.063Z"
}

I have to ask: have you flashed new code to your device, or is this a factory state Core running the Tinker firmware? Looking at your response, I’ve got feeling the original Tinker firmware is no longer running. If you’ve got your own code running on it, might you be able to share it here so we can take a look at it?

1 Like

i am not using my own code i am just sending the post request by curl
i am following this documentation http://docs.spark.io/tinker. as i said i am new in this not have much knowledge about spark api i don’t know i am going right or wrong my motive is to make functionality same as in Spark app

@shahzaib,

The default tinker app has declared the digitalread Spark.function in order for it to work.

If you are using your own firmware and did not so do, it will not work.

The best way is for you to load the default tinker firmware via Spark-cli or DFU-util and try out the API call :wink:

@ kennethlimcp is it possible to call digitalread using node.js library ?

Well, let’s give this a try first, to see if your firmware, the stuff running on your Core, is okay; Could you try logging in here, and checking whether or not it displays any functions for your Core? If so, you could try entering a valid argument in the function box, and try to call it. Checking if they show up in the first place is more important though, so do that first.

You don’t call the “digitalRead” from a language, you call the REST API. Almost every programming language can do that, and node.js is certainly one of them.
But rather than worrying about what language to use, you should first get the basic functionality working. From there on, you can expand.

Just to emphasize what the other elites have told you, this indicates that you are not running firmware on your core that will talk to the cloud in a meaningful way. A factory reset will reload Tinker and there will be four functions that you can use.

1 Like

@bko
Thanks Really appreciated it’s working after reset all four functions are included Thanks a lot :smile:

what does means return -2 in response?
{
“id”: “54ff70066672524846591267”,
“last_app”: “”,
“connected”: true,
“return_value”: -2
}

Hi @shahzaib

In this case it means that your request was not formatted properly and it is returning an error. In general the return integer values are decided by the programmer. Your request to Tinker typically requires the first character to be a “D” or and “A”.

Here is where to see the code:

https://github.com/spark/firmware/blob/master/src/application.cpp#L65