Browse Source

first commit

master
Vladimir Smagin 10 months ago
commit
ab7534f21d
5 changed files with 205 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 189
    0
      esp8266-samsung-vfd-clock-weather.ino
  3. BIN
      photo.jpg
  4. 12
    0
      readme.md
  5. 3
    0
      wifi.h.sample

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
wifi.h

+ 189
- 0
esp8266-samsung-vfd-clock-weather.ino View File

@@ -0,0 +1,189 @@
#include <SPI_VFD.h>

#include <Wire.h>
#include <TimeLib.h>
#include <NtpClientLib.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <tinyxml2.h>
#include "wifi.h"

using namespace tinyxml2;

#define ONBOARDLED 2 // Built in LED on ESP-12/ESP-07

#define CLK D2
#define STB D3
#define DIO D4

SPI_VFD vfd(DIO, CLK, STB);

//set timezone
static const int8_t timeZone = 7;
bool wifiFirstConnected = false;
bool ntp_online = false;

//set weather
static const char* yandexUrl = "http://blindage.org/weather";

void onSTAConnected (WiFiEventStationModeConnected ipInfo) {
Serial.printf ("Connected to %s\r\n", ipInfo.ssid.c_str ());
}

// Start NTP only after IP network is connected
void onSTAGotIP(WiFiEventStationModeGotIP ipInfo) {
Serial.printf("Got IP: %s\r\n", ipInfo.ip.toString().c_str());
wifiFirstConnected = true;
}

// Manage network disconnection
void onSTADisconnected(WiFiEventStationModeDisconnected event_info) {
Serial.printf("Disconnected from SSID: %s\n", event_info.ssid.c_str());
Serial.printf("Reason: %d\n", event_info.reason);
digitalWrite(ONBOARDLED, HIGH); // Turn off LED
NTP.stop();
ntp_online = false;
}


void processSyncEvent(NTPSyncEvent_t ntpEvent) {
if (ntpEvent) {
Serial.print("Time Sync error: ");
if (ntpEvent == noResponse) {
Serial.println("NTP server not reachable");
ntp_online = false;
}
else if (ntpEvent == invalidAddress) {
Serial.println("Invalid NTP server address");
ntp_online = false;
}
}
else {
Serial.print("Got NTP time: ");
ntp_online = true;
Serial.println(NTP.getTimeDateString(NTP.getLastNTPSync()));

HTTPClient http;
http.begin(yandexUrl);
Serial.println(yandexUrl);
int httpCode = http.GET();
if (httpCode > 0) {
Serial.println(httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
XMLDocument doc;
doc.Parse( payload.c_str() );
XMLElement* dayElement = doc.FirstChildElement( "info" )->FirstChildElement( "weather" )->FirstChildElement( "day" )->FirstChildElement( "day_part" );

const char* temp = dayElement->FirstChildElement( "temperature" )->GetText();
const char* pressure = dayElement->FirstChildElement( "pressure" )->GetText();
const char* dampness = dayElement->FirstChildElement( "dampness" )->GetText();
const char* wind = dayElement->FirstChildElement( "wind_speed" )->GetText();
const char* wind_direction = dayElement->FirstChildElement( "wind_direction" )->Attribute("id");
const char* weather_code = dayElement->FirstChildElement( "weather_code" )->GetText();
vfd.setCursor(0, 1);
vfd.print(" ");
string line = "";
line += temp;
line += " ";
line += wind;
line += " km/h ";
line += wind_direction;
line += " ";
line += dampness;
line += "%";
vfd.setCursor(0, 1);
Serial.println(line.c_str());
vfd.print(line.c_str());
}
}
}
}

boolean syncEventTriggered = false;
NTPSyncEvent_t ntpEvent;

void setup()
{
vfd.begin(20, 2);
vfd.clear();

static WiFiEventHandler e1, e2, e3;
Serial.begin(115200);
vfd.clear();
vfd.setCursor(0, 0);
vfd.print("Connecting WIFI...");
WiFi.mode(WIFI_STA);
WiFi.hostname("clock-vfd");
WiFi.begin(YOUR_WIFI_SSID, YOUR_WIFI_PASSWD);

pinMode(ONBOARDLED, OUTPUT); // Onboard LED
digitalWrite(ONBOARDLED, HIGH); // Switch off LED

NTP.onNTPSyncEvent([](NTPSyncEvent_t event) {
ntpEvent = event;
syncEventTriggered = true;
});

e1 = WiFi.onStationModeGotIP(onSTAGotIP);// As soon WiFi is connected, start NTP Client
e2 = WiFi.onStationModeDisconnected(onSTADisconnected);
e3 = WiFi.onStationModeConnected (onSTAConnected);

}

void starting() {

NTP.begin("ntp.tomtel.ru", timeZone, true);
NTP.setInterval(10, 600);

vfd.clear();

//Serial.println("Starting NTP client");

while (ntp_online == false) {
if (syncEventTriggered) {
processSyncEvent (ntpEvent);
syncEventTriggered = true;
}
vfd.clear();
vfd.print("Connecting NTP...");
Serial.println("Connecting NTP...");
delay(1000);
}

vfd.clear();

vfd.setCursor(0, 0);
vfd.print("CLOCK-VFD by");
vfd.setCursor(0, 1);
vfd.print("Vladimir Smagin");
delay(2000);
vfd.clear();
}

char timebuff[21];

void loop()
{
if (ntp_online == true) {
if (syncEventTriggered) {
processSyncEvent (ntpEvent);
syncEventTriggered = false;
}

String timestamp = NTP.getTimeDateString();

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

timestamp.toCharArray(timebuff, 21);

delay(100);
vfd.setCursor(0, 0);
vfd.print(timestamp);
} else {
starting();
}

}

BIN
photo.jpg View File


+ 12
- 0
readme.md View File

@@ -0,0 +1,12 @@
# Samsung VFD with ESP8266 NTP clock and weather

Requirements:

* Library for 20T202DA2JA SPI VFD (see arduino library)
* NtpClient
* Arduino Time Library
* [TinyXML2](https://github.com/leethomason/tinyxml2)

Use [openweathermap.org](https://openweathermap.org/api). My URL works only for my city!

![samsung vfd esp8266](photo.png)

+ 3
- 0
wifi.h.sample View File

@@ -0,0 +1,3 @@
#define YOUR_WIFI_SSID "supapupamegawifi"
#define YOUR_WIFI_PASSWD "sexdrugsrickroll"


Loading…
Cancel
Save