Spark.function() not registering properly

I’m having issues with Spark.function(). Even with the default “Controlling an LED from the net” sample it’s not working. I call:

Spark.function(“led”, ledToggle);

The project builds and flashes just fine, and I can confirm that the program gets initialized properly on my Photon.

Symptoms:

  • Calling the web function over HTTP GET or POST returns a 404.
  • Calling Particle call 0000000000000000 led on (with the ID properly populated) returns this:

Token error: Function led not found
Function call failed Function led not found

  • From the CLI, typing particle function list shows 0 functions on my Photon (or any other device)

I’ve tried to reset the access token, reflash the photon many times, use a different device (core), connect to a different Wi-Fi network, nothing works. The photon connects to Wi-Fi just fine, I can flash it just fine, but Spark.function doesn’t seem to do anything.

Your help is appreciated. Thanks.

Can you share your code? Can you also flash tinker to the device and verify the tinker functions appear in particle list. Thanks :slight_smile:

Hi @ActiveNick

Did you login to the particle CLI commands? See th doc here:

https://docs.particle.io/reference/cli/#particle-login

@mdma: At this point even the basic connected LED sample isn’t working, I simply forked the code from this sample: https://docs.particle.io/guide/getting-started/examples/photon/#control-leds-over-the-39-net.

I’m not sure what you mean by tinker functions. Can you clarify or point me to a reference link please?

@bko: Yes I logged in to the CLI and I can list my devices and can confirm the Photon is online. I can also see previously created webhooks when I use “particle webhook list”.

1 Like

@mdma Ok, figured out that you meant the Tinker sample. I flashed it and the functions DO appear in particle list. Let me compare the code and see if I find something obvious.

EDIT: I figured it out and fixed it, but I do not understand why it broke in the first place. I was introducing a delay(10000) as the very first line of code in my setup() to avoid rare cases where the Particle gets locked-up and goes into a state where it is no longer flushable without a reset. I’ve had that happen to me once and was advised to introduce the delay as a prevention mechanism.

For some reason, the delay was also causing an issue with the function registration. I removed the delay and the function gets registered properly and I can see it listed in the CLI, and I can call it successfully. I re-added the delay and it broke again, removed it and it was fixed.

The delay was the culprit but I do not understand why. If someone knows why, I’d love to know. My hack now works, but I like to understand what goes on under the hood. Thanks.

4 Likes

@ActiveNick,

Man, you saved me, I was doing same thing as you in my setup, to avoid lockup and also bad sketch that could block and break OTA, leaving me 5 seconds to launch a OTA in case of problem…

And since new firmware variable and functions were no more exposed due to this delay in setup (5 sec in my case). It could be fine if you guys at Particle could ::

  • Put information on this in the reference documentation so that call to Spark.variable or Spark.function need to be done quickly in setup
  • fix this problem if it’s a bug (which I think it is)

Anyway got things working back, this firmware update was really a pain after spark-dev problem and now this one, I hope never see this anymore…

@ActiveNick: Your update saved me from finally going bonkers. THANK YOU!