Flashing your core from command line

Hey,

I’m having trouble flashing my core from the command line. I’ve created a file named basiclock.ino
The code within the files compiles properly, since i tested it on the web IDE. however, when i try to send it to the spark over cURL, i get a flashing yellow/green light…

here is the command im using (sensitive ID and Token replaced)…and typo fixed

curl -X PUT -F file=@basiclock.ino
https://api.spark.io/v1/devices/MYDEVICEID?access_token=MYACCESSTOKEN

has anyone successfully gotten firmware updating working over cURL? id like to build a sublime plugin!

The file name at the beginning states a name of basiclock.ino

Yet your cURL states a name of basiclock.cpp

Should the file names not be the same? Sorry I dont have a spark so I am attempting tobhelp with what I can whilst waiting for it to arrive :slight_smile:

sorry, that was a typo. i tried with both filenames (the contents are identical). will update my original post. but that was a good catch!

the problem still exists…

Is there any feedback given from the cURL? For example stating if the file was uploaded correctly?

yes. i get back

{
“id”: “MYDEVICEID”,
“status”: “Update started”
}

and then im back at the command line

Ok. So how big is the actual file its uploading? It might sound daft but their may be a limit on it which the main programming api has

its small.
855 bytes

its basically the servo example…

So that removes it being a size issue, and the core not recieving the file or atleast most of it. It still isnt clear if some of the file is perhaps getting lost in transit and rhats why it is failing

Or perhaps there are certain headers or background text added to the firmware what we are unaware of

i thought it was file locking, so i closed the tab in sublime. still no luck…

but when i made the file an empty setup() and loop() function, it seemed to work. interesting

i can tell you one thing, factory reset works like a charm :wink:

So the core will only accept files with a setup and loop function? Interesting

Just letting you know that I had the same issue. It appears my code was invalid, so it just kept flashing green without warning or whatsoever. Validating it in the web IDE let me find my issue: a file needs the setup and loop function, and to be able to use Spark functions, you need to add an int variable at the top. Kind of a prototype.

Nope, I can’t seem to get it to work via the curl method.

Hi @Quagh,

This may not apply, but for anyone getting started, make sure you checkout the annotated examples and the core firmware reference:

http://docs.spark.io/#/firmware

or checkout the resources page for more info: https://www.spark.io/resources

Thanks!
David

I tried flashing via curl from the command line and I have the same problem. It lights up magenta just like it always does while flashing, but then it flashes yellow continuously. This even happened when I uploaded the following bare minimum sketch:

void setup() {}
void loop () {}

with the following command:

curl -X PUT -F file=@blank.cpp https://api.spark.io/v1/devices/$SPARK_CORE_DEVICE_ID?access_token=$SPARK_CORE_ACCESS_TOKEN

I am trying to write a vim function to upload my sketches with a leader command. Does anyone know where this is documented? This thread is the only reference I’ve found to the ability to upload via curl.

Thanks for your quick reply, @Dave. Unfortunately, after many tries, it still doesn’t work via curl. The same code via the web IDE works without flaws and the flashing goes from magenta to green to cyan as expected. Calls to functions in my code work too. So there must be something going on that shouldn’t? The green flashing refers to the internet connection, right? Maybe it resets the SSID and password?

Also, only a factory reset and inputting my credentials make my Core work again. And additionally, I get none of the expected responses. Just this, same as @avidan:

{
"id": "ID",
"status": "Update started"
}

@adamzaninovich, see https://github.com/spark/docs/blob/master/docs/api.md#flash-a-core-with-source-code for a short explanation on the topic.

1 Like

Hi @Quagh,

Ahh, sorry, my bad, I think I misunderstood earlier. It looks like the easy endpoint for flashing source directly to your core isn’t behaving as expected. You can still do a “PUT” to /v1/devices/your_core_id with a file, but it needs to be a compiled binary at the moment, and not a source file. I’m guessing the cores are dropping to yellow after the flash because the cloud is diligently flashing text right onto your core… :blush:

Thank you for bringing this to my attention, I’ll see if I can’t fix this this weekend, and get you a working example.

Thanks,
David

2 Likes

Has this issue been resolved. I am also trying to flash a plain text .ino file via the curl method detailed above

curl -X PUT -F file=@/absolute/path/to/file.ino “https://api.spark.io/v1/devices/device_id?access_token=access_token

I am inserting the correct device id and access token. I am able to use the API to access functions and variables exposed to the cloud so I know my device id and access token are correct.

I have tried changing the URL to my server to verify the file contents are properly sent via the PUT method.

From api.spark.io I am getting an empty reply back and the core is unchanged, never flashes magenta or any other colors.

Hi @goseese,

Yes this endpoint should be working normally, I would recommend trying putting the file with the spark-cli ( https://github.com/spark/spark-cli )

spark flash my_device_id file.ino 

Also make sure your core is online and breathing cyan before flashing, or try a factory reset if you think your firmware might be blocking a flash.

Thanks!
David