Initial
This commit is contained in:
+128
@@ -0,0 +1,128 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <Ethernet.h>
|
||||
#include <EthernetClient.h>
|
||||
#include <EthernetUdp.h>
|
||||
|
||||
// ******* Netzwerkeinstellungen, bitte anpassen! ********
|
||||
const char* ssid = "FingerWeg_nomap"; // SSID des vorhandenen WLANs
|
||||
const char* password = "9430080574628949"; // Passwort für das vorhandene WLAN
|
||||
byte mac[] = {
|
||||
0x90, 0xA2, 0xDA, 0x0D, 0x5E, 0xA6
|
||||
};
|
||||
long ntp1 = 0;
|
||||
char timeServer[] = "time.nist.gov";
|
||||
unsigned int localPort = 8888;
|
||||
EthernetUDP Udp;
|
||||
const int NTP_PACKET_SIZE = 48;
|
||||
byte packetBuffer[NTP_PACKET_SIZE];
|
||||
int mySecInt = 0;
|
||||
int myMinInt = 0;
|
||||
int myStdInt = 0;
|
||||
int delayval = 1000; // delay for half a second
|
||||
int cronixie[60] = {5, 0, 6, 1, 7, 2, 8, 3, 9, 4, 15, 10, 16, 11, 17, 12, 18, 13, 19, 14, 25, 20, 26, 21, 27, 22, 28, 23, 29, 24, 35, 30, 36, 31, 37, 32, 38, 33, 39, 34, 45, 40, 46, 41, 47, 42, 48, 43, 49, 44, 55, 50, 56, 51, 57, 52, 58, 53, 59, 54};
|
||||
int sec1 = 5;
|
||||
int sec2 = 5;
|
||||
int min1 = 8;
|
||||
int min2 = 5;
|
||||
int std1 = 3;
|
||||
int std2 = 1;
|
||||
|
||||
void sendNTPpacket(char* address) {
|
||||
Serial.println("sendNTPpacket");
|
||||
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
packetBuffer[0] = 0b11100011;
|
||||
packetBuffer[1] = 0;
|
||||
packetBuffer[2] = 6;
|
||||
packetBuffer[3] = 0xEC;
|
||||
packetBuffer[12] = 49;
|
||||
packetBuffer[13] = 0x4E;
|
||||
packetBuffer[14] = 49;
|
||||
packetBuffer[15] = 52;
|
||||
Serial.println(address);
|
||||
//Serial.println(packetBuffer);
|
||||
|
||||
Udp.beginPacket(address, 123);
|
||||
Serial.println("Udp.beginPacket");
|
||||
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
Serial.println("Udp.write");
|
||||
Udp.endPacket();
|
||||
Serial.println("Udp.endPacket");
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Seriellen Monitor für Kontrollausgaben öffnen
|
||||
Serial.begin(9600);
|
||||
Serial.println("WeMos Cronixie");
|
||||
|
||||
// WLAN-Verbindung herstellen
|
||||
WiFi.begin(ssid, password);
|
||||
Serial.print("Verbindungsaufbau");
|
||||
|
||||
// Verbindungsaufbau abwarten
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println(" erfolgreich!");
|
||||
Serial.print("Verbunden mit: ");
|
||||
Serial.println(ssid);
|
||||
Serial.print("Signalstaerke: ");
|
||||
int rssi = WiFi.RSSI();
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
Serial.print("IP-Adresse: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.println("");
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
Serial.println("Failed to configure Ethernet usind DHCP");
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
Udp.begin(localPort);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println(ntp1);
|
||||
if (ntp1 == 0) {
|
||||
Serial.println(ntp1);
|
||||
sendNTPpacket(timeServer);
|
||||
delay(1000);
|
||||
Serial.println(ntp1);
|
||||
if (Udp.parsePacket()) {
|
||||
Udp.read(packetBuffer, NTP_PACKET_SIZE);
|
||||
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
||||
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
||||
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
||||
const unsigned long seventyYears = 2208988800UL;
|
||||
unsigned long epoch = secsSince1900 - seventyYears;
|
||||
Serial.print("The UTC time is ");
|
||||
myStdInt = (epoch % 86400L) / 3600;
|
||||
Serial.print(myStdInt);
|
||||
Serial.print(':');
|
||||
myMinInt = (epoch % 3600) / 60;
|
||||
Serial.print(myMinInt);
|
||||
Serial.print(':');
|
||||
mySecInt = epoch % 60;
|
||||
Serial.println(mySecInt);
|
||||
sec2 = (mySecInt % 100) / 10; // Zehner berechnen
|
||||
sec1 = mySecInt % 10; // Einer berechnen
|
||||
min2 = (myMinInt % 100) / 10; // Zehner berechnen
|
||||
min1 = myMinInt % 10; // Einer berechnen
|
||||
std2 = (myStdInt % 100) / 10; // Zehner berechnen
|
||||
std1 = (myStdInt % 10) + 2; // Einer berechnen
|
||||
if (std1 > 23) {
|
||||
std1 = std1 - 24;
|
||||
}
|
||||
}
|
||||
Ethernet.maintain();
|
||||
ntp1 = 86400;
|
||||
}
|
||||
ntp1--;
|
||||
Serial.println(ntp1);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user