From 0f028e6757bc94566b881935ef4ade8bcd4854b8 Mon Sep 17 00:00:00 2001 From: Laurent Claude Date: Mon, 5 Jun 2023 09:57:54 +0200 Subject: [PATCH] =?UTF-8?q?debut=20de=20pilotage=20Nixie=20debut=20de=20co?= =?UTF-8?q?nnexion=20wifi=20debut=20de=20r=C3=A9up=C3=A9ration=20heure=20e?= =?UTF-8?q?n=20ntp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Horloge_Nixie_firmware.ino | 4 +++- README.md | 2 ++ horlogerie.cpp | 49 ++++++++++++++++++++++++++++++++++++++ horlogerie.h | 11 +++++++++ secrets.h.default | 2 ++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 horlogerie.cpp create mode 100644 horlogerie.h create mode 100644 secrets.h.default diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03b2b46 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +secrets.h diff --git a/Horloge_Nixie_firmware.ino b/Horloge_Nixie_firmware.ino index c8452c9..b851a67 100644 --- a/Horloge_Nixie_firmware.ino +++ b/Horloge_Nixie_firmware.ino @@ -8,6 +8,8 @@ #include "hardware.h" #include "nixie.h" +#include "horlogerie.h" +#include "secrets.h" // Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include @@ -46,7 +48,7 @@ void setup () { // sets the RTC with an explicit date & time, for example to set // January 21, 2021 at 3am you would call: // rtc.adjust(DateTime(2021, 1, 21, 3, 0, 0)); - + initwifintp(); } void loop () { diff --git a/README.md b/README.md index 68d51a3..24310e9 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ Firmware ESP32 pour mon horloge Nixie + +Utilise les librairies : wifi, NTPClient, WiFiUdp \ No newline at end of file diff --git a/horlogerie.cpp b/horlogerie.cpp new file mode 100644 index 0000000..1766b02 --- /dev/null +++ b/horlogerie.cpp @@ -0,0 +1,49 @@ +#include "horlogerie.h" +#include "Arduino.h" +#include "hardware.h" +#include "secrets.h" + +#include +#include +#include + + +void initwifintp() { + + // Replace with your network credentials (see in 'arduino_secrets.h' file) + char ssid[] = SECRET_WIFI_SSID; + const char* password = SECRET_WIFI_PASS; + + // Define NTP Client to get time + WiFiUDP ntpUDP; + NTPClient timeClient(ntpUDP); + + // Variables to save date and time + String formattedDate; + String dayStamp; + String timeStamp; + + // Initialize Serial Monitor + Serial.begin(115200); + Serial.print("Connecting to "); + Serial.println(ssid); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(100); + Serial.print("."); + } + // Print local IP address and start web server + Serial.println(""); + Serial.println("WiFi connected."); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + + // Initialize a NTPClient to get time + timeClient.begin(); + // Set offset time in seconds to adjust for your timezone, for example: + // GMT +1 = 3600 + // GMT +8 = 28800 + // GMT -1 = -3600 + // GMT 0 = 0 + timeClient.setTimeOffset(3600); +} \ No newline at end of file diff --git a/horlogerie.h b/horlogerie.h new file mode 100644 index 0000000..e53e38c --- /dev/null +++ b/horlogerie.h @@ -0,0 +1,11 @@ +/* fichier nixie.h */ +#include "Arduino.h" +#include "hardware.h" +#include "secrets.h" + +#include +#include +#include + + +void initwifintp(); \ No newline at end of file diff --git a/secrets.h.default b/secrets.h.default new file mode 100644 index 0000000..c13a152 --- /dev/null +++ b/secrets.h.default @@ -0,0 +1,2 @@ +#define SECRET_WIFI_SSID "YOUR_SSID" +#define SECRET_WIFI_PASS "YOUR_PASS"