Différences entre versions de « Spark-Could-API-FirmwareCheckAndFlash »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
(Page créée avec « {{Spark.IO-Could-API-NAV}} {{traduction}} {{Spark.IO-Could-API-TRAILER}} »)
 
Ligne 2 : Ligne 2 :
  
 
{{traduction}}
 
{{traduction}}
 +
 +
== Vérifier et flasher un nouveau Firmware ==
 +
 +
{{bloc-etroit|text=All your Spark firmware coding can happen entirely in the build section of the website. However, if you prefer to use your own text editor or IDE, you can! It just means that instead of hitting the "Flash" or "Verify" buttons, you'll make API calls that reference a file.}}
 +
 +
== Flasher un Core avec du Code Source ==
 +
{{bloc-etroit|text=If you have written a source code file that defines setup() and loop() functions, you can flash it to your Spark Core with an HTTP PUT request.}}
 +
 +
<nowiki># HTTP REQUEST DEFINITION
 +
PUT /v1/devices/{DEVICE_ID}
 +
Content-Type: multipart/form-data
 +
 +
Send the source code file as "file" in request body.</nowiki>
 +
 +
The API request should be encoded as multipart/form-data with a file field populated. Your filename does not matter. In particular, the extension can be .c, .cpp, .ino, or anything else your prefer.
 +
 +
This API request will submit your firmware to be compiled into a Spark binary, after which, if compilation was successful, the binary will be flashed to your Core wirelessly.
 +
 +
<nowiki># EXAMPLE REQUEST IN TERMINAL
 +
# Flash a Core with a file called "my-firmware-app.cpp"
 +
curl -X PUT -F file=@my-firmware-app.cpp \
 +
  "https://api.spark.io/v1/devices/0123456789abcdef01234567?access_token=1234123412341234123412341234123412341234"</nowiki>
 +
 +
There are three possible response formats:
 +
* A successful response, in which both compilation and flashing succeed.
 +
** Note that the LED on your Core will blink magenta while updating.
 +
* A failure due to compilation errors.
 +
* A failure due to inability to transmit the binary to the core.
 +
 +
<nowiki>// EXAMPLE SUCCESSFUL RESPONSE
 +
{
 +
  "ok": true,
 +
  "firmware_binary_id": "12345"
 +
}
 +
 +
// EXAMPLE COMPILE FAILURE RESPONSE
 +
{
 +
  "ok": false,
 +
  "errors": ["Compile error"],
 +
  "output": ".... lots of debug output from the compiler..."
 +
}
 +
 +
// EXAMPLE FLASH FAILURE RESPONSE
 +
{
 +
  "ok": false,
 +
  "firmware_binary_id": "1234567",
 +
  "errors": ["Device is not connected."]
 +
}</nowiki>
 +
 +
== Flasher un Core avec un binaire pre-compilé ==
 +
If you want to compile the firmware yourself and send a binary instead of a source file, you can do that too! Just add file_type=binary to the request body, and we will skip the compilation stage altogether. The response format will look like those shown above.
 +
 +
<nowiki># EXAMPLE REQUEST IN TERMINAL TO FLASH A BINARY
 +
curl -X PUT -F file=@my-firmware-app.bin -F file_type=binary \
 +
  "https://api.spark.io/v1/devices/0123456789abcdef01234567?access_token=1234123412341234123412341234123412341234"</nowiki>
  
 
{{Spark.IO-Could-API-TRAILER}}
 
{{Spark.IO-Could-API-TRAILER}}

Version du 11 janvier 2015 à 16:03


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Vérifier et flasher un nouveau Firmware

All your Spark firmware coding can happen entirely in the build section of the website. However, if you prefer to use your own text editor or IDE, you can! It just means that instead of hitting the "Flash" or "Verify" buttons, you'll make API calls that reference a file.

Flasher un Core avec du Code Source

If you have written a source code file that defines setup() and loop() functions, you can flash it to your Spark Core with an HTTP PUT request.

# HTTP REQUEST DEFINITION
PUT /v1/devices/{DEVICE_ID}
Content-Type: multipart/form-data

Send the source code file as "file" in request body.

The API request should be encoded as multipart/form-data with a file field populated. Your filename does not matter. In particular, the extension can be .c, .cpp, .ino, or anything else your prefer.

This API request will submit your firmware to be compiled into a Spark binary, after which, if compilation was successful, the binary will be flashed to your Core wirelessly.

# EXAMPLE REQUEST IN TERMINAL
# Flash a Core with a file called "my-firmware-app.cpp"
curl -X PUT -F file=@my-firmware-app.cpp \
  "https://api.spark.io/v1/devices/0123456789abcdef01234567?access_token=1234123412341234123412341234123412341234"

There are three possible response formats:

  • A successful response, in which both compilation and flashing succeed.
    • Note that the LED on your Core will blink magenta while updating.
  • A failure due to compilation errors.
  • A failure due to inability to transmit the binary to the core.
// EXAMPLE SUCCESSFUL RESPONSE
{
  "ok": true,
  "firmware_binary_id": "12345"
}

// EXAMPLE COMPILE FAILURE RESPONSE
{
  "ok": false,
  "errors": ["Compile error"],
  "output": ".... lots of debug output from the compiler..."
}

// EXAMPLE FLASH FAILURE RESPONSE
{
  "ok": false,
  "firmware_binary_id": "1234567",
  "errors": ["Device is not connected."]
}

Flasher un Core avec un binaire pre-compilé

If you want to compile the firmware yourself and send a binary instead of a source file, you can do that too! Just add file_type=binary to the request body, and we will skip the compilation stage altogether. The response format will look like those shown above.

# EXAMPLE REQUEST IN TERMINAL TO FLASH A BINARY
curl -X PUT -F file=@my-firmware-app.bin -F file_type=binary \
  "https://api.spark.io/v1/devices/0123456789abcdef01234567?access_token=1234123412341234123412341234123412341234"

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.