Ligne 1 : |
Ligne 1 : |
| {{Spark.IO-Could-API-NAV}} | | {{Spark.IO-Could-API-NAV}} |
− |
| |
− | {{traduction}}
| |
| | | |
| == Introduction == | | == Introduction == |
− | {{bloc-etroit|text=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. | + | {{bloc-etroit|text=Pour controler un Core, vous devez d'abord définir et exposer des fonctions dans le firmware du Core. Ensuite, vous pouvez appeler ces fonctions à distance en utilisant l'API Spark Cloud. |
| | | |
− | Note: If you have declared a function name longer than 12 characters it {{underline|will be truncated}} to 12 characters. | + | Note: Si vous avez déclaré une fonction dont le nom est supérieur à 12 charactères, le nom {{underline|sera tronqué}} à 12 charactères. |
| | | |
− | Example: Spark.function("someFunction1", ...); exposes a function called '''someFunction''' and not '''someFunction1'''}}
| + | Exemple: Spark.function("someFunction1", ...); expose une fonction nommée '''someFunction''' et non '''someFunction1'''}} |
| | | |
| == Sur le Core == | | == 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.
| + | Disons, par exemple, que nous avons créé une machine à café contrôlé par Spark Core. Dans le firmware, nous devrions trouver une fonction '''brew''' (''faire infuser''). |
| | | |
| <nowiki>/* FIRMWARE */ | | <nowiki>/* FIRMWARE */ |
| int brew(String args) | | int brew(String args) |
| { | | { |
− | // parse brew temperature and duration from args | + | // parser la température d'infusion et la durée depuis args |
| // ... | | // ... |
| | | |
− | activate_heating_element(temperature); | + | activater_resistance_chauffante(temperature); |
− | start_water_pump(duration_seconds); | + | demarrer_pompe_eau(duration_seconds); |
| | | |
| // int status_code = ... | | // int status_code = ... |
Ligne 33 : |
Ligne 31 : |
| | | |
| | | |
− | In a normal coffeemaker, '''brew''' might be called when a button on the front of the coffeemaker is pressed.
| + | Dans une machine à caffé, '''brew''' (''faire infuser'') devrait normalement être appelé lorsque le bouton est pressé sur la machine. |
| | | |
− | To make this function available through the Spark Cloud, simply add a '''Spark.function''' call to your '''setup()'''.
| + | Pour rendre cette fonction disponible par l'intermédiaire du Spark Clound, ajoutez simplement l'appel à '''Spark.function''' dans la fonction '''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.
| + | Cela expose la fonction ''brew'' de façon a pouvoir l'appeler via l'API. Lorsque ce code est présent dans le firmware, vous pouvez faire des appels d'API. |
| | | |
− | == Appel d'API === | + | == Appel d'API == |
− | The API request will be routed to the Spark Core and will run your '''brew''' function.
| + | La requête d'API sera redirigé vers votre Spark Core et exécutera votre fonction '''brew'''. |
| | | |
− | The response will have a '''return_value''' key containing the integer returned by '''brew'''.
| + | La réponse contiendra une clé '''return_value''' contenant la valeur entière (int) retournée par '''brew'''. |
| | | |
| POST /v1/devices/{DEVICE_ID}/{FUNCTION} | | POST /v1/devices/{DEVICE_ID}/{FUNCTION} |
| | | |
| <nowiki> | | <nowiki> |
− | # EXAMPLE REQUEST | + | # Exemple de requête |
| curl https://api.spark.io/v1/devices/0123456789abcdef01234567/brew \ | | curl https://api.spark.io/v1/devices/0123456789abcdef01234567/brew \ |
| -d access_token=1234123412341234123412341234123412341234 \ | | -d access_token=1234123412341234123412341234123412341234 \ |
Ligne 54 : |
Ligne 52 : |
| Exemple de réponse | | Exemple de réponse |
| | | |
− | <nowiki>// EXAMPLE RESPONSE | + | <nowiki>{ |
− | { | |
| "id": "0123456789abcdef01234567", | | "id": "0123456789abcdef01234567", |
| "name": "prototype99", | | "name": "prototype99", |