Browse Source

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

pull/1/head
Vladimir Smagin 6 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) {

String NTPClient::getDateStr (time_t moment) {
char dateStr[12];
sprintf (dateStr, " %02d-%02d", day (moment), month (moment), year (moment));
sprintf (dateStr, "%02d-%02d", day (moment), month (moment));

return dateStr;
}

String NTPClient::getTimeDateString (time_t moment) {
return getTimeStr (moment) + " " + getDateStr (moment);
return getTimeStr (moment) + " " + getDateStr (moment);
}

time_t NTPClient::getLastNTPSync () {

+ 36
- 13
tm1640-ntp.ino View File

@@ -15,11 +15,15 @@

LM1640Display display(CLK, DIO);

HTTPClient http;

boolean syncEventTriggered = false;
NTPSyncEvent_t ntpEvent;
//set timezone
static const int8_t timeZone = 7;
bool wifiFirstConnected = false;
bool ntp_online = false;
String outside_termo = "00";
int outside_termo = 0;


void onSTAConnected (WiFiEventStationModeConnected ipInfo) {
@@ -57,20 +61,12 @@ void processSyncEvent(NTPSyncEvent_t ntpEvent) {
else {
Serial.print("Got NTP time: ");
ntp_online = true;
get_outside_termo();
Serial.println(NTP.getTimeDateString(NTP.getLastNTPSync()));
HTTPClient http;
http.begin("http://termo.tomsk.ru/data.txt");
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
outside_termo = http.getString();
}
}
}
}

boolean syncEventTriggered = false;
NTPSyncEvent_t ntpEvent;


void setup() {
static WiFiEventHandler e1, e2, e3;
@@ -95,6 +91,17 @@ void setup() {
digitalWrite(ONBOARDLED, HIGH); // Switch off LED
}

void get_outside_termo() {
http.begin("http://termo.tomsk.ru/data.txt");
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
String result = http.getString();
outside_termo = round(result.toInt());
}
}
}

void starting() {

NTP.begin("ntp.tomtel.ru", timeZone, true);
@@ -114,7 +121,7 @@ void starting() {
//Serial.println("Connecting");
delay(1000);
}
get_outside_termo();
display.clear();

for (uint8_t l = 0; l <= 7; l++) {
@@ -130,13 +137,29 @@ char timebuff[17];

void loop() {
if (ntp_online == true) {

// sync time
if (syncEventTriggered) {
processSyncEvent (ntpEvent);
syncEventTriggered = false;
}

String timestamp = NTP.getTimeDateString();
String result = timestamp + " " + outside_termo;

// draw temperature
String nozero = "";
String sign;
if (outside_termo < 0) {
sign = "";
} else
{
sign = " ";
}
if (outside_termo > -10 && outside_termo < 10) {
nozero = " ";
}

String result = timestamp + " " + nozero + sign + outside_termo;

//Serial.print(timestamp + "\n");


Loading…
Cancel
Save