Wifi Shield syncing up with NTP server

Im using this code:

#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <WiFlyHQ.h>
#include <SoftwareSerial.h>

SoftwareSerial wifiSerial(2,3); //WIFI SHIELD CLIENT
WiFly wifly;                          //WIFI
String data;                          //WIFI
const char mySSID[] = "linksys";
const char myPassword[] = "somekey";

void terminal();

char dataBufferToReceive[30];  //for the time
int dataSize = 256;  //for the size
//time data 
long int uptime;
char timezone;
long int rtc;
char MyTime[20];

void setup(){
  Serial.begin(9600);  
  Alarm.timerRepeat(60, MorningAlarm); // timer for every 60 seconds    

  //GetTime from DS1307
  //DateTime now = wifly.getRTC();
  //setTime(now.hour(), now.minute(), now.second(), now.month(), now.day(), now.year());
  //Serial.print("Time is: ");
  //Serial.println(now.hour(),now.minute());

}

void  loop(){  
  Alarm.delay(10); // wait one second between clock display
}

void MorningAlarm(){
  Serial.println("Morning Alarm...");
  wifiSerial.listen();                                    

  //Init wifi module
  Serial.print("Free memory: ");
  Serial.println(wifly.getFreeMemory(),DEC);
  wifiSerial.begin(9600);

  if (!wifly.begin(&wifiSerial, &Serial)) {
      Serial.println("Failed to start wifly");
      wifly.terminal();
  } else {
    Serial.println("Success");
  }
  
  // set time from ntp server
  wifly.setTimeAddress("129.6.15.30"); //28, 29 or 64.113.32.5 or 216.229.0.179
  wifly.setTimePort(123);
  wifly.setTimezone(22);
  wifly.setTimeEnable(1);
  wifly.time();
  wifly.save();
  delay(1000);                                  

wifly.getTime(MyTime, 20);
     uptime = wifly.getUptime();
     timezone = wifly.getTimezone();
     rtc = wifly.getRTC();

     Serial.print("uptime: ");
     Serial.println(uptime);
     Serial.print("timezone: ");
     Serial.println(timezone);
     Serial.print("rtc: ");
     Serial.println(rtc);
  
     Serial.println(MyTime);
     
  //Get time from wifi module
  if (wifly.time()) {                              // My testing of rtc
    //print time
    delay(1000);                                  // My testing of rtc below
    //char *something = wifly.getTime(dataBufferToReceive,sizeof(dataBufferToReceive));
    int something = wifly.getRTC();
    Serial.println(something);
  } else {
    Serial.println("Failed to get time");
  }
  
  //OPEN WEBSITE
 if(wifly.open("google.com", 80)){
     wifly.println( "POST /your_http_request HTTP/1.1");
     wifly.println();
     wifly.close();
 }
}

/* Connect the WiFly serial to the serial monitor. */
void terminal(){
   while (1) {
	if (wifly.available() > 0) {
	    Serial.write(wifly.read());
	}
	if (Serial.available() > 0) {
	    wifly.write(Serial.read());
	}
   }
}

The results I get are:

Alime is: Alarms set!
Time is: Morning Alarm...
Free memory: 875
Success
uptime: 2832
timezone:
rtc: 2833
2831 s
2835
open google.com 80

So Im wondering, its saying that the module has been up for 2832, must be milliseconds, so about 3 seconds. Timezone comes back blank, rtc seems to be nothing more than 1 ms greater than the uptime.

MyTime is 2831s
and
something is 2835.

So these are all uptime values, not real time values.

So Im puzzled as to why Im not getting real time values from the ntp server.

  wifiSerial.listen();                                   

  //Init wifi module
  Serial.print("Free memory: ");
  Serial.println(wifly.getFreeMemory(),DEC);
  wifiSerial.begin(9600);

listen(), then begin().

You need to call listen() only if you have more than one SoftwareSerial instance. You need to call begin() ONCE, in setup().

The anonymous prints are stupid. Identify what you are printing.

So Im puzzled as to why Im not getting real time values from the ntp server.

I don't see where you explicitly ask for the ntp server's time. I don't see where you deal with the server response.

I do see plenty of place where you assume that we know what the WiFly library is doing, incorrectly.

Post a link to the library.

At present I havent finished writing the sketch, I barely just started and my objective is to first get the rtc working. I want to make sure I can use the wifly module's rtc function to replace my external ds1307.

The library is here: WiFlyHQ/WiFlyHQ.cpp at master · harlequin-tech/WiFlyHQ · GitHub

I just found this...around p67 it talks about the rtc function.

Great example of how a possibly well written library program can be painful to use if it is poorly documented. But it looks like you set up NTP with setTimeAddress() etc., and then get the time with getTime().

You should be able to use a domain name like "ntp.blah.blah" to specify an NTP source, instead of a hard coded IP.

Ok I tried this:

#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <WiFlyHQ.h>
#include <SoftwareSerial.h>

SoftwareSerial wifiSerial(2,3); //WIFI SHIELD CLIENT
WiFly wifly;                          //WIFI
String data;                          //WIFI
const char mySSID[] = "linksys";
const char myPassword[] = "somekey";

void terminal();

//time data 
long int uptime;
char timezone = 7;
long int rtc;
char MyTime[20];

void setup(){
  Serial.begin(9600);  
  Alarm.timerRepeat(60, MorningAlarm); // timer for every 60 seconds    
}

void  loop(){  
  Alarm.delay(10); // wait one second between clock display
}

void MorningAlarm(){
  Serial.println("Morning Alarm...");

  //Init wifi module
  Serial.print("Free memory: ");
  Serial.println(wifly.getFreeMemory(),DEC);
  wifiSerial.begin(9600);

  if (!wifly.begin(&wifiSerial, &Serial)) {
      Serial.println("Failed to start wifly");
      wifly.terminal();
  } else {
    Serial.println("Success");
  }

  // set time from ntp
  wifly.setTimeAddress("ntp-nist.ldsbc.net");
  wifly.setTimePort(123);
  wifly.setTimezone(7);
  //wifly.setTimeEnable(1); //maybe because we dont want it to set time on powerup
  wifly.time();
  wifly.save();
  delay(1000);                                  

wifly.getTime(MyTime, 20);
     uptime = wifly.getUptime();
     timezone = wifly.getTimezone();
     rtc = wifly.getRTC();

     Serial.print("uptime: ");
     Serial.println(uptime);
     Serial.print("timezone: ");
     Serial.println(timezone);
     Serial.print("rtc: ");
     Serial.println(rtc);
     Serial.print("MyTime from wifly getTime: ");
     Serial.println(MyTime);
     
  //Get time from wifi module
  if (wifly.time()) {                  
    //print time
    delay(1000);                                 
    int something = wifly.getRTC();
    Serial.print("RTC from wifly getRTC: ");
    Serial.println(something);
  } else {
    Serial.println("Failed to get time");
  }
  
  //OPEN WEBSITE
 if(wifly.open("google.com", 80)){
     Serial.print("done");
     wifly.println( "POST /your_http_request HTTP/1.1");
     wifly.println();
     wifly.close();
 }
}

/* Connect the WiFly serial to the serial monitor. */
void terminal(){
   while (1) {
	if (wifly.available() > 0) {
	    Serial.write(wifly.read());
	}
	if (Serial.available() > 0) {
	    wifly.write(Serial.read());
	}
   }
}

But still all logs come back as ms since just as before...Im also wondering about timezone which comes back blank.