Hello guys!I've got a very very big problem!So i would like to give a hand to help me one more time...
I'm newbie so forgive for my mistakes!
Arduino source code:
#include <Time.h>
#include <stdio.h>
#define TIME_MSG_LEN 11 // time sync consists of a HEADER followed by ten ascii digits
#define TIME_HEADER 'T' // Header tag for serial time sync message
void setup() {
Serial.begin(9600);
//Serial.println("Waiting for time sync message");
}
void loop(){
if(Serial.available() )
{
processSyncMessage();
}
if(timeStatus()!= timeNotSet)
{
// here if the time has been set
digitalClockDisplay();
}
delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
/*Serial.print(hour());
printDigits(minute());
printDigits(second());*/
Serial.println(String(hour())+String(printDigits(minute()))+String(printDigits(second())));
/*Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());*/
Serial.println();
}
String printDigits(int digits){
String str = "";
String padding = "";
// utility function for digital clock display: prints preceding colon and leading 0
//Serial.print(':');
padding = ":";
if(digits < 10){
//Serial.print('0');
//Serial.print(digits);
str = ('0'+String(digits));
}
return (padding + str);
}
void processSyncMessage() {
// if time sync available from serial port, update time and return true
// time message consists of a header and ten ascii digits
while(Serial.available() >= TIME_MSG_LEN ){
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 clock to the time received on serial port
}
}
}
I want to take a string from time like that! 00:00:00, because should connect this values with a C# application.
Something else:
When i'm sending pulse ( unix time) to synchronize from pc e.g T18384590 etc i'm taking response fine.
but i don't take correct strings to modify them in my application.
The 1st string is e.g 12:
and the other one is 00:00\n\r00:00:00\n\r00:00:00\n\r
Please help me if you can!!!
Thanks