How to Check if my functions registered successfully?

I am having an intermittent issue with functions not registering: ideally I’d get my electron to determine if the functions registered successfully, and if not, I’d get it to restart itself to see if it worked.

Does this sound crazy? Is there a method to do this?

@mblackler, can you share the code where you are registering your functions? Timing the registration vis-a-vis having a cloud connection is important. Are you using SYSTEM_THREAD(ENABLED)?

1 Like

As pointed out by @peekay123, seeing your code may enable us to see potential causes but as for your request it’s not an easy matter to check on the device whether your functions have been registered with the cloud or not.

While Particle.function() returns a boolean value informing you about the success of the call, this is not providing any info about the actual registration with the cloud.

You can call these functions even while the device is offline and get a true returned as this only indicates that your “wish to register a function” has been accepted by the device OS. From then on it’s the duty of the device OS to inform the cloud of your intent once a connection can be established (including re-registering if needed), but there will be no asynchronous feedback when this actually happens.

Sure you could incorporate some test scheme (e.g. a webhook triggering a function call) but that is typically not required since function registration is quite bullet proof when you know how to do it right :wink:


Posting your code structure and configuration might help determine if you just have a sequencing issue.

I suppose you could set up a webhook and have the device call into its own function.

However, if this is reproducible and not something obvious it would be great if you could gather some serial logs demonstrating the issue and pass those along so hopefully the issue can be fixed.

Thanks for the notes.

Weird thing is, that we’ve not changed the function registration code for the past 2 years, the only thing that’s changed is the DeviceOS version.

I see that some other people are having intermittent issues with function registration, however on Xenons. We see it in Electrons running DeviceOS 1.4.3.

Bunch of other non-relevant stuff...

void setup() {

  atcab_init( &cfg_ateccx08a_i2c_default );

  #if PLATFORM_ID == 10 // Electron
      // We store connection events in retained memory. Do this early because things like batteryCheck will generate events.

      // Set up the other modules

  //Initialize accumulated meter Reading from FRAM
  _activeEnergyMeterValue = readActiveEnergyMeter();

  //SETUP Functions

  //Bypass FRAM for the time being
  _framReportingState = FRAMReportingState::OFF;

  // We use semi-automatic mode so we can disconnect if we want to, but basically we
  // use it like automatic, as we always connect initially.

void calSetupEnterFunction(){

  // register the cloud function
  Particle.function("setMaxPower", setMaxPowerHandler);
  Particle.function("getMaxPower", getMaxPowerPercHandler);
//  Particle.function("accMtrPsNg", getAccumulatePosNegHandler);
//  Particle.function("toggleDebug", toggleDebugHandler);
//  Particle.function("maxConfWP", maxConfigPowerPercHandler);
//  Particle.function("getMaxConfWP", getMaxConfigPowerPercHandler);
  //Particle.function("isTimeValid", isTimeValidHandler);
  Particle.function("runVRMStest", runVoltageRMStestHandler);
  Particle.function("runCRMStest", runCurrentRMStestHandler);

  Particle.function("getVoltCalb", getVoltageCalibrationHandler);
  Particle.function("setVoltCalb", setVoltageCalibrationHandler);
  Particle.function("getCurrCalb", getCurrentCalibrationHandler);
  Particle.function("setCurrCalb", setCurrentCalibrationHandler);
  Particle.function("reset", resetHandler);
  Particle.function("resetSTPM", resetSTPM32Handler);
  Particle.function("setConfig", setConfigHandler);

  Particle.function("wSerNum", setSerialNumberHandler);
  //rSerNum rolled into cmd function
  //Particle.function("rSerNum", getSerialNumberHandler);
  Particle.function("rssi", rssiHandler);
  Particle.function("runCommTest", postHandler);
  //Particle.function("test", createStatus);
  Particle.function("cmd", cmdHandler);

  //Particle.subscribe("msgBus", msgBusHandler, MY_DEVICES);

  Particle.subscribe("dutVoltMsg", runDeviceUnderTestVoltageHandler, MY_DEVICES);
  Particle.subscribe("dutAmpMsg", runDeviceUnderTestCurrentHandler, MY_DEVICES);
  //Particle.subscribe("dutCalRst", resetDeviceUnderTestCalOffsetHAndler, MY_DEVICES);
  Particle.subscribe("dutSetVCal", setVCalibrationHandler, MY_DEVICES);
  Particle.subscribe("dutSetICal", setCCalibrationHandler, MY_DEVICES);

I don’t think it is just on Xenon - we have been seeing it on Photon running 1.4.1. One thing I would say about your code is have you tried reducing the number of functions by passing an action in the data field?

Yes, certainly have for any new functions, but for legacy reasons it is difficult to cut it down much without significant changes elsewhere in our stack.

Thanks for letting me know about seeing it in other DeviceOS builds.