I am attempting to go from unix to ISO8601 for a webserver (m2x). Using NTP to get the time, and RTClib.h or Time.h libraries, what would be the best way to get into the time format the website requires? the full ISOcode has to look like this: yyyy-mm-dd T hh:mm:ss.123 (without spaces). I then somehow need to get this into an array that is outlined in the header.
Im using an UNO r3 (but if it makes any difference i'll have to use a mega by the time im done...)
I am going to use adafruit's NTP example as a starting point:
/***************************************************
This is an example for the Adafruit CC3000 Wifi Breakout & Shield
Designed specifically to work with the Adafruit WiFi products:
----> https://www.adafruit.com/products/1469
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried, Kevin Townsend and Phil Burgess for
Adafruit Industries. BSD license, all text above must be included
in any redistribution
****************************************************/
/*
This example queries an NTP time server to get the current "UNIX time"
(seconds since 1/1/1970, UTC (GMT)), then uses the Arduino's internal
timer to keep relative time. The clock is re-synchronized roughly
once per day. This minimizes NTP server misuse/abuse.
The RTClib library (a separate download, and not used here) contains
functions to convert UNIX time to other formats if needed.
*/
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <RTClib.h>
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIVIDER); // you can change this clock speed but DI
unixtime
#define WLAN_SSID "HOME-61B2" // cannot be longer than 32 characters!
#define WLAN_PASS "0C6B7DEB3241400F"
#define WLAN_SECURITY WLAN_SEC_WPA2
Adafruit_CC3000_Client client;
const unsigned long
connectTimeout = 15L * 1000L, // Max time to wait for server connection
responseTimeout = 15L * 1000L; // Max time to wait for data from server
int
countdown = 0; // loop() iterations until next time server query
unsigned long
lastPolledTime = 0L, // Last value retrieved from time server
sketchTime = 0L; // CPU milliseconds since last server query
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Hello, CC3000!\n"));
displayDriverMode();
Serial.println(F("\nInitialising the CC3000 ..."));
if (!cc3000.begin()) {
Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
for(;;);
}
uint16_t firmware = checkFirmwareVersion();
if (firmware < 0x113) {
Serial.println(F("Wrong firmware version!"));
for(;;);
}
displayMACAddress();
Serial.println(F("\nDeleting old connection profiles"));
if (!cc3000.deleteProfiles()) {
Serial.println(F("Failed!"));
while(1);
}
/* Attempt to connect to an access point */
char *ssid = WLAN_SSID; /* Max 32 chars */
Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid);
/* NOTE: Secure connections are not available in 'Tiny' mode! */
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
/* Wait for DHCP to complete */
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP()) {
delay(100); // ToDo: Insert a DHCP timeout!
}
/* Display the IP address DNS, Gateway, etc. */
while (!displayConnectionDetails()) {
delay(1000);
}
}
// To reduce load on NTP servers, time is polled once per roughly 24 hour period.
// Otherwise use millis() to estimate time since last query. Plenty accurate.
void loop(void) {
if(countdown == 0) { // Time's up?
unsigned long t = getTime(); // Query time server
if(t) { // Success?
lastPolledTime = t; // Save time
sketchTime = millis(); // Save sketch time of last valid time query
countdown = 24*60*4-1; // Reset counter: 24 hours * 15-second intervals
}
} else {
countdown--; // Don't poll; use math to figure current time
}
unsigned long currentTime = lastPolledTime + (millis() - sketchTime) / 1000;
Serial.print(F("Current UNIX time: "));
Serial.print(currentTime);
Serial.println(F(" (seconds since 1/1/1970 UTC)"));
delay(15000L); // Pause 15 seconds
}
then attempt to integrate the RTClb.h or Time.h libraries. i can post examples those libraries if needed.
thanks
EDIT: alternatively, instead of using ntp.gov, is there one that will send me the data in the form i need off the bat (that the arduino can then use millis() to keep accurate?)