add OTA
This commit is contained in:
parent
471bfbe6ac
commit
4efdbb3d63
@ -13,7 +13,11 @@
|
||||
#include <RTClib.h> // Date and time functions using a DS1307 RTC connected via I2C and Wire lib. https://github.com/adafruit/RTClib
|
||||
#include <NTP.h> // The NTP library allows you to receive time information from the Internet. https://github.com/sstaub/NTP
|
||||
#include "nixie.h" // Mes routines de pilotage d'affichage Nixie
|
||||
#include <FastLED.h>
|
||||
#include <FastLED.h> // https://github.com/FastLED/FastLED
|
||||
|
||||
#include <ESPmDNS.h>
|
||||
#include <NetworkUdp.h>
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
// Number of leds in your strip
|
||||
#define NUM_LEDS 4
|
||||
@ -27,10 +31,12 @@ bool wifiOK, ntpOK, rtcOK;
|
||||
unsigned long LastRTCUpdate; // le temps de dernière MAJ de l'horloge interne RTC
|
||||
unsigned long LastNixieUpdate; // le temps de dernière MAJ affichage Nixie
|
||||
unsigned long LastDotUpdate; // le temps de dernière MAJ de l'affichage du point des secondes
|
||||
unsigned long LastLedUpdate; // le temps de dernière MAJ des leds RGB
|
||||
int heu_d, heu_u, min_d, min_u, sec_d, sec_u;
|
||||
int brightnessInput, brightnessLeds ; //for RGB led brightness
|
||||
byte brightnessInput, brightnessLeds ; //for RGB led brightness
|
||||
byte randomR, randomG, randomB; // for RGB led random colors
|
||||
|
||||
const long intervalRTCUpdate = 3600000; // 86400000 = 24 heures / 3600000 = 1 heure
|
||||
const long intervalRTCUpdate = 600000; // 86400000 = 24 heures / 3600000 = 1 heure / 600000 = 10 minutes
|
||||
const long intervalNixieUpdate = 1000; // 1000 = 1 seconde
|
||||
|
||||
WiFiUDP wifiUdp;
|
||||
@ -163,10 +169,13 @@ void setup() {
|
||||
Serial.println("Liaison série OK");
|
||||
|
||||
//// Initialisation des LEDs RGB
|
||||
FastLED.addLeds<WS2812B, LEDS_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
|
||||
FastLED.addLeds<WS2812B, LEDS_PIN>(leds, NUM_LEDS); // GRB ordering is typical - avant : FastLED.addLeds<WS2812B, LEDS_PIN, RGB>(leds, NUM_LEDS);
|
||||
FastLED.setBrightness(16);
|
||||
leds[0] = CRGB::Black;
|
||||
FastLED.show();
|
||||
randomR = random(256);
|
||||
randomG = random(256);
|
||||
randomB = random(256);
|
||||
|
||||
wifiOK = initWIFI(); // initialisation du wifi
|
||||
initNTP(); // récupération du temps Internet
|
||||
@ -177,6 +186,59 @@ void setup() {
|
||||
syncNTPtoRTC(); // Mise à l'heure de l'horloge RTC locale avec l'heure Internet
|
||||
printRTC(); // Affichage du temps RTC en console série
|
||||
}
|
||||
|
||||
// Port defaults to 3232
|
||||
// ArduinoOTA.setPort(3232);
|
||||
|
||||
// Hostname defaults to esp3232-[MAC]
|
||||
// ArduinoOTA.setHostname("myesp32");
|
||||
|
||||
// No authentication by default
|
||||
// ArduinoOTA.setPassword("admin");
|
||||
|
||||
// Password can be set with it's md5 value as well
|
||||
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
|
||||
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
|
||||
|
||||
ArduinoOTA
|
||||
.onStart([]() {
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH) {
|
||||
type = "sketch";
|
||||
} else { // U_SPIFFS
|
||||
type = "filesystem";
|
||||
}
|
||||
|
||||
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
||||
Serial.println("Start updating " + type);
|
||||
})
|
||||
.onEnd([]() {
|
||||
Serial.println("\nEnd");
|
||||
})
|
||||
.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
})
|
||||
.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) {
|
||||
Serial.println("Auth Failed");
|
||||
} else if (error == OTA_BEGIN_ERROR) {
|
||||
Serial.println("Begin Failed");
|
||||
} else if (error == OTA_CONNECT_ERROR) {
|
||||
Serial.println("Connect Failed");
|
||||
} else if (error == OTA_RECEIVE_ERROR) {
|
||||
Serial.println("Receive Failed");
|
||||
} else if (error == OTA_END_ERROR) {
|
||||
Serial.println("End Failed");
|
||||
}
|
||||
});
|
||||
|
||||
ArduinoOTA.begin();
|
||||
|
||||
Serial.println("Ready");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
Serial.print("Pour info, le temps de compil : ");
|
||||
Serial.print(__DATE__);
|
||||
Serial.print(" - ");
|
||||
@ -191,6 +253,8 @@ void setup() {
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
void loop() {
|
||||
ArduinoOTA.handle();
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
// Mise à jour de l'affichage Nixie
|
||||
@ -205,25 +269,34 @@ void loop() {
|
||||
sec_d = (now.second()) / 10;
|
||||
sec_u = (now.second()) % 10;
|
||||
|
||||
printRTC();
|
||||
|
||||
// Si c'est la nuit alors réduire la luminosité des leds
|
||||
if ((now.hour()> 21) || (now.hour() < 8)) {
|
||||
FastLED.setBrightness(10);
|
||||
} else {
|
||||
brightnessInput = analogRead(IN_PHOTO_R); // read the input pin
|
||||
FastLED.setBrightness(brightnessInput/16);
|
||||
FastLED.setBrightness(brightnessInput/2);
|
||||
}
|
||||
}
|
||||
|
||||
int aupif = random(0, 4);
|
||||
int randomR = random(255);
|
||||
int randomG = random(255);
|
||||
int randomB = random(255);
|
||||
|
||||
// Mise à jour de l'affichage des led RGB x fois par seconde
|
||||
if ((currentMillis - LastLedUpdate > 50) || (currentMillis < LastLedUpdate)) {
|
||||
LastLedUpdate = currentMillis;
|
||||
|
||||
randomR += random(3) - 1;
|
||||
randomG += random(3) - 1;
|
||||
randomB += random(3) - 1;
|
||||
byte aupif = random(4);
|
||||
leds[aupif] = CRGB(randomR, randomG, randomB);
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
// allumage du point une seconde puis éteint une seconde
|
||||
// allumage du point x seconde puis éteint x seconde
|
||||
// utilisation du digit "9" du Nixie 3 (dizaines de minutes)
|
||||
if ((currentMillis - LastDotUpdate < 1000) || (currentMillis < LastDotUpdate)) {
|
||||
printNixie3(9);
|
||||
delay(5);
|
||||
digitalWrite(NX3A, 0); //Switch OFF Anode Nixie 1
|
||||
digitalWrite(NX3A, 0); //Switch OFF Anode Nixie 3
|
||||
} else {
|
||||
if ((currentMillis - LastDotUpdate < 2000) || (currentMillis < LastDotUpdate)) {
|
||||
delay(5);
|
||||
@ -238,15 +311,15 @@ void loop() {
|
||||
|
||||
printNixie2(heu_u);
|
||||
delay(5);
|
||||
digitalWrite(NX2A, 0); //Switch OFF Anode Nixie 1
|
||||
digitalWrite(NX2A, 0); //Switch OFF Anode Nixie 2
|
||||
|
||||
printNixie3(min_d);
|
||||
delay(5);
|
||||
digitalWrite(NX3A, 0); //Switch OFF Anode Nixie 1
|
||||
digitalWrite(NX3A, 0); //Switch OFF Anode Nixie 3
|
||||
|
||||
printNixie4(min_u);
|
||||
delay(5);
|
||||
digitalWrite(NX4A, 0); //Switch OFF Anode Nixie 1
|
||||
digitalWrite(NX4A, 0); //Switch OFF Anode Nixie 4
|
||||
|
||||
// Mise à jour de l'horloge interne RTC. Une fois par 24H
|
||||
if ((currentMillis - LastRTCUpdate >= intervalRTCUpdate) || (currentMillis < LastRTCUpdate)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user