Différences entre versions de « Spark-Could-API-CoreControling »
(Page créée avec « {{Spark.IO-Could-API-NAV}} {{traduction}} == Introduction == {{bloc-etroit|text=To control a Core, you must first define and expose functions in the Core firmware. You then... ») |
|||
Ligne 39 : | Ligne 39 : | ||
This exposes the brew function so that it can be called through the API. When this code is present in the firmware, you can make this API call. | This exposes the brew function so that it can be called through the API. When this code is present in the firmware, you can make this API call. | ||
− | == Appel d'API | + | == Appel d'API == |
The API request will be routed to the Spark Core and will run your '''brew''' function. | The API request will be routed to the Spark Core and will run your '''brew''' function. | ||
Version du 7 janvier 2015 à 07:32
En cours de traduction/élaboration. |
Introduction
To control a Core, you must first define and expose functions in the Core firmware. You then call these functions remotely using the Spark Cloud API.
Note: If you have declared a function name longer than 12 characters it will be truncated to 12 characters.
Example: Spark.function("someFunction1", ...); exposes a function called someFunction and not someFunction1
Sur le Core
Let's say, as an example, you create a Spark-powered coffeemaker. Within the firmware, we might expect to see something like this brew function.
/* FIRMWARE */ int brew(String args) { // parse brew temperature and duration from args // ... activate_heating_element(temperature); start_water_pump(duration_seconds); // int status_code = ... return status_code; } /* FIRMWARE */ void setup() { Spark.function("brew", brew); }
In a normal coffeemaker, brew might be called when a button on the front of the coffeemaker is pressed.
To make this function available through the Spark Cloud, simply add a Spark.function call to your setup().
This exposes the brew function so that it can be called through the API. When this code is present in the firmware, you can make this API call.
Appel d'API
The API request will be routed to the Spark Core and will run your brew function.
The response will have a return_value key containing the integer returned by brew.
POST /v1/devices/{DEVICE_ID}/{FUNCTION}
# EXAMPLE REQUEST curl https://api.spark.io/v1/devices/0123456789abcdef01234567/brew \ -d access_token=1234123412341234123412341234123412341234 \ -d "args=202,230"
Exemple de réponse
// EXAMPLE RESPONSE { "id": "0123456789abcdef01234567", "name": "prototype99", "connected": true, "return_value": 42 }
Source: Cloud CODE (API) créé par Spark.IO.
Traduction réalisée par Meurisse D pour MCHobby.be - Translated by Meurisse D. for MCHobby.be
Traduit avec l'autorisation de Spark.IO - Translated with the permission from Spark.IO - Spark.IO
Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : « Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.
L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.