@@ -22,7 +22,7 @@ ESP8266WiFiMulti wifiMulti;
22
22
#define WIFI_AUTH_OPEN ENC_TYPE_NONE
23
23
#endif
24
24
25
- #include < InfluxDbClient.h
25
+ #include < InfluxDbClient.h>
26
26
#include < InfluxDbCloud.h>
27
27
28
28
// WiFi AP SSID
@@ -44,6 +44,10 @@ ESP8266WiFiMulti wifiMulti;
44
44
// Japanesse: "JST-9"
45
45
// Central Europe: "CET-1CEST,M3.5.0,M10.5.0/3"
46
46
#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"
47
51
#define WRITE_PRECISION WritePrecision::S
48
52
#define MAX_BATCH_SIZE 10
49
53
#define WRITE_BUFFER_SIZE 30
@@ -76,9 +80,8 @@ void setup() {
76
80
sensorStatus.addTag (" SSID" , WiFi.SSID ());
77
81
78
82
// 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/
80
83
// 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 );
82
85
83
86
// Check server connection
84
87
if (client.validateConnection ()) {
@@ -89,22 +92,22 @@ void setup() {
89
92
Serial.println (client.getLastErrorMessage ());
90
93
}
91
94
92
- // Enable messages batching and retry buffer
95
+ // Enable messages batching and retry buffer
93
96
client.setWriteOptions (WRITE_PRECISION, MAX_BATCH_SIZE, WRITE_BUFFER_SIZE);
94
97
}
95
98
96
99
void loop () {
97
100
// Sync time for batching once per hour
98
101
if (iterations++ >= 360 ) {
99
- timeSync ();
102
+ timeSync (TZ_INFO, NTP_SERVER1, NTP_SERVER2 );
100
103
iterations = 0 ;
101
104
}
102
105
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
104
107
if (client.isBufferEmpty ()) {
105
108
// Report all the detected wifi networks
106
109
int networks = WiFi.scanNetworks ();
107
- // Set identical time for the whole network scan
110
+ // Set identical time for the whole network scan
108
111
time_t tnow = time (nullptr );
109
112
for (int i = 0 ; i < networks; i++) {
110
113
Point sensorNetworks (" wifi_networks" );
@@ -152,7 +155,7 @@ void loop() {
152
155
Serial.println (client.isBufferFull () ? " Yes" : " No" );
153
156
}
154
157
155
- // Wait 10s
158
+ // Wait 10s
156
159
Serial.println (" Wait 10s" );
157
160
delay (10000 );
158
161
}
0 commit comments