That is indeed the correct call - however, as per the wiki and v1 firmware release notes, 'Particle.syncTime() - though time is not yet connected to anything'.
So the function is available (in as far as compiling without failing, it doesn't sync with anything, as the Oak doesn't have a user accessible RTC to sync the time with. And if you try to access any of the Time functions, it will fail with a 'Time not declared in this scope' error.
You could get the time via a HTTP request from one of the NIST time servers like in the code below.
#include <ESP8266WiFi.h>
// const char* host = "utcnist2.colorado.edu";
const char* host = "128.138.141.172";
String TimeDate = "";
void setup()
{
Particle.begin();
Particle.println("time test sketch");
}
void loop()
{
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 13;
if (!client.connect(host, httpPort)) {
Particle.println("connection failed");
return;
}
// This will send the request to the server
client.print("HEAD / HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Mozilla/4.0 (compatible; ESP8266 Arduino Oak;)\r\n\r\n");
delay(100);
// Read all the lines of the reply from server and print them to Serial
// expected line is like : Date: Thu, 01 Jan 2015 22:00:14 GMT
char buffer[12];
String dateTime = "";
while (client.available())
{
String line = client.readStringUntil('\r');
if (line.indexOf("Date") != -1)
{
Particle.print("=====>");
}
else
{
//Particle.print(line);
TimeDate = line.substring(7);
//Particle.println(TimeDate);
// date starts at pos 7
TimeDate = line.substring(7, 15);
TimeDate.toCharArray(buffer, 10);
Particle.print("UTC Date/Time: ");
Particle.print(buffer);
// time starts at pos 14
TimeDate = line.substring(16, 24);
TimeDate.toCharArray(buffer, 10);
Particle.print(" ");
Particle.println(buffer);
}
}
delay(10000);
}
With a few modifications to the TimeNTP_ESP8266Wifi examples that come with the Time library, it is also possible to get the time via NTP, and in an easier to manipulate form.
/*
* Time_NTP.pde
* Example showing time sync to NTP time source
*
* This sketch uses the ESP8266WiFi library
*/
#include <TimeLib.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char ssid[] = "*************"; // your network SSID (name)
const char pass[] = "********"; // your network password
// NTP Servers:
IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov
// IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov
// IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov
const int timeZone = 1; // Central European Time
//const int timeZone = -5; // Eastern Standard Time (USA)
//const int timeZone = -4; // Eastern Daylight Time (USA)
//const int timeZone = -8; // Pacific Standard Time (USA)
//const int timeZone = -7; // Pacific Daylight Time (USA)
WiFiUDP Udp;
unsigned int localPort = 8888; // local port to listen for UDP packets
void setup()
{
Particle.begin();
// while (!Serial) ; // Needed for Leonardo only
delay(250);
Particle.println("TimeNTP Example");
// Particle.print("Connecting to ");
// Serial.println(ssid);
// WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
// Serial.print(".");
}
// Serial.print("IP number assigned by DHCP is ");
// Serial.println(WiFi.localIP());
// Serial.println("Starting UDP");
Udp.begin(localPort);
// Serial.print("Local port: ");
// Serial.println(Udp.localPort());
Particle.println("waiting for sync");
setSyncProvider(getNtpTime);
}
time_t prevDisplay = 0; // when the digital clock was displayed
void loop()
{
if (timeStatus() != timeNotSet) {
if (now() != prevDisplay) { //update the display only if time has changed
prevDisplay = now();
digitalClockDisplay();
}
}
}
void digitalClockDisplay(){
// digital clock display of the time
Particle.print(hour());
printDigits(minute());
printDigits(second());
Particle.print(" ");
Particle.print(day());
Particle.print(".");
Particle.print(month());
Particle.print(".");
Particle.print(year());
Particle.println();
}
void printDigits(int digits){
// utility for digital clock display: prints preceding colon and leading 0
Particle.print(":");
if(digits < 10)
Particle.print('0');
Particle.print(digits);
}
/*-------- NTP code ----------*/
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
time_t getNtpTime()
{
while (Udp.parsePacket() > 0) ; // discard any previously received packets
Particle.println("Transmit NTP Request");
sendNTPpacket(timeServer);
uint32_t beginWait = millis();
while (millis() - beginWait < 1500) {
int size = Udp.parsePacket();
if (size >= NTP_PACKET_SIZE) {
Particle.println("Receive NTP Response");
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
unsigned long secsSince1900;
// convert four bytes starting at location 40 to a long integer
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
}
}
Particle.println("No NTP Response :-(");
return 0; // return 0 if unable to get the time
}
// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address)
{
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}