Compare commits

..

8 Commits

61 changed files with 218 additions and 145 deletions

32
include/SimpleEffect.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include "Effect.h"
#include "prototypes.h"
#include <cmath>
#define SE_CYCLE_COLORS 1 // Slowly cycle through the rainbow.
#define SE_RANDOM_PIXEL_COLORS 2 // Every pixel gets a random color every frame.
#define SE_ONLY_POSITIVE 4 // Only use colors, not white. This is equivalent to running your output through abs()
#define SE_FADEOUT 8 // Fades the old image out. Returning 0 doesn't change the pixel's value.
#define SE_RANDOM_STATIC_COLOR 16 // Sets a random static color at start of the effect.
#define SE_DEBUG 32 // Prints debug messages.
class SimpleEffect : public Effect {
protected:
Window* window = &Window::window_full; // Use a full screen window per default.
uint8_t _color = 0;
uint16_t _flags;
String _name;
simple_effect_t _method;
public:
SimpleEffect(String name, uint16_t flags, simple_effect_t method): _name { name }, _method { method } {
_flags = flags;
if (_flags & SE_RANDOM_STATIC_COLOR) {
_color = random8();
_flags &= ~SE_CYCLE_COLORS & ~SE_RANDOM_PIXEL_COLORS;
}
};
void loop(uint16_t ms) override;
String get_name() { return _name; };
boolean can_be_shown_with_clock() { return true; }
};

View File

@ -1,20 +0,0 @@
#pragma once
#include "Effect.h"
#include "my_fastled.h"
class ConfettiEffect : public Effect {
protected:
virtual CRGB _getColor();
public:
void loop(uint16_t ms);
boolean can_be_shown_with_clock();
String get_name() override { return "confetti"; }
};
class RandomConfettiEffect : public ConfettiEffect {
protected:
CRGB _getColor() override;
String get_name() override { return "random_confetti"; }
};

View File

@ -1,8 +1,10 @@
#pragma once #pragma once
#include "Effect.h" #include "Effect.h"
#include "effect_clock.h" #include "effects/clock.h"
#include "effect_timer.h" #include "effects/timer.h"
#define SIMPLE_EFFECT(name, use_in_cycle, flags, ...) {name, use_in_cycle, [](){ return new SimpleEffect(name, flags, [](double t, uint16_t i, uint8_t x, uint8_t y)->double __VA_ARGS__ ); }}
struct EffectEntry { struct EffectEntry {
const char* name; const char* name;

View File

@ -19,9 +19,12 @@ public:
virtual void loop(uint16_t ms); virtual void loop(uint16_t ms);
String get_name() override { return "big_clock"; } String get_name() override { return "big_clock"; }
}; };
<<<<<<< HEAD:include/effects/big_clock.h
=======
class NightClockEffect : public BigClockEffect { class NightClockEffect : public BigClockEffect {
private: private:
void _draw_border_pixel(accum88 pos, CRGB* color) { }; void _draw_border_pixel(accum88 pos, CRGB* color) { };
CRGB _get_color_font() { return CRGB(0x220000); } CRGB _get_color_font() { return CRGB(0x220000); }
}; };
>>>>>>> ecf5998510bf1f8230d070cebccb4c89f95ce856:include/effect_big_clock.h

View File

@ -0,0 +1,8 @@
#pragma once
#include "Effect.h"
class NightClockEffect : public Effect {
public:
virtual void loop(uint16_t ms);
String get_name() override { return "night_clock"; }
};

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
#include "my_fastled.h"
extern uint8_t baseHue; extern uint8_t baseHue;
extern char hostname[30]; extern char hostname[30];
@ -31,3 +32,5 @@ typedef struct {
uint16_t x; uint16_t x;
uint16_t y; uint16_t y;
} Coords; } Coords;
typedef std::function<double(double, uint16_t, uint8_t, uint8_t)> simple_effect_t;

35
src/SimpleEffect.cpp Normal file
View File

