currently i am using this Arduino Playground - Time attempt to create a time stamp for arduino. but it did't work.
i am using XbeeS2 ,XbeeShield and Arduino. i want to set-up a wireless network communication. example i send a message. then i want to know what time message is send and receive. currently only this i am able to do. com 5 is the sender,com 7 is the receiver.the message are send via xbeeS2. iam very new to arduino and all this is self-taught
sender
#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() {
// setTime(12,10,00,1,1,2014);
Serial.begin(9600);
}
void loop(){
{
time_t t = now();
Serial.println("ABCDE");
digitalClockDisplay();
}
delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
printDigits(minute());
printDigits(second());
Serial.println(" S");
}
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);
}
time_t requestSync()
{
Serial.write(TIME_REQUEST);
return 0; // the time will be sent later in response to serial mesg
}
receiver
#include <Time.h>
#define portIndex = 1;
#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();
digitalClockDisplay();
}
delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
printDigits(minute());
printDigits(second());
Serial.println (" R");
}
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);
return 0; // the time will be sent later in response to serial mesg
}