diff --git a/src/date_parser.cpp/date_parser.cpp.ino b/src/date_parser.cpp/date_parser.cpp.ino new file mode 100644 index 0000000000000000000000000000000000000000..611595394980739a3968a668c8562cd5bb789ebf --- /dev/null +++ b/src/date_parser.cpp/date_parser.cpp.ino @@ -0,0 +1,45 @@ +#include <TimeLib.h> + +#define TIME_MSG_LEN 11 // time sync to PC is HEADER and unix time_t as ten ascii digits +#define TIME_HEADER 255 // Header tag for serial time sync message + +int GetCurrentTIme(); +void GetPCTime(); + +void setup() { + // put your setup code here, to run once: + Serial.begin(19200); +} + +void loop() { + // put your main code here, to run repeatedly: + Serial.println(GetCurrentTime()); +} + +int GetCurrentTime() { + if (Serial.available()) { + GetPCTime(); + } + if(timeStatus() != timeNotSet) { + return(month()); + } else { + return (0); + } +} + + +void GetPCTime() { + // if time available from serial port, sync the DateTime library + while(Serial.available() >= TIME_MSG_LEN ){ // time message + if( Serial.read() == TIME_HEADER ) { + time_t pctime = 0; + for(int i=0; i < TIME_MSG_LEN -1; i++){ + char charRead= Serial.read(); + if( charRead >= '0' && charRead <= '9') { + pctime = (10 * pctime) + (charRead - '0') ; // convert digits to a number + } + } + setTime(pctime); + } + } +} diff --git a/src/json_parser.cpp/json_parser.cpp.ino b/src/json_parser.cpp/json_parser.cpp.ino index e18cac80b88b7b306b2278c3ade6590c12edd3c3..41fcb257686d8a58e0e8aeec73a027cd830d15ff 100644 --- a/src/json_parser.cpp/json_parser.cpp.ino +++ b/src/json_parser.cpp/json_parser.cpp.ino @@ -12,7 +12,8 @@ char* GenerateJSONString(); void setup() { // put your setup code here, to run once: - + Serial.begin(9600); + while (!Serial) continue; } void loop() { @@ -21,9 +22,6 @@ void loop() { } void ReadJson() { - Serial.begin(9600); - while (!Serial) continue; - StaticJsonBuffer<200> jsonBuffer; JsonObject& jsonReader = jsonBuffer.parseObject(json); diff --git a/src/lib/Time-master.zip b/src/lib/Time-master.zip new file mode 100644 index 0000000000000000000000000000000000000000..01f73c6f1f3ce15850d5ea595868418189b9ba8e Binary files /dev/null and b/src/lib/Time-master.zip differ