hello,
i try to compile some sample from the TimeLib.h
if i Compile the sample-file TimeRTCSet.ino
with arduino-ide works fine.
if i try it with platformio then i get some errors
her is the code
#include <Arduino.h>
#include <TimeLib.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
void setup() {
Serial.begin(9600);
while (!Serial) ; // Needed for Leonardo only
setSyncProvider(RTC.get); // the function to get the time from the RTC
if (timeStatus() != timeSet)
Serial.println(“Unable to sync with the RTC”);
else
Serial.println(“RTC has set the system time”);
}
void loop()
{
if (Serial.available()) {
time_t t = processSyncMessage();
if (t != 0) {
RTC.set(t); // set the RTC and the system time to the received value
setTime(t);
}
}
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);
}
/* code to process time sync messages from the serial port */
#define TIME_HEADER “T” // Header tag for serial time sync message
unsigned long processSyncMessage() {
unsigned long pctime = 0L;
const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013
if(Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
return pctime;
if( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013)
pctime = 0L; // return 0 to indicate that the time is not valid
}
}
return pctime;
}
and there is the Error-message
Processing megaatmega2560 (platform: atmelavr; board: megaatmega2560; framework: arduino)
Verbose mode can be enabled via -v, --verbose
option
CONFIGURATION: Redirecting...
PLATFORM: Atmel AVR > Arduino Mega or Mega 2560 ATmega2560 (Mega 2560)
HARDWARE: ATMEGA2560 16MHz 8KB RAM (248KB Flash)
Library Dependency Finder -> Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 32 compatible libraries
Scanning dependencies…
Dependency Graph
|-- <Time> 1.5
|-- <DS1307RTC>
| |-- <Time> 1.5
| |-- <Wire> 1.0
|-- <Wire> 1.0
Compiling .pioenvs\megaatmega2560\src\main.cpp.o
Compiling .pioenvs\megaatmega2560\libd23\Time\DateStrings.cpp.o
Compiling .pioenvs\megaatmega2560\libd23\Time\Time.cpp.o
Compiling .pioenvs\megaatmega2560\lib571\Wire\Wire.cpp.o
src\main.cpp: In function ‘void loop()’:
src\main.cpp:20:35: error: ‘processSyncMessage’ was not declared in this scope
time_t t = processSyncMessage();
^
src\main.cpp:26:23: error: ‘digitalClockDisplay’ was not declared in this scope
digitalClockDisplay();
^
src\main.cpp: In function ‘void digitalClockDisplay()’:
src\main.cpp:33:23: error: ‘printDigits’ was not declared in this scope
printDigits(minute());
^
src\main.cpp: In function ‘long unsigned int processSyncMessage()’:
src\main.cpp:59:29: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
if(Serial.find(TIME_HEADER)) {
^
*** [.pioenvs\megaatmega2560\src\main.cpp.o] Error 1
[ERROR] Took 2.17 seconds
my plaformio.ini looks like
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
lib_deps =
https://github.com/PaulStoffregen/Time/archive/master.zip
https://github.com/PaulStoffregen/DS1307RTC/archive/master.zip
what i do wrong?
best regards
Achim