Fixed Nightlight function

added /version query
updated readme
This commit is contained in:
cschwinne 2017-04-26 14:04:53 +02:00
parent 624b3c3f16
commit 692c41b7c2
7 changed files with 31 additions and 48 deletions

View File

@ -42,6 +42,10 @@ toggle nightlight
toggle notifier toggle notifier
var. brightness var. brightness
auto update (get from server)
ifLed feature -> set triggers for reqs.?
BUGS BUGS
general forced reset (usually around 48h) general forced reset (usually around 48h)
NTP crash (1-48h) NTP crash (1-48h)

View File

@ -1,15 +1,13 @@
WLED is a basic, fast and (relatively) (ok, VERY relatively) secure implementation of a ESP8266 webserver to control Neopixel (WS2812B) leds WLED is a basic, fast and (relatively) (ok, VERY relatively) secure implementation of a ESP8266 webserver to control Neopixel (WS2812B) leds
Uses ESP8266 Arduino libraries from 15th August 2016! Untested with newer version! Uses ESP arduino version 2.3.0 (latest as of April 2017).
Contents in the /data directory may be uploaded to SPIFFS. Contents in the /data directory may be uploaded to SPIFFS.
Features: (V0.2) Features: (V0.3pd)
- RGB and brightness sliders - RGB and brightness sliders
- Settings page - configuration over network - Settings page - configuration over network
- Access Point and station mode - automatic failsafe AP - Access Point and station mode - automatic failsafe AP
- Edit page. Change html and other files via OTA. - Edit page. Change html and other files via OTA.
Additions for V0.3 (nearly complete!)
- WS2812FX library integrated for nearly 50 special effects! - WS2812FX library integrated for nearly 50 special effects!
- Nightlight function (gradually dims down) - Nightlight function (gradually dims down)
- Notifier function (multiple ESPs sync color via UDP broadcast) - Notifier function (multiple ESPs sync color via UDP broadcast)
@ -17,10 +15,11 @@ Additions for V0.3 (nearly complete!)
- Full OTA software update capability - Full OTA software update capability
- Password protected OTA page for added security (OTA lock) - Password protected OTA page for added security (OTA lock)
- Alexa smart home device server - Alexa smart home device server
- (not working) NTP and experimental analog clock function - (unstable) NTP and experimental analog clock function
- better client HTML page (not yet implemented)
Compile settings: Compile settings:
Board: WeMos D1 mini Board: WeMos D1 mini (untested with other HW, should work if it has 4MB flash)
CPU frequency: 80 MHz CPU frequency: 80 MHz
Flash size : 4MB (1MB SPIFFS) Flash size : 4MB (1MB SPIFFS)
Upload speed: 115200 Upload speed: 115200
@ -36,7 +35,7 @@ Just flash a basic HTTP OTA updater sketch and upload the bin!
Connect a WS2812B RGB led strip to GPIO2. Optionally connect a NO-pushbutton to GPIO0 (internal pull-up) and ground. Connect a WS2812B RGB led strip to GPIO2. Optionally connect a NO-pushbutton to GPIO0 (internal pull-up) and ground.
2. Follow a guide to setup your Arduino client (I am using version 1.8.1) with the ESP8266 libraries. 2. Follow a guide to setup your Arduino client (I am using version 1.8.1) with the ESP8266 libraries.
For current compiles I use an old version from 15th August 2016. For current compiles I use version 2.3.0.
3. You will also need the ESP8266 SPIFFS sketch data uploader. (currently working on making this step unnecessary) 3. You will also need the ESP8266 SPIFFS sketch data uploader. (currently working on making this step unnecessary)
-> In the newest commit this step is not essential (HTML included in sketch), but recommended, since otherwise you have to upload the pictures manually to /edit SPIFFS -> In the newest commit this step is not essential (HTML included in sketch), but recommended, since otherwise you have to upload the pictures manually to /edit SPIFFS

View File

@ -22,7 +22,7 @@
#include "CallbackFunction.h" #include "CallbackFunction.h"
//version in format yymmddb (b = daily build) //version in format yymmddb (b = daily build)
#define VERSION 1703251 #define VERSION 1704263
//to toggle usb serial debug (un)comment following line //to toggle usb serial debug (un)comment following line
#define DEBUG #define DEBUG
@ -76,9 +76,8 @@ IPAddress staticsubnet(255, 255, 255, 0);
boolean turnOnAtBoot = true; boolean turnOnAtBoot = true;
byte col_s[]{255, 127, 0}; byte col_s[]{255, 127, 0};
byte bri_s = 127; byte bri_s = 127;
uint8_t bri_nl = 0; uint8_t bri_nl = 0, bri_nls;
boolean fadeTransition = true; boolean fadeTransition = true;
boolean seqTransition = false;
uint16_t transitionDelay = 1500; uint16_t transitionDelay = 1500;
boolean ota_lock = true; boolean ota_lock = true;
boolean only_ap = false; boolean only_ap = false;
@ -135,7 +134,6 @@ boolean transitionActive = false;
boolean buttonPressedBefore = false; boolean buttonPressedBefore = false;
boolean nightlightActive = false; boolean nightlightActive = false;
boolean nightlightActive_old = false; boolean nightlightActive_old = false;
int transitionDelay_old;
int nightlightDelayMs; int nightlightDelayMs;
uint8_t effectCurrent = 0; uint8_t effectCurrent = 0;
uint8_t effectSpeed = 75; uint8_t effectSpeed = 75;

View File

