Browse Source

погода теперь лучше

pull/1/head
Vladimir Smagin 4 months ago
parent
commit
f63bfb8e1c
2 changed files with 38 additions and 15 deletions
  1. 2
    2
      NTPClientLib.cpp
  2. 36
    13
      tm1640-ntp.ino

+ 2
- 2
NTPClientLib.cpp View File

@@ -288,13 +288,13 @@ String NTPClient::getTimeStr (time_t moment) {
288 288
 
289 289
 String NTPClient::getDateStr (time_t moment) {
290 290
     char dateStr[12];
291
-    sprintf (dateStr, " %02d-%02d", day (moment), month (moment), year (moment));
291
+    sprintf (dateStr, "%02d-%02d", day (moment), month (moment));
292 292
 
293 293
     return dateStr;
294 294
 }
295 295
 
296 296
 String NTPClient::getTimeDateString (time_t moment) {
297
-    return getTimeStr (moment) + " " + getDateStr (moment);
297
+    return getTimeStr (moment) + "  " + getDateStr (moment);
298 298
 }
299 299
 
300 300
 time_t NTPClient::getLastNTPSync () {

+ 36
- 13
tm1640-ntp.ino View File

@@ -15,11 +15,15 @@
15 15
 
16 16
 LM1640Display display(CLK, DIO);
17 17
 
18
+HTTPClient http;
19
+
20
+boolean syncEventTriggered = false;
21
+NTPSyncEvent_t ntpEvent;
18 22
 //set timezone
19 23
 static const int8_t timeZone = 7;
20 24
 bool wifiFirstConnected = false;
21 25
 bool ntp_online = false;
22
-String outside_termo = "00";
26
+int outside_termo = 0;
23 27
 
24 28
 
25 29
 void onSTAConnected (WiFiEventStationModeConnected ipInfo) {
@@ -57,20 +61,12 @@ void processSyncEvent(NTPSyncEvent_t ntpEvent) {
57 61
   else {
58 62
     Serial.print("Got NTP time: ");
59 63
     ntp_online = true;
64
+    get_outside_termo();
60 65
     Serial.println(NTP.getTimeDateString(NTP.getLastNTPSync()));
61
-    HTTPClient http;
62
-    http.begin("http://termo.tomsk.ru/data.txt");
63
-    int httpCode = http.GET();
64
-    if (httpCode > 0) {
65
-      if (httpCode == HTTP_CODE_OK) {
66
-        outside_termo = http.getString();
67
-      }
68
-    }
69 66
   }
70 67
 }
71 68
 
72
-boolean syncEventTriggered = false;
73
-NTPSyncEvent_t ntpEvent;
69
+
74 70
 
75 71
 void setup() {
76 72
   static WiFiEventHandler e1, e2, e3;
@@ -95,6 +91,17 @@ void setup() {
95 91
   digitalWrite(ONBOARDLED, HIGH); // Switch off LED
96 92
 }
97 93
 
94
+void get_outside_termo() {
95
+  http.begin("http://termo.tomsk.ru/data.txt");
96
+  int httpCode = http.GET();
97
+  if (httpCode > 0) {
98
+    if (httpCode == HTTP_CODE_OK) {
99
+      String result = http.getString();
100
+      outside_termo = round(result.toInt());
101
+    }
102
+  }
103
+}
104
+
98 105
 void starting() {
99 106
 
100 107
   NTP.begin("ntp.tomtel.ru", timeZone, true);
@@ -114,7 +121,7 @@ void starting() {
114 121
     //Serial.println("Connecting");
115 122
     delay(1000);
116 123
   }
117
-
124
+  get_outside_termo();
118 125
   display.clear();
119 126
 
120 127
   for (uint8_t l = 0; l <= 7; l++) {
@@ -130,13 +137,29 @@ char timebuff[17];
130 137
 
131 138
 void loop() {
132 139
   if (ntp_online == true) {
140
+
141
+    // sync time
133 142
     if (syncEventTriggered) {
134 143
       processSyncEvent (ntpEvent);
135 144
       syncEventTriggered = false;
136 145
     }
137 146
 
138 147
     String timestamp = NTP.getTimeDateString();
139
-    String result = timestamp + " " + outside_termo;
148
+
149
+    // draw temperature
150
+    String nozero = "";
151
+    String sign;
152
+    if (outside_termo < 0) {
153
+      sign = "";
154
+    } else
155
+    {
156
+      sign = " ";
157
+    }
158
+    if (outside_termo > -10 && outside_termo < 10) {
159
+      nozero = " ";
160
+    }
161
+
162
+    String result = timestamp + " " + nozero + sign + outside_termo;
140 163
 
141 164
     //Serial.print(timestamp + "\n");
142 165
 

Loading…
Cancel
Save