implement OTA via Web Server

This commit is contained in:
Jonas Leder 2022-12-22 20:16:59 +01:00
commit aa4a07f4b9
3 changed files with 26 additions and 2 deletions

View file

@ -12,5 +12,7 @@
platform = espressif8266
board = d1_mini_lite
framework = arduino
lib_deps =
fastled/FastLED
lib_deps =
fastled/FastLED
ayushsharma82/AsyncElegantOTA@^2.2.7
ottowinter/ESPAsyncWebServer-esphome@^3.0.0

View file

@ -16,6 +16,10 @@
#define ANIMATION_DURATION 120 //seconds
#define BRIGHTNESS 255
#define MESH_AP_NAME "LED_TREE"
#define MESH_AP_PASSWORD "7uaG2CFmPj"
#define MESH_AP_TIMEOUT 30
/*
* █████ ███ ██ ██ ███ ███ █████ ████████ ██ ██████ ███ ██ ███████
* ██ ██ ████ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ████ ██ ██

View file

@ -1,16 +1,24 @@
#include <Arduino.h>
#include <config.h>
#include <FastLED.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#define ANIMATION_DURATION_MS (ANIMATION_DURATION * 1000)
#define MESH_AP_TIMEOUT_MS (MESH_AP_TIMEOUT * 1000)
#define NUMLEDS (LEDS_STAGE_1 + LEDS_STAGE_2 + LEDS_STAGE_3 + LEDS_STAGE_4 + LEDS_TOP)
CRGB leds[NUMLEDS];
AsyncWebServer server(80);
unsigned long colorScrollTemperature = 0;
unsigned long lastChange = 0;
unsigned long snakeColor = 0;
byte animation = 0;
bool meshApActive = true;
bool meshClientConnected = false;
void colorScroll();
void stars();
@ -20,6 +28,10 @@ void snow();
void setup()
{
WiFi.softAP(MESH_AP_NAME, MESH_AP_PASSWORD);
AsyncElegantOTA.begin(&server);
server.begin();
FastLED.addLeds<WS2812B, LEDPIN_STAGE_1, BRG>(leds, LEDS_STAGE_1);
FastLED.addLeds<WS2812B, LEDPIN_STAGE_2, BRG>(leds, LEDS_STAGE_1, LEDS_STAGE_2);
FastLED.addLeds<WS2812B, LEDPIN_STAGE_3, BRG>(leds, LEDS_STAGE_1 + LEDS_STAGE_2, LEDS_STAGE_3);
@ -53,6 +65,12 @@ void loop()
animation++;
lastChange = millis();
}
if(meshApActive && (millis() > MESH_AP_TIMEOUT_MS ) && (millis() < MESH_AP_TIMEOUT_MS + 60000 ) && (wifi_softap_get_station_num() == 0))
{
meshApActive = false;
WiFi.softAPdisconnect (true);
}
}
void colorScroll()