Problem with SerialTime example from Time library

Hello,

I am trying to learn a bit about the timekeeping capabilities of my arduino. My ulitimate intention it to add timestamps to data collected from the analog pins as they log data to an SD card. I thought the Time library would be good for this, but I can not get the example sketch TimeSerial to work. The error I get is:

TimeSerial.cpp: In function ‘time_t requestSync()’:
TimeSerial.cpp:86:30: error: ‘BYTE’ was not declared in this scope

Here is the code of the example sketch:

/* 
 * TimeSerial.pde
 * example code illustrating Time library set through serial port messages.
 *
 * Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970)
 * you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2010
 T1262347200  
 *
 * A Processing example sketch to automatically send the messages is inclided in the download
 */ 
 
#include <Time.h>  

#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message 

void setup()  {
  Serial.begin(9600);
  setSyncProvider( requestSync);  //set function to call when sync required
  Serial.println("Waiting for sync message");
}

void loop(){    
  if(Serial.available() ) 
  {
    processSyncMessage();
  }
  if(timeStatus()!= timeNotSet)   
  {
    digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh  
    digitalClockDisplay();  
  }
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of a header and ten ascii digits
    char c = Serial.read() ; 
    Serial.print(c);  
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();          
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number    
        }
      }   
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
    }  
  }
}

time_t requestSync()
{
  Serial.write(TIME_REQUEST, BYTE);  
  return 0; // the time will be sent later in response to serial mesg
}

How can I go about getting this to work? I am not sure what BYTE means in this context and I did not find anything on a google search.

Thanks,

Lines in question:

time_t requestSync()
{
  Serial.write(TIME_REQUEST, BYTE);  
  return 0; // the time will be sent later in response to serial mesg
}

Error message:

sketch_jul25a.ino: In function 'time_t requestSync()':
sketch_jul25a:79: error: 'BYTE' was not declared in this scope

As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.

As it says, don't use BYTE.

Change the code above to:

time_t requestSync()
{
  Serial.write(TIME_REQUEST);  
  return 0; // the time will be sent later in response to serial mesg
}

Hello, thanks for replying.

I tried to do this before (although you get a slightly different error message than me about BYTE no longer being supported, interesting.) I get the following error message:

Error Message

/home/user01/sketchbook/libraries/Time/DateStrings.cpp:18:18: error: variable ‘monthStr1’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:19:18: error: variable ‘monthStr2’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:20:18: error: variable ‘monthStr3’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:21:18: error: variable ‘monthStr4’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:22:18: error: variable ‘monthStr5’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:23:18: error: variable ‘monthStr6’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:24:18: error: variable ‘monthStr7’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:25:18: error: variable ‘monthStr8’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:26:18: error: variable ‘monthStr9’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:27:19: error: variable ‘monthStr10’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:28:19: error: variable ‘monthStr11’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:29:19: error: variable ‘monthStr12’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:31:22: error: variable ‘monthNames_P’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:37:26: error: variable ‘monthShortNames_P’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:39:16: error: variable ‘dayStr0’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:40:16: error: variable ‘dayStr1’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:41:16: error: variable ‘dayStr2’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:42:16: error: variable ‘dayStr3’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:43:16: error: variable ‘dayStr4’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:44:16: error: variable ‘dayStr5’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:45:16: error: variable ‘dayStr6’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:46:16: error: variable ‘dayStr7’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:48:20: error: variable ‘dayNames_P’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
/home/user01/sketchbook/libraries/Time/DateStrings.cpp:49:24: error: variable ‘dayShortNames_P’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

I tried using Serial.write for all of those values, and updated writeln to simply "write", but then I got a few more errors. Has anyone been able to get this code to work? I am running on Debian-based linux and I believe I have the most recent version of the Arduino environment.

Current Error

TimeSerial.cpp: In function ‘void digitalClockDisplay()’:
TimeSerial.cpp:55:16: error: no matching function for call to ‘HardwareSerial::write()’
TimeSerial.cpp:55:16: note: candidates are:
In file included from /usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:193:0,
                 from TimeSerial.cpp:18:
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.h:58:20: note: virtual size_t HardwareSerial::write(uint8_t)
/usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.h:58:20: note:   candidate expects 1 argument, 0 provided
In file included from /usr/share/arduino/hardware/arduino/cores/arduino/Stream.h:26:0,
                 from /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.h:27,
                 from /usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:193,
                 from TimeSerial.cpp:18:
/usr/share/arduino/hardware/arduino/cores/arduino/Print.h:50:20: note: virtual size_t Print::write(const uint8_t*, size_t)
/usr/share/arduino/hardware/arduino/cores/arduino/Print.h:50:20: note:   candidate expects 2 arguments, 0 provided
/usr/share/arduino/hardware/arduino/cores/arduino/Print.h:49:12: note: size_t Print::write(const char*)
/usr/share/arduino/hardware/arduino/cores/arduino/Print.h:49:12: note:   candidate expects 1 argument, 0 provided

I believe I have the most recent version of the Arduino environment.

But what version, though?

Sorry, I have Arduino version 1.0.5. I am on a debian-based 32 bit linux system. I also quickly (thinking maybe this is a version issue) tried it in version 1.0.1 of arduino and have the same problem.

Thanks again for your input.

Today I deleted the Time library and installed the older version. I was able to get the example sketch working on that one. I'm not sure if there is something incompatible with the new library, or if there was just an error in unpackaging the Time library the first time, but it's working now.

Thanks for the advice.