diff --git a/fw_esp8266.ino b/fw_esp8266.ino index 27db799..5dfc6d2 100644 --- a/fw_esp8266.ino +++ b/fw_esp8266.ino @@ -3,6 +3,7 @@ #include "Adafruit_MQTT_Client.h" #include #include +//#include "time.h" /************************* WiFi Settings *********************************/ @@ -20,9 +21,9 @@ /***********************NTP settings*********************************/ //UTC offset in seconds, 3600 for UTC+1 -#define UTC_OFFSET_S 3600 +#define UTC_OFFSET_S 3600 //NTP server to use, pool is recommended -#define NTP_SERVER "europe.pool.ntp.org" +#define NTP_SERVER "europe.pool.ntp.org" /************************* MQTT Setup ************************************/ @@ -93,36 +94,38 @@ void loop() { } } - i = 0; + i = 0; - if(commRecvd == true){ - if(strcmp("?ntp", incoming) == 0){ //if request for time update received, process time update - while(!timeClient.update()){ //update from ntp server - delay(10); //time sync is critical, wait for succesful update - }; - Serial.print(">"); //indicate time data - Serial.print(timeClient.getYear()); - Serial.print(","); - Serial.print(timeClient.getMonth()); - Serial.print(","); - Serial.print(timeClient.getDate()); - Serial.print(","); - Serial.print(timeClient.getHours()); - Serial.print(","); - Serial.print(timeClient.getMinutes()); - Serial.print(","); - Serial.print(timeClient.getSeconds()); - Serial.print('\n'); - delay(1000); //give time to process comm - } else { - Serial.print("esp: recvd: "); - Serial.println(incoming); - test.publish(incoming); - Serial.println("esp: sent data"); +if(commRecvd == true){ + if(strcmp("?ntp", incoming) == 0){ //if request for time update received, process time update + while(!timeClient.update()){ //update from ntp server + delay(10); //time sync is critical, wait for succesful update + Serial.print("\\"); }; - commRecvd = false; - } - delay(100);; + Serial.print(">"); //indicate time data + delay(50); + Serial.print(timeClient.getYear()); + Serial.print("/"); + Serial.print(timeClient.getMonth()); + Serial.print("/"); + Serial.print(timeClient.getDate()); + Serial.print("/"); + Serial.print(timeClient.getHours()); + Serial.print("/"); + Serial.print(timeClient.getMinutes()); + Serial.print("/"); + Serial.print(timeClient.getSeconds()); + Serial.print('\n'); + delay(1000); //give time to process comm + } else { + Serial.print("esp: recvd: "); + Serial.println(incoming); + test.publish(incoming); + Serial.println("esp: sent data"); + }; + commRecvd = false; +} + delay(100);; } // Function to connect and reconnect as necessary to the MQTT server.