I have the following code running on an Electron (0.5.1) …
int PIN_LED = D0;
void setup() {
pinMode( PIN_LED, OUTPUT );
Particle.function( "led", led );
}
void loop() {;}
int led( String value ) {
int state = value.toInt();
if( state == 1 ) {
digitalWrite( PIN_LED, HIGH );
} else if( state == 0 ) {
digitalWrite( PIN_LED, LOW );
}
return 1;
}
Using the CLI I am trying to call the “led” function. Using “particle list” on the CLI, I can see that the Electron has registered the function. When I invoke the function using the CLI …
particle call ABC123 led "1"
… I always get a return value of “-1”. Per my code above, there should be no way to return anything other than “1”. This makes me think there is some problem in calling the function. Any ideas as to what that problem might be?
Appreciate the extra eyes,
Kevin
Could you try the same using this page to rule out any issues with the CLI?
http://suda.github.io/particle-web-interface/
Alternatively, try changing your function name to make sure your code gets flashed successfully.
Give it a shot and let us know
Huh,
I changed the function from “led” to “light” along the lines of …
Particle.function( "light", light );
...
int light( String value ) { ... }
So it looks like the code is not getting flashed successfully. I am editing in the online IDE, then clicking the cloud icon to download “firmware.bin”. Then I put the Electron in listening mode (blinking blue). Finally, using the CLI I run “particle flash --serial firmware.bin”. Everything seems to go fine. There are no errors. The Electron restarts and connects to the network.
Am I missing something on getting my code onto the Electron?
Thanks,
Kevin
1 Like
Okay,
I just tried this using the Particle Dev tool, and the new code was flashed, and I was able to call the function. So it looks like a bug (?) in downloading from the cloud IDE?
Checking that the new code was flashed by changing the name was a great tip - thanks!
Kevin
1 Like
I like to expose a “version” Cloud variable which I increment each flash
1 Like
One common mistake when that happens is that the target was not set correctly for the Electron and/or the correct system version.
The “bad” thing with particle flash --serial firmware.bin
is that it doesn’t inform you about the incompatibility, the code just doesn’t stick.
If you try particle flash --usb firmware.bin
(providing you have got dfu_util installed and your device in DFU mode), you should get a more elaborate information about the root cause.
And for building you won’t need Dev, you could also use
particle compile electron <yourProjectFolder> --safeTo firmware.bin