@@ -22,7 +22,7 @@ ESP8266WiFiMulti wifiMulti;
2222#define WIFI_AUTH_OPEN ENC_TYPE_NONE
2323#endif
2424
25- #include < InfluxDbClient.h
25+ #include < InfluxDbClient.h>
2626#include < InfluxDbCloud.h>
2727
2828// WiFi AP SSID
@@ -44,6 +44,10 @@ ESP8266WiFiMulti wifiMulti;
4444// Japanesse: "JST-9"
4545// Central Europe: "CET-1CEST,M3.5.0,M10.5.0/3"
4646#define TZ_INFO " CET-1CEST,M3.5.0,M10.5.0/3"
47+ // NTP servers the for time syncronozation.
48+ // For the fastest time sync find NTP servers in your area: https://www.pool.ntp.org/zone/
49+ #define NTP_SERVER1 " pool.ntp.org"
50+ #define NTP_SERVER2 " time.nis.gov"
4751#define WRITE_PRECISION WritePrecision::S
4852#define MAX_BATCH_SIZE 10
4953#define WRITE_BUFFER_SIZE 30
@@ -76,9 +80,8 @@ void setup() {
7680 sensorStatus.addTag (" SSID" , WiFi.SSID ());
7781
7882 // Accurate time is necessary for certificate validation and writing in batches
79- // For the fastest time sync find NTP servers in your area: https://www.pool.ntp.org/zone/
8083 // Syncing progress and the time will be printed to Serial.
81- timeSync (TZ_INFO, " pool.ntp.org " , " time.nis.gov " );
84+ timeSync (TZ_INFO, NTP_SERVER1, NTP_SERVER2 );
8285
8386 // Check server connection
8487 if (client.validateConnection ()) {
@@ -89,22 +92,22 @@ void setup() {
8992 Serial.println (client.getLastErrorMessage ());
9093 }
9194
92- // Enable messages batching and retry buffer
95+ // Enable messages batching and retry buffer
9396 client.setWriteOptions (WRITE_PRECISION, MAX_BATCH_SIZE, WRITE_BUFFER_SIZE);
9497}
9598
9699void loop () {
97100 // Sync time for batching once per hour
98101 if (iterations++ >= 360 ) {
99- timeSync ();
102+ timeSync (TZ_INFO, NTP_SERVER1, NTP_SERVER2 );
100103 iterations = 0 ;
101104 }
102105
103- // Report networks (low priority data) just in case we successfully wrote the previous batch
106+ // Report networks (low priority data) just in case we successfully wrote the previous batch
104107 if (client.isBufferEmpty ()) {
105108 // Report all the detected wifi networks
106109 int networks = WiFi.scanNetworks ();
107- // Set identical time for the whole network scan
110+ // Set identical time for the whole network scan
108111 time_t tnow = time (nullptr );
109112 for (int i = 0 ; i < networks; i++) {
110113 Point sensorNetworks (" wifi_networks" );
@@ -152,7 +155,7 @@ void loop() {
152155 Serial.println (client.isBufferFull () ? " Yes" : " No" );
153156 }
154157
155- // Wait 10s
158+ // Wait 10s
156159 Serial.println (" Wait 10s" );
157160 delay (10000 );
158161}
0 commit comments