Skip to content
Snippets Groups Projects
Commit 1ef5195a authored by 13515029 - Finiko Kasula Novenda's avatar 13515029 - Finiko Kasula Novenda
Browse files

Add Date Parser

parent 96bcdc4e
No related merge requests found
#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);
}
}
}
...@@ -12,7 +12,8 @@ char* GenerateJSONString(); ...@@ -12,7 +12,8 @@ char* GenerateJSONString();
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) continue;
} }
void loop() { void loop() {
...@@ -21,9 +22,6 @@ void loop() { ...@@ -21,9 +22,6 @@ void loop() {
} }
void ReadJson() { void ReadJson() {
Serial.begin(9600);
while (!Serial) continue;
StaticJsonBuffer<200> jsonBuffer; StaticJsonBuffer<200> jsonBuffer;
JsonObject& jsonReader = jsonBuffer.parseObject(json); JsonObject& jsonReader = jsonBuffer.parseObject(json);
......
File added
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment