Expected Unqualified-id Error

I am getting an error when compiling in Particle Dev that states “expected unqualified-id before ‘(’ token .:14:15”. I should also note that I am using a photon and “Spark.syncTime();” is commented out because it causes another error (I read that this was specific to the photon and would be resolved soon). How can i fix this unqualified-id error and will the photon syncTime() error be resolved soon?

In my own testing I found that commenting out the entire refreshDisplayTime() function made the error go away.

EDIT: I am now fairly certain the problem is originating from “unsigned long currentTime = Time.now()” because removing that line and just getting the hour/minute without the epoch parameter ( Time.minute() ) does not provide the error. However, I still don’t know how to fix the problem.

Another EDIT: I also tried entering Time.now() as the parameter directly ( Time.minute(Time.now()) ) only to receive the error three times now (one for each use) so perhaps the error is originating from that Time.now() function directly? Nonetheless, I still don’t know how to fix this.

#include "application.h"
#include "TimeAlarms.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

bool isDST(int dayOfMonth, int month, int dayOfWeek, String rule);
void refreshDisplayTime();

Adafruit_7segment display = Adafruit_7segment();

const int ONE_DAY_MILLIS = 24 * 60 * 60 * 1000;
unsigned long lastSync = millis();
int timeZone = -8; //UTC time zone offset TODO: Must be set/recieved from web/cloud
String DSTRule = "US"; //US, EU, or OFF TODO: Must be set/recieved from web/cloud
int DSTJumpHour; //When DST takes effect
int hourFormat = 12; //12 or 24 TODO: Must be set/recieved from web/cloud

void setup() {
  if(DSTRule == "US") {
    DSTJumpHour = 2;
  } else if(DSTRule == "EU") {
    DSTJumpHour = 1+timeZone;
  } else {
    DSTJumpHour = 0;
  }

  //Set the proper time zone according to DST status
  Time.zone(isDST(Time.day(), Time.month(), Time.weekday(), DSTRule) ? timeZone+1 : timeZone);

  //Setup the 7-segment display
  display.begin(0x70);
  display.setBrightness(15); //TODO: adjust brightness to optimize for veneer/time
}

void loop() {
  //Request time synchronization from the Spark Cloud every 24 hours
  if (millis() - lastSync > ONE_DAY_MILLIS) {
    //Spark.syncTime();
    lastSync = millis();
  }

  //Update time zone at DSTJumpHour incase DST is now in effect
  if(Time.hour() == DSTJumpHour && Time.minute() == 0) {
    Time.zone(isDST(Time.day(), Time.month(), Time.weekday(), DSTRule) ? timeZone+1 : timeZone);
  }

  refreshDisplayTime();

  //Delay for checking alarms/timers
  Alarm.delay(500);
}

//Return true if DST is currently observed
bool isDST(int dayOfMonth, int month, int dayOfWeek, String rule) {
  if(rule == "US") {
    //Month quick check
    if (month < 3 || month > 11) {
      return false;
    } else if (month > 3 && month < 11) {
      return true;
    }
    //The US observes DST from the first Sunday of March
    //The US observes DST until the first Sunday of November
    int previousSunday = dayOfMonth - dayOfWeek + 1;
    if (month == 3) {
      return previousSunday >= 1;
    } else {
      return previousSunday <= 0;
    }
  } else if(rule == "EU") {
    //Month quick check
    if (month < 3 || month > 10) {
      return false;
    } else if (month > 3 && month < 10) {
      return true;
    }
    //The EU observes DST from the last Sunday of March
    //The EU observes DST until the last Sunday of November
    int previousSunday = dayOfMonth - dayOfWeek + 1;
    if(month == 3) {
      if(previousSunday+7>31) {
        return true;
      } else {
        return false;
      }
    } else {
      if(previousSunday+7>31) {
        return false;
      } else {
        return true;
      }
    }
  } else {
    return false;
  }
}

//display the current time on the 7-segment display
void refreshDisplayTime() {
  unsigned long currentTime = Time.now();
  int hour;
  if(hourFormat == 12) {
    hour = Time.hourFormat12(currentTime);
  } else {
    hour = Time.hour(currentTime);
  }
  int minute = Time.minute(currentTime);

  display.drawColon(true);
  if(hour/10 != 0) {
    display.writeDigitNum(0, hour/10);
  }
  display.writeDigitNum(1, hour%10);
  display.writeDigitNum(2, minute/10);
  display.writeDigitNum(3, minute%10);
  display.writeDisplay();
}

I think this is a preprocessor glitch that was known from Particle Build in the past.

When I reformatted your function into this

void refreshDisplayTime() {
  unsigned long currentTime = Time.now();
  int hour;

  if(hourFormat == 12) 
    hour = Time.hourFormat12(currentTime);
  else
    hour = Time.hour(currentTime);

  int minute = Time.minute(currentTime);

  display.drawColon(true);
  if(hour/10 != 0) {
    display.writeDigitNum(0, hour/10);
  }
  display.writeDigitNum(1, hour%10);
  display.writeDigitNum(2, minute/10);
  display.writeDigitNum(3, minute%10);
  display.writeDisplay();
}

it compiled.
Sometimes - I don’t know why and when - a construct like } else { causes the preproc to trip.

1 Like

My thought was that if by some unfortunate chance, i get the hour when it’s 12:59:59 and then by the time i call Time.minute() its now already 1:00:00 my clock would display 12:00 when really it should have been 12:59 or 1:00. I don’t think that’s very likely but as far as i know it’s possible, and not too difficult to address.

1 Like

I missed the 500ms delay in your loop, otherwise even if it happened it would only be visible for a few milli seconds, but then I removed that part of my post :blush:

I’ll probably reduce that delay at a later time but have it for testing at the moment. Thanks for your help!

Did the reformat work for you too?

Any updates on getting Spark.syncTime() working with the photon. I saw a post back in May Photon and syncTime saying that there would be a fix coming soon but it’s been quite a while now?

Actually, i guess i spoke a bit too soon. I’m still getting the error having copy and pasted your reformatted version.

I haven’t checked lately, but the 0.4.2 firmware should be coming to the cloud build farm soon.
(OK, I know, people have heard this for the last few weeks, but Particle is working hard on it)


If it still doesn’t work, try out

#pragma SPARK_NO_PREPROCESSOR
//#include "application.h"  // you've already got that anyhow

at the top of you INO file.

It’s a .cpp file so I don’t think that would help. Just in case, i tried it but it didn’t change anything

Sorry, for not stating that in my original question

Sorry for the confusion.

When I tested your original code, I had an INO and removed the external libs and still got a similar error to yours, which went away the way I said above.
But now I’ve tried your full code and now I see the problem, too.

TimeAlarms/TimeAlarms.h:14:15: error: expected unqualified-id before '(' token
 #define now() (Time.now()+time_zone_cache)
               ^

The problem is not in your code, but in the combination of Time.now() and the TimeAlarms library.
Maybe you could try #undef now in your user code, after all the #include statements.

If this causes errors with Adafruit_GFX, try commenting the #include "Adafruit_GFX.h", that solved these errors for me.

That (with or without the parentheses - both worked) removed the error, it’s just a bit odd considering “#undef now()” is already at the bottom of TimeAlarms.cpp. No new errors popped up and I don’t see any references to now in the GFX library.

I don’t get any errors with Adafruit_GFX - i didn’t have to comment it out.

For reference, i’m using the Adafruit_GFX library from https://github.com/creationix/spark-adafruit-led-backpack/tree/master/firmware - that may explain why you receive new errors that I don’t

I guess the #undef in TimeAlarms.cpp has no effect due to the build order and maybe also only in file scope.


I have to confess, that I use Particle Build (rather then Dev) for quick testing and including its Adafruit_GFX library might have caused my errors.
But good to know, you got your issue sorted :+1:

While I have a thread going, I have two hopefully quick questions.
1.) Is it best practice/convention to often use fixed-width integers (uint32_t rather than unsigned long)
2.) Is there any way using particle dev (or if i use some other ide) to have my libraries within a separate folder. At the moment i have to keep them all in the same directory as my main file or i get errors.

I can only speak for myself regarding 1.)
I do prefere uint32_t (and int32_t, int16_t, …) over the use of int, integer, long, … since it actually does tell you what you are dealing with.
Experience in this forum (and others) has shown, that some confusion arises when talking about int and long thinking these are two different types, but on a 32bit µC they are not.
This doesn’t happen with the more obvious int16_t and int32_t - and it’s shorter to write and easier for alignment like this

int      dontCareHowLong;
int8_t   bit8;
uint8_t  ubit8;
uint16_t ubit16;
uint32_t ubit32;
String   s;

unsigned long thisMessesItAllUp;

I just like the look of it :sunglasses:

As for 2.)
This is something that comes up from all different directions, but I have no idea about ETA.
There are other things tieing up Particle resources (firmware 0.4.x for Photon and Core, Electron, …), but it won’t get forgotten.

I need to fix this in the ported TimeAlarms library in a better way. This was the quick way to make it work but like all macros, it can cause problems. Sorry.

I always prefer the exact size (uint32_t) if I know what I need. This is the most portable way to write code.

2 Likes