[SOLVED]waitUntil(Particle.process()); causes multiple errors

In my project I want to make sure the time is processed correctly during setup.

   WiFi.on();                        //Turning the WiFi on.
   waitUntil(WiFi.ready);            //wait until the WiFi is ready.
   Particle.connect();               //Connect to the Particle Cloud
   waitUntil(Particle.connected);    //Wait until connected to the Particle Cloud.
   Particle.syncTime();              //Synchronize timer with the Particle Cloud.
   Particle.process();               //Ensures that data received from the Cloud is actually processed and used.
   waitUntil(Particle.process());    //Waits until all the data is processed (this ensure time on the Photon is correct).
   Time.zone(timeZone);              //Makes sure the time is correct for our timezone.
   currTime = Time.local() % 86400;  //Sets the current time in seconds from midnight.

However, waitUntil(Particle.process()) is causing 4 errors:

  1. void value not ignored as it ought to be (breakbeam.ino:93:31), clearly it does not accept Particle.process() in waitUntil() function.
  2. could not convert ‘_condition.setup()::__lambda5()’ from ‘void’ to ‘bool’ (…/wiring/inc/spark_wiring_system.h:158:40)
  3. in argument to unary ! (…/wiring/inc/spark_wiring_system.h:158:28)
  4. void value not ignored as it ought to be (…/wiring/inc/spark_wiring_system.h:161:27).

The problem with this code is that it actually works in another project. I directly copied it from there, including the declarations of currTime and timeZone.

I work in the Particle Dev IDE, and when I copy the code of the working project directly into this project it gives me errors. However, when I close the IDE, open the IDE with the working project and upload that, it does work!

How is it possible that completely identical code, with identical declarations and usage, yield such a different result? I was thinking, perhaps, I had the wrong firmware, perhaps the usage of Particle.process() in waitUntil() has been changed. But this is impossible because I can upload the working sketch.

So, I’m completely at a loss here. I don’t know if this is a bug. I cannot open spark_wiring_system.h. I expect it is in the cloud.

Can you guys help me figure out how to solve this or perhaps the Particle development team can use this to fix a bug. Whatever helps.

First, waitUntil() does not take the return value of a function call as a paramter but a function pointer.
So having the () in the parameter list is wrong.

And next, why would you want to waitFor() a synchronous function that just does its job and not return anything?
Particle.connected() and WiFi.ready() are returning booleans to provide a "status report" of asynchronous processes, Particle.process() doesn't, it's just there to do things.

Hmm, I doubt that.
Can you have another look in that project, and check what system version you were targeting there?
If it actually builds there, this might be a "glitch" in that version, which was corrected later on - since it should not.

With Dev it's often the point, that you actually are not building the project you think you are.
To test that, you'd just add a deliberate error in the supposedly working project and check if it actually trips. If it doesn't, you are building a different project than you are working on.

check what system version you were targeting there?

How do I check this? In both programs I am flashing the same Photon. If I remember correctly the 'working' version is on 0.5.3, but I'm not sure.

I can assure you however, that building the working .ino does not give any errors. However, when I copy all the code from that project into this one, I do get the error. This could definitely be an error in that version, then.

I had that written before I got to the point where you said you're using Dev - which always builds agains the default version (currently 0.5.3).

This is the declaration of waitFor() and waitUntil()

#define waitFor(condition, timeout) System.waitCondition([]{ return (condition)(); }, (timeout))
#define waitUntil(condition) System.waitCondition([]{ return (condition)(); })

    template<typename Condition, typename While> static bool waitConditionWhile(Condition _condition, While _while) {
        while (_while() && !_condition()) {
            spark_process();
        }
        return _condition();
    }

    template<typename Condition> static bool waitCondition(Condition _condition) {
        return waitConditionWhile(_condition, []{ return true; });
    }

    template<typename Condition> static bool waitCondition(Condition _condition, system_tick_t timeout) {
        const system_tick_t start = millis();
        return waitConditionWhile(_condition, [=]{ return (millis()-start)<timeout; });
    }

There must be another explanation to that, since that syntax is plain out wrong.
Have you tried out my test with the supposedly working .ino?
Some version of Dev didn't (or maybe still doesn't) rebuild if there already is a bin file present in the project folder. Try to remove/rename that binary.

Removed the .bin and compiled it. No errors. A new .bin file is now in the folder. Flashing it also works. This code has always worked for me and it has been running successfully for the last two months.

This new project is the first time I have had an error with this specific code and while I understand from your post that the syntaxing should not work, it does work. I’ve just uploaded it again and it well… works. No errors given, nothing.

Can you post the full code of the working project - or send me a PM?

Have you also tried adding a deliberate error and see the build trip, then correct the error again and see it succede again?

I’ll PM you and try out the deliberate error.

EDIT: it always builds a bin. Regardless of errors, actually it doesn’t even give errors. It just builds… Very weird.

That suggests that it doesn't actually build that .ino but some other that happens to work :wink:

But there is no other .ino in that folder and it does overwrite the Photon (I know this to be true, because I deliberately flashed it with something completely different).

Well, it is weird, but now I do know my mistake. Thanks for your input.

Which was?

Could it be that the project is in a completely different folder?
Can you post a screenshot of you full Dev window?

Well, I know now that waitUntil() does not work with Particle.process().

And with your comment about different folder… Inside the folder, there are some sub folders with old code. I’ve changed extensions of all these codes, except for one. When I change that extension to something that’s not .ino. I now get the error as well in the working code.

EDIT: removing the whole waitUntil(Particle.process()); line seems to fix everything. That’s the only thing causing errors.

2 Likes

You might just leave the Particle.process(); and only drop the waitUntil() part.

1 Like

Yep, that’s what I did and everything seems to have been solved. Anyway, thanks again for helping me. Much appreciated.

3 Likes