@ -0,0 +1,35 @@
#include "SimpleEffect.h"
void SimpleEffect::loop(uint16_t ms) {
if (_flags & SE_FADEOUT) window->fadeToBlackBy(3);
double t = 0.001 * millis();
for(uint8_t x=0; x<window->width; x++) for(uint8_t y=0; y<window->height; y++) {
uint16_t i = y*window->width + x;
double r = _method(t, i, x, y);
//if (i==0) Serial.printf("t=%f i=%d x=%d y=%d => r=%f, abs(r)=%d\n", t, i, x, y, r, abs(r)*255);
if ((_flags & SE_DEBUG) && i==17) Serial.printf("t=%f i=%d x=%d y=%d => r=%f, abs(r*255)=%d\n", t, i, x, y, r, (int)abs(r*255));
if ((_flags & SE_FADEOUT) && r==0) {
continue;
}
// Clamp r between -1.0 and +1.0
if (r<-1.0) {
r = -1.0;
} else if (r>1.0) {
r = 1.0;
}
if (_flags & SE_ONLY_POSITIVE) {
r = abs(r);
}
CRGB color;
if (_flags & SE_RANDOM_PIXEL_COLORS) {
color = CHSV(random8(), 255, abs(r*255));
} else {
color = CHSV(_flags & SE_CYCLE_COLORS ? baseHue : _color, r<0?0:255, abs(r*255));
}
window->setPixel(x, y, &color);
}
}

View File

@ -1,22 +0,0 @@
#include "effect_confetti.h"
#include "config.h"
#include "functions.h"
#include "prototypes.h"
void ConfettiEffect::loop(uint16_t ms) {
window->fadeToBlackBy(3);
for (int i=0; i<settings.effects.confetti.pixels_per_loop; i++) {
CRGB color = _getColor();
window->addPixelColor(random16(LED_COUNT), &color);
}
}
CRGB ConfettiEffect::_getColor() {
return CHSV(baseHue + random8(64), 255, 255);
}
CRGB RandomConfettiEffect::_getColor() {
return CHSV(random8(), 255, 255);
}
boolean ConfettiEffect::can_be_shown_with_clock() { return true; };

View File

