Using thing.handle(); in Setup?

Hi
the coding guide says
thing.handle();
must stay in loop();

I would need to take over some parameters from a manually created device property during setup().

Is it legitimate to call
thing.handle();
for that sake in setup() too?

Thank you for an advice.

Hi,

What do you mean specifically to “take over”?

thing.handle(); will execute any comm task (from wifi/GSM/ethernet negotiation up to send/receive any value), maybe (I’m not sure) it can be invoked at setup() or loop() (but I dont think it is a good practice), however I think that what you need to warantee is to keep the value you are interested in without modification until you “take over it”.

I hope have explained myself, let us know any other detail to see think how to achieve your goal.

Hope this helps.

Thank you.
so e.g.

  pson setparams;
  thing.get_property("setparams", setparams, true);    
  windLimit        = setparams["windLimit"];
  upperLimitDB     = setparams["UpperDB"];
  lowerLimitDB     = setparams["LowerDB"];
  eventTresholdLevel = setparams["EventTreshold"];
  natTresholdLevel = setparams["NATTreshold"];
  measurementTresholdLevel = setparams["MeasTreshold"];
  minExceedenceTime = setparams["MinExcTime"];
  maxExceedenceTime = setparams["MaxExcTime"];
  listeningTime     = setparams["ListenTime"];

does nothing until activated by a thing.handle();

Right?
What happens, if the property “setparams” does not exist?
a) all values will be zeroed
b) all values remain unchanged
c) third world war is started… :wink:

Hi,

You are partially right, note the instruction that require the thing.handle(); is →

Because it will set a flag to get that property, and will be executed in the next thing.handle(); program line, however note that the pson variable is declared locally at the uC, so that instruction of course will be executed in that order, and it will try to assing those values, because those are local instructions.

If property “setparams” does not exist, honestly I dont know which could be the behaviour, maybe the values are zeroed or falsed as the uC cannot assing "null’ values, I doubt it remain unchanged but for sure it won’t be related to WWIII, so keep making cool stuff :wink:

Hope this helps.

Thank you. I’ll test it.
Have we got a method to test if a property exists?
I would prefer to leave the variables unchanged if nobody did create the property upfront.

you wrote: note the instruction that require the thing.handle(); is →

I suppose the arrow stood for >>?
but
thing.get_property("setparams", setparams, true);
has no >> , so its executed directly?

Hi

Not at all, I used the arrow just to point the next line, not related with code.

I’ve just checked that get_property() function does not have the confirmation parameter (as the write_bucket() function), so currently I dont see how to confirm that the property exists, what I would do? I would check the uC response when the property does not exist, and if it get to zero all the parameters and would check with all the parameters as flag for the correct property read, if all parameter are zero (and by nature of the process this is not a real possible case), no modifications, different from zero, assign values.

Hope this helps.