@ -175,7 +175,6 @@ void loadSettingsFromEEPROM()
receiveNotificationsDefault = receiveNotifications; receiveNotificationsDefault = receiveNotifications;
fadeTransition = EEPROM.read(251); fadeTransition = EEPROM.read(251);
transitionDelay = ((EEPROM.read(253) << 0) & 0xFF) + ((EEPROM.read(254) << 8) & 0xFF00); transitionDelay = ((EEPROM.read(253) << 0) & 0xFF) + ((EEPROM.read(254) << 8) & 0xFF00);
transitionDelay_old = transitionDelay;
bri_n = EEPROM.read(255); bri_n = EEPROM.read(255);
otapass = ""; otapass = "";
for (int i = 256; i < 288; ++i) for (int i = 256; i < 288; ++i)

View File

@ -154,7 +154,6 @@ void handleSettingsSet()
int i = server.arg("TDLAY").toInt(); int i = server.arg("TDLAY").toInt();
if (i > 0){ if (i > 0){
transitionDelay = i; transitionDelay = i;
transitionDelay_old = transitionDelay;
} }
} }
if (server.hasArg("TLBRI")) if (server.hasArg("TLBRI"))

View File

@ -90,6 +90,9 @@ void wledInit()
handleSettingsSet(); handleSettingsSet();
if(!handleFileRead("/settingssaved.htm")) server.send(200, "text/html", PAGE_settingssaved); if(!handleFileRead("/settingssaved.htm")) server.send(200, "text/html", PAGE_settingssaved);
}); });
server.on("/version", HTTP_GET, [](){
server.send(200, "text/plain", (String)VERSION);
});
if (!ota_lock){ if (!ota_lock){
server.on("/edit", HTTP_GET, [](){ server.on("/edit", HTTP_GET, [](){
if(!handleFileRead("/edit.htm")) server.send(200, "text/html", PAGE_edit); if(!handleFileRead("/edit.htm")) server.send(200, "text/html", PAGE_edit);

View File

@ -41,13 +41,19 @@ void colorUpdated(int callMode)
if (callMode == 6) notify(6); if (callMode == 6) notify(6);
return; //no change return; //no change
} }
if (callMode != 5 && nightlightActive && nightlightFade)
{
bri_nls = bri;
nightlightDelayMs -= (millis() - nightlightStartTime);
nightlightStartTime = millis();
}
col_it[0] = col[0]; col_it[0] = col[0];
col_it[1] = col[1]; col_it[1] = col[1];
col_it[2] = col[2]; col_it[2] = col[2];
bri_it = bri; bri_it = bri;
if (bri > 0) bri_last = bri; if (bri > 0) bri_last = bri;
notify(callMode); notify(callMode);
if (fadeTransition || seqTransition) if (fadeTransition)
{ {
if (transitionActive) if (transitionActive)
{ {
@ -55,10 +61,10 @@ void colorUpdated(int callMode)
col_old[1] = col_t[1]; col_old[1] = col_t[1];
col_old[2] = col_t[2]; col_old[2] = col_t[2];
bri_old = bri_t; bri_old = bri_t;
tper_last = 0;
} }
transitionActive = true; transitionActive = true;
transitionStartTime = millis(); transitionStartTime = millis();
transitionDelay = transitionDelay_old;
} else } else
{ {
setLedsStandard(); setLedsStandard();
@ -75,10 +81,6 @@ void handleTransitions()
transitionActive = false; transitionActive = false;
tper_last = 0; tper_last = 0;
setLedsStandard(); setLedsStandard();
if (nightlightActive && nightlightFade)
{
initNightlightFade();
}
return; return;
} }
if (tper - tper_last < transitionResolution) if (tper - tper_last < transitionResolution)
@ -93,29 +95,10 @@ void handleTransitions()
col_t[2] = col_old[2]+((col[2] - col_old[2])*tper); col_t[2] = col_old[2]+((col[2] - col_old[2])*tper);
bri_t = bri_old+((bri - bri_old)*tper); bri_t = bri_old+((bri - bri_old)*tper);
} }
if (seqTransition) setAllLeds();
{
} else setAllLeds();
} }
} }
void initNightlightFade()
{
float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs);
nightlightDelayMs = nightlightDelayMs*(1-nper);
if (nper >= 1)
{
return;
}
bri = bri_nl;
bri_it = bri_nl;
transitionDelay = (int)(nightlightDelayMins*60000);
transitionStartTime = nightlightStartTime;
transitionActive = true;
nightlightStartTime = millis();
}
void handleNightlight() void handleNightlight()
{ {
if (nightlightActive) if (nightlightActive)
@ -126,12 +109,14 @@ void handleNightlight()
notify(4); notify(4);
nightlightDelayMs = (int)(nightlightDelayMins*60000); nightlightDelayMs = (int)(nightlightDelayMins*60000);
nightlightActive_old = true; nightlightActive_old = true;
if (nightlightFade) bri_nls = bri;
{
initNightlightFade();
}
} }
float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs); float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs);
if (nightlightFade)
{
bri = bri_nls+((bri_nl - bri_nls)*nper);
colorUpdated(5);
}
if (nper >= 1) if (nper >= 1)
{ {
nightlightActive = false; nightlightActive = false;
@ -140,14 +125,10 @@ void handleNightlight()
bri = bri_nl; bri = bri_nl;
colorUpdated(5); colorUpdated(5);
} }
if (bri == 0) bri_last = bri_nls;
} }
} else if (nightlightActive_old) //early de-init } else if (nightlightActive_old) //early de-init
{ {
nightlightActive_old = false; nightlightActive_old = false;
if (nightlightFade)
{
transitionDelay = transitionDelay_old;
transitionActive = false;
}
} }
} }