@ -1,31 +1,32 @@
#include "effects.h" #include "effects.h"
#include "config.h" #include "config.h"
#include "my_fastled.h" #include "my_fastled.h"
#include "effect_bell.h" #include "effects/bell.h"
#include "effect_sinematrix3.h" #include "effects/sinematrix3.h"
#include "effect_big_clock.h" #include "effects/big_clock.h"
#include "effect_clock.h" #include "effects/clock.h"
#include "effect_static.h" #include "effects/static.h"
#include "effect_animation.h" #include "effects/animation.h"
#include "effect_dynamic.h" #include "effects/dynamic.h"
#include "effect_matrix.h" #include "effects/matrix.h"
#include "effect_twirl.h" #include "effects/twirl.h"
#include "effect_cycle.h" #include "effects/cycle.h"
#include "effect_confetti.h" #include "effects/snake.h"
#include "effect_snake.h" #include "effects/fire.h"
#include "effect_fire.h" #include "effects/firework.h"
#include "effect_firework.h" #include "effects/gol.h"
#include "effect_gol.h" #include "effects/pixelclock.h"
#include "effect_pixelclock.h" #include "effects/dvd.h"
#include "effect_dvd.h" #include "effects/analogclock.h"
#include "effect_analogclock.h" #include "effects/sines.h"
#include "effect_sines.h" #include "effects/marquee.h"
#include "effect_marquee.h" #include "effects/blur2d.h"
#include "effect_blur2d.h" #include "effects/tv_static.h"
#include "effect_tv_static.h" #include "effects/lightspeed.h"
#include "effect_lightspeed.h" #include "effects/diamond.h"
#include "effect_diamond.h" #include "effects/tpm2_net.h"
#include "effect_tpm2_net.h" #include "SimpleEffect.h"
#include "effects/night_clock.h"
Effect* current_effect; Effect* current_effect;
@ -34,42 +35,48 @@ TimerEffect effect_timer;
// We're using 0 instead of false to get a better visual difference between true and false. // We're using 0 instead of false to get a better visual difference between true and false.
EffectEntry effects[] = { EffectEntry effects[] = {
/* 0 */ {"sinematrix3", true, [](){ return new Sinematrix3Effect(); }}, /* 0 */ {"sinematrix3", true, [](){ return new Sinematrix3Effect(); }},
/* 1 */ {"big_clock", true, [](){ return new BigClockEffect(); }}, /* 1 */ {"big_clock", true, [](){ return new BigClockEffect(); }},
/* 2 */ {"clock", 0, [](){ return new ClockEffect(); }}, /* 2 */ {"clock", 0, [](){ return new ClockEffect(); }},
/* 3 */ {"bell", 0, [](){ return AnimationEffect::Blinker("/bell.pia", 300, 0xFFFF00); }}, /* 3 */ {"bell", 0, [](){ return AnimationEffect::Blinker("/bell.pia", 300, 0xFFFF00); }},
/* 4 */ {"off", 0, [](){ return new StaticEffect(0x000000); }}, /* 4 */ {"off", 0, [](){ return new StaticEffect(0x000000); }},
/* 5 */ {"single_dynamic", true, [](){ return new SingleDynamicEffect(); }}, /* 5 */ {"single_dynamic", true, [](){ return new SingleDynamicEffect(); }},
/* 6 */ {"multi_dynamic", true, [](){ return new MultiDynamicEffect(); }}, /* 6 */ {"multi_dynamic", true, [](){ return new MultiDynamicEffect(); }},
/* 7 */ {"big_dynamic", true, [](){ return new BigDynamicEffect(); }}, /* 7 */ {"big_dynamic", true, [](){ return new BigDynamicEffect(); }},
/* 8 */ {"matrix", true, [](){ return new MatrixEffect(); }}, /* 8 */ {"matrix", true, [](){ return new MatrixEffect(); }},
/* 9 */ {"random_matrix", true, [](){ return new RandomMatrixEffect(); }}, /* 9 */ {"random_matrix", true, [](){ return new RandomMatrixEffect(); }},
/* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }}, /* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }},
/* 11 */ {"cycle", 0, [](){ return new CycleEffect(); }}, /* 11 */ {"cycle", 0, [](){ return new CycleEffect(); }},
/* 12 */ {"twirl", true, [](){ return new TwirlEffect(); }}, /* 12 */ {"twirl", true, [](){ return new TwirlEffect(); }},
/* 13 */ {"confetti", true, [](){ return new ConfettiEffect(); }}, /* 13 */ SIMPLE_EFFECT("confetti", true, SE_CYCLE_COLORS | SE_FADEOUT, {return random8()>252?1:0;}),
/* 14 */ {"random_confetti", true, [](){ return new RandomConfettiEffect(); }}, /* 14 */ SIMPLE_EFFECT("rainbow_confetti", true, SE_RANDOM_PIXEL_COLORS | SE_FADEOUT, {return random8()>252?1:0;}),
/* 15 */ {"snake", true, [](){ return new SnakeEffect(); }}, /* 15 */ {"snake", true, [](){ return new SnakeEffect(); }},
/* 16 */ {"firework", true, [](){ return new FireworkEffect(); }}, /* 16 */ {"firework", true, [](){ return new FireworkEffect(); }},
/* 17 */ {"gol", true, [](){ return new GolEffect(); }}, /* 17 */ {"gol", true, [](){ return new GolEffect(); }},
/* 18 */ {"pixel_clock", 0, [](){ return new PixelClockEffect(); }}, /* 18 */ {"pixel_clock", 0, [](){ return new PixelClockEffect(); }},
/* 19 */ {"dvd", true, [](){ return new DvdEffect(); }}, /* 19 */ {"dvd", true, [](){ return new DvdEffect(); }},
/* 20 */ {"analog_clock", 0, [](){ return new AnalogClockEffect(); }}, /* 20 */ {"analog_clock", 0, [](){ return new AnalogClockEffect(); }},
/* 21 */ {"sines", true, [](){ return new SinesEffect(); }}, /* 21 */ {"sines", true, [](){ return new SinesEffect(); }},
/* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }}, /* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }},
/* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }}, /* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }},
/* 24 */ {"night_clock", 0, [](){ return new NightClockEffect(); }}, /* 24 */ {"night_clock", 0, [](){ return new NightClockEffect(); }},
/* 25 */ {"tv_static", 0, [](){ return new TvStaticEffect(); }}, /* 25 */ {"tv_static", 0, [](){ return new TvStaticEffect(); }},
/* 26 */ {"sinematrix3_rainbow", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_RAINBOW); }}, /* 26 */ {"sinematrix3_rainbow", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_RAINBOW); }},
/* 27 */ {"sinematrix3_purplefly", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_PURPLEFLY); }}, /* 27 */ {"sinematrix3_purplefly", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_PURPLEFLY); }},
/* 28 */ {"lightspeed", true, [](){ return new LightspeedEffect(); }}, /* 28 */ {"lightspeed", true, [](){ return new LightspeedEffect(); }},
/* 29 */ {"koopa", 0, [](){ return new AnimationEffect("/koopa.pia"); }}, /* 29 */ {"koopa", 0, [](){ return new AnimationEffect("/koopa.pia"); }},
/* 30 */ {"cake", 0, [](){ return new AnimationEffect("/cake.pia"); }}, /* 30 */ {"cake", 0, [](){ return new AnimationEffect("/cake.pia"); }},
/* 31 */ {"child", 0, [](){ return AnimationEffect::Blinker("/child.pia", 300, 0xFFFF00); }}, /* 31 */ {"child", 0, [](){ return AnimationEffect::Blinker("/child.pia", 300, 0xFFFF00); }},
/* 32 */ {"diamond", true, [](){ return new DiamondEffect(); }}, /* 32 */ {"diamond", true, [](){ return new DiamondEffect(); }},
/* 33 */ {"tpm2.net", 0, [](){ return new Tpm2NetEffect(); }}, /* 33 */ {"tpm2.net", 0, [](){ return new Tpm2NetEffect(); }},
/* 34 */ SIMPLE_EFFECT("slow_blinking", true, SE_CYCLE_COLORS, {return sin(t + (x+1)*(y+1)*i);} ),
/* 35 */ SIMPLE_EFFECT("upwave", true, SE_CYCLE_COLORS, {return (cos(t+y/2));} ),
/* 36 */ SIMPLE_EFFECT("centerwave", true, SE_CYCLE_COLORS, {return sin(t*2 - sqrt((x-4)*(x-4) + (y-7)*(y-7)));} ),
/* 37 */ SIMPLE_EFFECT("sineline", true, SE_RANDOM_STATIC_COLOR, {return sin(x/2)-sin(x-t)-y+6;} ),
/* 38 */ SIMPLE_EFFECT("barbershop", true, SE_RANDOM_STATIC_COLOR, {return 1*cos(0.8*i-t*5);} ),
/* 39 */ SIMPLE_EFFECT("zigzag", true, SE_CYCLE_COLORS, { return cos(cos(x+y)-y*cos(t/8+x/16));} ),
}; };
const uint8_t effects_size = 34; const uint8_t effects_size = 40;
Effect* select_effect(const char* name) { Effect* select_effect(const char* name) {

View File

@ -1,4 +1,4 @@
#include "effect_analogclock.h" #include "effects/analogclock.h"
#include "my_fastled.h" #include "my_fastled.h"
#include "ntp.h" #include "ntp.h"
#include <time.h> #include <time.h>

View File

@ -1,4 +1,4 @@
#include "effect_animation.h" #include "effects/animation.h"
#include "functions.h" #include "functions.h"
AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) { AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) {

View File

@ -1,6 +1,6 @@
#include "Effect.h" #include "Effect.h"
#include "functions.h" #include "functions.h"
#include "effect_bell.h" #include "effects/bell.h"
#include "sprites.h" #include "sprites.h"
void BellEffect::loop(uint16_t ms) { void BellEffect::loop(uint16_t ms) {

View File

@ -1,5 +1,5 @@
#include "Effect.h" #include "Effect.h"
#include "effect_big_clock.h" #include "effects/big_clock.h"
#include "fonts.h" #include "fonts.h"
#include <time.h> #include <time.h>
#include "settings.h" #include "settings.h"

View File

@ -1,4 +1,4 @@
#include "effect_blur2d.h" #include "effects/blur2d.h"
Blur2DBlob::Blur2DBlob() { Blur2DBlob::Blur2DBlob() {
_x_freq = random16(6<<8, 15<<8); _x_freq = random16(6<<8, 15<<8);
_y_freq = random16(6<<8, 15<<8); _y_freq = random16(6<<8, 15<<8);

View File

@ -1,4 +1,4 @@
#include "effect_clock.h" #include "effects/clock.h"
#include <FastLED.h> #include <FastLED.h>
#include "functions.h" #include "functions.h"
#include "fonts.h" #include "fonts.h"

View File

@ -1,4 +1,4 @@
#include "effect_cycle.h" #include "effects/cycle.h"
#include "effects.h" #include "effects.h"
CycleEffect::CycleEffect() { CycleEffect::CycleEffect() {

View File

@ -1,4 +1,4 @@
#include "effect_diamond.h" #include "effects/diamond.h"
#include "my_fastled.h" #include "my_fastled.h"
void DiamondEffect::loop(uint16_t ms) { void DiamondEffect::loop(uint16_t ms) {

View File

@ -1,4 +1,4 @@
#include "effect_dvd.h" #include "effects/dvd.h"
#include "my_fastled.h" #include "my_fastled.h"
void DvdEffect::loop(uint16_t ms) { void DvdEffect::loop(uint16_t ms) {

View File

@ -1,4 +1,4 @@
#include "effect_dynamic.h" #include "effects/dynamic.h"
#include "functions.h" #include "functions.h"
#include "config.h" #include "config.h"

View File

@ -1,4 +1,4 @@
#include "effect_fire.h" #include "effects/fire.h"
#include "my_color_palettes.h" #include "my_color_palettes.h"
#include "config.h" #include "config.h"
#include "my_fastled.h" #include "my_fastled.h"

View File

@ -1,5 +1,5 @@
// Based on https://gist.github.com/kriegsman/68929cbd1d6de4535b20 // Based on https://gist.github.com/kriegsman/68929cbd1d6de4535b20
#include "effect_firework.h" #include "effects/firework.h"
FireworkEffectDot::FireworkEffectDot(Window* w, FireworkEffect* e) { FireworkEffectDot::FireworkEffectDot(Window* w, FireworkEffect* e) {
_window = w; _window = w;

View File

@ -1,4 +1,4 @@
#include "effect_gol.h" #include "effects/gol.h"
#include "my_fastled.h" #include "my_fastled.h"
GolEffect::GolEffect() { GolEffect::GolEffect() {

View File

@ -1,4 +1,4 @@
#include "effect_lightspeed.h" #include "effects/lightspeed.h"
#include "config.h" #include "config.h"
#include "functions.h" #include "functions.h"
#include "prototypes.h" #include "prototypes.h"

View File

@ -1,4 +1,4 @@
#include "effect_marquee.h" #include "effects/marquee.h"
#include "fonts.h" #include "fonts.h"
boolean MarqueeEffect::can_be_shown_with_clock() { boolean MarqueeEffect::can_be_shown_with_clock() {

View File

@ -1,4 +1,4 @@
#include "effect_matrix.h" #include "effects/matrix.h"
#include "my_color_palettes.h" #include "my_color_palettes.h"
#include "functions.h" #include "functions.h"

View File

@ -0,0 +1,26 @@
#include "Effect.h"
#include "effects/night_clock.h"
#include "fonts.h"
#include <time.h>
void NightClockEffect::loop(uint16_t ms) {
window->clear();
time_t now;
tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
uint8_t h = timeinfo.tm_hour;
CRGB color = CRGB(0x440000);
window->drawChar(&font5x7, 4<<8, 0<<8, '0' + (h / 10), &color);
window->drawChar(&font5x7, 10<<8, 0<<8, '0' + (h % 10), &color);
uint8_t m = timeinfo.tm_min;
window->drawChar(&font5x7, 4<<8, 9<<8, '0' + (m / 10), &color);
window->drawChar(&font5x7, 10<<8, 9<<8, '0' + (m % 10), &color);
uint8_t s = timeinfo.tm_sec;
if(s & 1) {
window->setPixel(2, 11, &color);
window->setPixel(2, 13, &color);
}
}

View File

@ -1,4 +1,4 @@
#include "effect_pixelclock.h" #include "effects/pixelclock.h"
#include "ntp.h" #include "ntp.h"
PixelClockEffect::PixelClockEffect() { PixelClockEffect::PixelClockEffect() {

View File

@ -1,4 +1,4 @@
#include "effect_sinematrix3.h" #include "effects/sinematrix3.h"
#include "prototypes.h" #include "prototypes.h"
#include "functions.h" #include "functions.h"
#include "Effect.h" #include "Effect.h"

View File

@ -1,4 +1,4 @@
#include "effect_sines.h" #include "effects/sines.h"
SinesEffectSinus::SinesEffectSinus(Window* w) { SinesEffectSinus::SinesEffectSinus(Window* w) {
_window = w; _window = w;

View File

@ -1,4 +1,4 @@
#include "effect_snake.h" #include "effects/snake.h"
#include "functions.h" #include "functions.h"
SnakeEffect::SnakeEffect() { SnakeEffect::SnakeEffect() {

View File

@ -1,4 +1,4 @@
#include "effect_static.h" #include "effects/static.h"
#include "functions.h" #include "functions.h"
#include "my_fastled.h" #include "my_fastled.h"

View File

@ -1,4 +1,4 @@
#include "effect_timer.h" #include "effects/timer.h"
#include <FastLED.h> #include <FastLED.h>
#include "functions.h" #include "functions.h"
#include "fonts.h" #include "fonts.h"

View File

@ -1,4 +1,4 @@
#include "effect_tpm2_net.h" #include "effects/tpm2_net.h"
#include "my_fastled.h" #include "my_fastled.h"
void Tpm2NetEffect::loop(uint16_t ms) { void Tpm2NetEffect::loop(uint16_t ms) {

View File

@ -1,4 +1,4 @@
#include "effect_tv_static.h" #include "effects/tv_static.h"
void TvStaticEffect::loop(uint16_t ms) { void TvStaticEffect::loop(uint16_t ms) {
//uint8_t dark_position = (millis() % settings.effects.tv_static.black_bar_speed) * _window->width / settings.effects.tv_static.black_bar_speed; //uint8_t dark_position = (millis() % settings.effects.tv_static.black_bar_speed) * _window->width / settings.effects.tv_static.black_bar_speed;

View File

@ -1,4 +1,4 @@
#include "effect_twirl.h" #include "effects/twirl.h"
#include "functions.h" #include "functions.h"
boolean TwirlEffect::can_be_shown_with_clock() { return true; }; boolean TwirlEffect::can_be_shown_with_clock() { return true; };

View File

@ -2,16 +2,6 @@
require 'websocket-eventmachine-client' require 'websocket-eventmachine-client'
require 'pp' require 'pp'
def rgb2ansi(r, g, b)
if r==g && g==b
return 16 if r<8
return 231 if r>248
return (((r - 8) / 247.0) * 24).round + 232
end
return 16 + 36*(r/51.0).round + 6*(g/51.0).round + (b/51.0).round
end
IP = ARGV[0] IP = ARGV[0]
EFFECT = ARGV[1] EFFECT = ARGV[1]
uri = "ws://#{IP}:80/ws" uri = "ws://#{IP}:80/ws"
@ -41,8 +31,7 @@ EM.run do
str += "|" str += "|"
(0...width).each do |x| (0...width).each do |x|
r, g, b = *data.shift(3) r, g, b = *data.shift(3)
color_code = rgb2ansi(r, g, b) str += "\033[38;2;#{r};#{g};#{b}m●"
str += "\033[48;5;#{color_code}m "
end end
str += "\033[0m|\n" str += "\033[0m|\n"
end end

View File

@ -6,10 +6,20 @@
void wifi_setup() { void wifi_setup() {
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS); WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.waitForConnectResult() != WL_CONNECTED) { uint8_t result;
Serial.println("WiFi * Connection Failed! Rebooting..."); uint8_t counter = 0;
delay(5000); while ((result = WiFi.waitForConnectResult()) != WL_CONNECTED) {
ESP.restart(); counter++;
if (counter > 100) {
Serial.print("WiFi * Connection Failed! Last result was: ");
Serial.print(result);
Serial.println(" Rebooting...");
delay(100);
ESP.restart();
}
Serial.print("WiFi * Still waiting for WiFi to connect. This is loop number ");
Serial.println(counter);
delay(100);
} }
Serial.println("WiFi * Ready"); Serial.println("WiFi * Ready");
Serial.print("WiFi * IP address: "); Serial.print("WiFi * IP address: ");