Initial commit

This commit is contained in:
2023-10-31 14:52:26 +01:00
parent b59860bd86
commit 97aa2c5c7f
7 changed files with 255 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

10
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

39
include/README Normal file
View File

@@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
lib/README Normal file
View File

@@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

16
platformio.ini Normal file
View File

@@ -0,0 +1,16 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
monitor_speed = 115200

128
src/main.cpp Normal file
View File

@@ -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);
}

11
test/README Normal file
View File

@@ -0,0 +1,11 @@
This directory is intended for PlatformIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html