-
Notifications
You must be signed in to change notification settings - Fork 34
Compiler API
Coming Soon™
There are 4 main keys in the JSON request body:
- files
- format
- version
- build
files contains an array of the files to be compiled, with one record for each file. Each file is represented as a key-value array itself, with the filename key containing the filename and the content key containing the code.
For example, to represent a single file named myfile and containing the code printf(300);, its representation would be:
{"filename":"myfile","content":"printf(300);"}
and the files key would contain:
[{"filename":"myfile","content":"printf(300);"}]
format contains the output format you would like to request from the compiler. The valid options are:
-
syntax- performs a syntax check only. used for "Verify". -
object- returns an object file (.o) for your code on success -
binary- returns a base64-encoded binary file for the target device on success -
elf- returns an ELF (.elf) binary file on success -
hex- returns a hex-encoded (.hex) binary file for the target device on success
version contains the Arduino SDK version that your code will be built with. Valid options are 100, 101, 102, 103, 104 and 105 for Arduino versions 1.0.0-1.0.5 respectively.
last but not least, build contains the build parameters for the selected board configuration, which the ones found in the original boards.txt configuration files under the board_name.build.* parameters. The parameters you need to specify are:
-
mcu- processor's MCU spec -
f_cpu- processor's clock speed F_CPU spec -
core- Arduino core used for the board -
variant- variant used for the board -
vid- USB VID (optional, for Leonardo-like USB-enabled devices) -
pid- USB VID (optional, for Leonardo-like USB-enabled devices)
Here's an example of the JSON request for verifying (syntax check) a 2-file sketch for Arduino UNO.
{
"files":[
{
"filename":"hello.h",
"content":"#define HELLO"
},
{
"filename":"hello.ino",
"content":"void setup()\n{\n\tint bla, blabla = 5;\n}\n\nvoid loop()\n{\n\n}\n"
}
],
"format":"syntax",
"version":"105",
"build":{
"mcu":"atmega328p",
"f_cpu":"16000000L",
"core":"arduino",
"variant":"standard"
}
}The compiler will respond with a JSON-encoded response, which will contain some of the following keys:
-
success- mandatory -
output- used only upon successful compilation (success = true). contains the output in the requested format. -
size- used only on successful compilation. contains the size of the generated binary. -
time- used only on successful compilation and verification. Contains the time it took for the procedure to be completed. -
message- used usually when something went wrong (success = false), to notify the user (i.e. compilation error messages). The message is HTML-encoded, using html<font>tags to color-code various errors. -
step- used when something went wrong, used for debugging purposes so that we know at which step the error occurred
{
"success":false,
"step":4,
"message":"<b>hello.ino:4:6: <\/b><b><font style=\"color: red\">error: <\/font><\/b><b>cannot initialize a variable of type 'int' with an lvalue of type 'const char [8]'\n<\/b> int hello = "ehehehe";\n<b><font style=\"color: green\"> ^ ~~~~~~~~~\n<\/font><\/b>1 error generated."
}
{
"success":true,
"time":0.54590511322021
}
{
"success":true,
"time":0.65779185295105,
"size":"2758",
"output":"HUGE STRING HERE WITH BASE64 ENCODING OF BINARY AMMAGAAAAAD!!!!!11111oneoneonecos(0)=="
}