diff --git a/CHANGELOG.md b/CHANGELOG.md index be0750be..5090a4b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ### Development versions after the 0.10.2 release +#### Build 2009100 + +- Fixed sunrise mode not reinitializing +- Fixed passwords not clearable + #### Build 2009070 - New Segments are now initialized with default speed and intensity diff --git a/usermods/Temperature/platformio_override.ini b/usermods/Temperature/platformio_override.ini new file mode 100644 index 00000000..d9e3fbac --- /dev/null +++ b/usermods/Temperature/platformio_override.ini @@ -0,0 +1,13 @@ +; Options +; ------- +; USERMOD_DALLASTEMPERATURE - define this to have this user mod included wled00\usermods_list.cpp +; USERMOD_DALLASTEMPERATURE_CELSIUS - define this to report temperatures in degrees celsius, otherwise fahrenheit will be reported +; USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL - the number of milliseconds between measurements, defaults to 60 seconds +; USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT - the number of milliseconds after boot to take first measurement, defaults to 20 seconds +; +[env:d1_mini_usermod_dallas_temperature_C] +extends = env:d1_mini +build_flags = ${common.build_flags_esp8266} -D USERMOD_DALLASTEMPERATURE -D USERMOD_DALLASTEMPERATURE_CELSIUS +lib_deps = ${env.lib_deps} + milesburton/DallasTemperature@^3.9.0 + OneWire@~2.3.5 diff --git a/usermods/Temperature/readme.md b/usermods/Temperature/readme.md index f6ce8532..5e26ba69 100644 --- a/usermods/Temperature/readme.md +++ b/usermods/Temperature/readme.md @@ -5,11 +5,18 @@ This usermod will read from an attached DS18B20 temperature sensor (as available The temperature is displayed both in the Info section of the web UI as well as published to the `/temperature` MQTT topic if enabled. This usermod will be expanded with support for different sensor types in the future. +If temperature sensor is not detected during boot, this usermod will be disabled. + ## Installation -Copy `usermod_temperature.h` to the wled00 directory. -Uncomment the corresponding lines in `usermods_list.cpp` and compile! -If this is the only v2 usermod you plan to use, you can alternatively replace `usermods_list.h` in wled00 with the one in this folder. +Copy the example `platformio_override.ini` to the root directory. This file should be placed in the same directory as `platformio.ini`. + +### Define Your Options + +* `USERMOD_DALLASTEMPERATURE` - define this to have this user mod included wled00\usermods_list.cpp +* `USERMOD_DALLASTEMPERATURE_CELSIUS` - define this to report temperatures in degrees celsious, otherwise fahrenheit will be reported +* `USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL` - the number of milliseconds between measurements, defaults to 60 seconds +* `USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT` - the number of milliseconds after boot to take first measurement, defaults to 20 seconds ## Project link @@ -17,7 +24,10 @@ If this is the only v2 usermod you plan to use, you can alternatively replace `u ### PlatformIO requirements -You might have to uncomment `DallasTemperature@~3.8.0`,`OneWire@~2.3.5 under` `[common]` section in `platformio.ini`: +If you are using `platformio_override.ini`, you should be able to refresh the task list and see your custom task, for example `env:d1_mini_usermod_dallas_temperature_C`. + + +If you are not using `platformio_override.ini`, you might have to uncomment `DallasTemperature@~3.8.0`,`OneWire@~2.3.5 under` `[common]` section in `platformio.ini`: ```ini # platformio.ini @@ -38,3 +48,11 @@ lib_deps_external = OneWire@~2.3.5 ... ``` + +## Change Log + +2020-09-12 +* Changed to use async, non-blocking implementation +* Do not report low temperatures that indicate an error to mqtt +* Disable plugin if temperature sensor not detected +* Report the number of seconds until the first read in the info screen instead of sensor error \ No newline at end of file diff --git a/usermods/Temperature/usermod_temperature.h b/usermods/Temperature/usermod_temperature.h index eb123df0..d72be934 100644 --- a/usermods/Temperature/usermod_temperature.h +++ b/usermods/Temperature/usermod_temperature.h @@ -11,61 +11,156 @@ #define TEMPERATURE_PIN 14 #endif -#define TEMP_CELSIUS // Comment out for Fahrenheit +// the frequency to check temperature, 1 minute +#ifndef USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL +#define USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL 60000 +#endif -#define MEASUREMENT_INTERVAL 60000 //1 Minute +// how many seconds after boot to take first measurement, 20 seconds +#ifndef USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT +#define USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT 20000 +#endif OneWire oneWire(TEMPERATURE_PIN); DallasTemperature sensor(&oneWire); class UsermodTemperature : public Usermod { private: - //set last reading as "40 sec before boot", so first reading is taken after 20 sec - unsigned long lastMeasurement = UINT32_MAX - 40000; - float temperature = 0.0f; - public: - void getReading() { - sensor.requestTemperatures(); - #ifdef TEMP_CELSIUS - temperature = sensor.getTempCByIndex(0); - #else - temperature = sensor.getTempFByIndex(0); - #endif + // The device's unique 64-bit serial code stored in on-board ROM. + // Reading directly from the sensor device address is faster than + // reading from index. When reading by index, DallasTemperature + // must first look up the device address at the specified index. + DeviceAddress sensorDeviceAddress; + // set last reading as "40 sec before boot", so first reading is taken after 20 sec + unsigned long lastMeasurement = UINT32_MAX - (USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL - USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT); + // last time requestTemperatures was called + // used to determine when we can read the sensors temperature + // we have to wait at least 93.75 ms after requestTemperatures() is called + unsigned long lastTemperaturesRequest; + float temperature = -100; // default to -100, DS18B20 only goes down to -50C + // indicates requestTemperatures has been called but the sensor measurement is not complete + bool waitingForConversion = false; + // flag to indicate we have finished the first getTemperature call + // allows this library to report to the user how long until the first + // measurement + bool getTemperatureComplete = false; + // flag set at startup if DS18B20 sensor not found, avoids trying to keep getting + // temperature if flashed to a board without a sensor attached + bool disabled = false; + + void requestTemperatures() { + // there is requestTemperaturesByAddress however it + // appears to do more work, + // TODO: measure exection time difference + sensor.requestTemperatures(); + lastTemperaturesRequest = millis(); + waitingForConversion = true; } + void getTemperature() { + #ifdef USERMOD_DALLASTEMPERATURE_CELSIUS + temperature = sensor.getTempC(sensorDeviceAddress); + #else + temperature = sensor.getTempF(sensorDeviceAddress); + #endif + + lastMeasurement = millis(); + waitingForConversion = false; + getTemperatureComplete = true; + } + + public: + + void setup() { sensor.begin(); - sensor.setResolution(9); + + // get the unique 64-bit serial code stored in on-board ROM + // if getAddress returns false, the sensor was not found + disabled = !sensor.getAddress(sensorDeviceAddress, 0); + + if (!disabled) { + DEBUG_PRINTLN("Dallas Temperature found"); + // set the resolution for this specific device + sensor.setResolution(sensorDeviceAddress, 9, true); + // do not block waiting for reading + sensor.setWaitForConversion(false); + } else { + DEBUG_PRINTLN("Dallas Temperature not found"); + } } void loop() { - if (millis() - lastMeasurement > MEASUREMENT_INTERVAL) - { - getReading(); + if (disabled) { + return; + } + + unsigned long now = millis(); + // check to see if we are due for taking a measurement + // lastMeasurement will not be updated until the conversion + // is complete the the reading is finished + if (now - lastMeasurement < USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL) + { + return; + } + + // we are due for a measurement, if we are not already waiting + // for a conversion to complete, then make a new request for temps + if (!waitingForConversion) + { + requestTemperatures(); + return; + } + + // we were waiting for a conversion to complete, have we waited log enough? + if (now - lastTemperaturesRequest >= 94 /* 93.75ms per the datasheet */) + { + getTemperature(); + if (WLED_MQTT_CONNECTED) { char subuf[38]; strcpy(subuf, mqttDeviceTopic); - strcat(subuf, "/temperature"); - mqtt->publish(subuf, 0, true, String(temperature).c_str()); + if (-100 <= temperature) { + // dont publish super low temperature as the graph will get messed up + // the DallasTemperature library returns -127C or -196.6F when problem + // reading the sensor + strcat(subuf, "/temperature"); + mqtt->publish(subuf, 0, true, String(temperature).c_str()); + } else { + // publish something else to indicate status? + } } - lastMeasurement = millis(); } } void addToJsonInfo(JsonObject& root) { + // dont add temperature to info if we are disabled + if (disabled) { + return; + } + JsonObject user = root["u"]; if (user.isNull()) user = root.createNestedObject("u"); JsonArray temp = user.createNestedArray("Temperature"); - if (temperature == DEVICE_DISCONNECTED_C) { + + if (!getTemperatureComplete) { + // if we haven't read the sensor yet, let the user know + // that we are still waiting for the first measurement + temp.add((USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT - millis()) / 1000); + temp.add(" sec until read"); + return; + } + + if (temperature <= -100) { temp.add(0); temp.add(" Sensor Error!"); return; } temp.add(temperature); - #ifdef TEMP_CELSIUS + #ifdef USERMOD_DALLASTEMPERATURE_CELSIUS temp.add("°C"); #else temp.add("°F"); @@ -76,4 +171,4 @@ class UsermodTemperature : public Usermod { { return USERMOD_ID_TEMPERATURE; } -}; \ No newline at end of file +}; diff --git a/usermods/Temperature/usermods_list.cpp b/usermods/Temperature/usermods_list.cpp index 1a1efdd7..50dd7816 100644 --- a/usermods/Temperature/usermods_list.cpp +++ b/usermods/Temperature/usermods_list.cpp @@ -9,7 +9,10 @@ * \/ \/ \/ */ //#include "usermod_v2_example.h" -#include "usermod_temperature.h" +#ifdef USERMOD_DALLASTEMPERATURE +#include "../usermods/Temperature/usermod_temperature.h" +#endif + //#include "usermod_v2_empty.h" void registerUsermods() @@ -20,6 +23,9 @@ void registerUsermods() * \/ \/ \/ */ //usermods.add(new MyExampleUsermod()); +#ifdef USERMOD_DALLASTEMPERATURE usermods.add(new UsermodTemperature()); +#endif + //usermods.add(new UsermodRenameMe()); } \ No newline at end of file diff --git a/wled00/data/404.html b/wled00/data/404.html new file mode 100644 index 00000000..92f87d3d --- /dev/null +++ b/wled00/data/404.html @@ -0,0 +1,48 @@ + + + + + + + Not found + + + + +

404 Not Found

+Akemi does not know where you are headed...

+ + + \ No newline at end of file diff --git a/wled00/data/index.htm b/wled00/data/index.htm index 71292e4b..8b532de8 100644 --- a/wled00/data/index.htm +++ b/wled00/data/index.htm @@ -60,6 +60,8 @@ body { -ms-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; + scrollbar-width: 6px; + scrollbar-color: var(--c-sb) transparent; } html, diff --git a/wled00/data/welcome.htm b/wled00/data/welcome.htm index 0542aff5..f0e1b463 100644 --- a/wled00/data/welcome.htm +++ b/wled00/data/welcome.htm @@ -3,13 +3,13 @@ - - WLED Setup + + Welcome! - - - - -

- + +

Welcome to WLED!

Thank you for installing my application!

-If you encounter a bug or have a question/feature suggestion, feel free to open a GitHub issue!

Next steps:

Connect the module to your local WiFi here!

Just trying this out in AP mode?
- - +
+
\ No newline at end of file diff --git a/wled00/html_other.h b/wled00/html_other.h index dc77cd51..e78f6d18 100644 --- a/wled00/html_other.h +++ b/wled00/html_other.h @@ -52,27 +52,17 @@ onclick="B()">Back)====="; // Autogenerated from wled00/data/welcome.htm, do not edit!! const char PAGE_welcome[] PROGMEM = R"=====(WLED Setup - - - -

-

Welcome to WLED!

Thank you for installing my application!

-If you encounter a bug or have a question/feature suggestion, feel free to open a GitHub issue! -

Next steps:

Connect the module to your local WiFi here! -

Just trying this out in AP mode?
-)====="; +content="#222222">Welcome! +

Welcome to WLED!

+Thank you for installing my application!

Next steps:

+Connect the module to your local WiFi here!

+Just trying this out in AP mode?

+)====="; // Autogenerated from wled00/data/liveview.htm, do not edit!! diff --git a/wled00/led.cpp b/wled00/led.cpp index d11cefe0..7b359fae 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -225,7 +225,7 @@ void handleNightlight() nightlightDelayMs = (int)(nightlightDelayMins*60000); nightlightActiveOld = true; briNlT = bri; - for (byte i=0; i<4; i++) colNlT[i] = col[i]; // remember starting color + for (byte i=0; i<4; i++) colNlT[i] = col[i]; // remember starting color if (nightlightMode == NL_MODE_SUN) { //save current @@ -233,6 +233,7 @@ void handleNightlight() colNlT[1] = effectSpeed; colNlT[2] = effectPalette; + strip.setMode(strip.getMainSegmentId(), FX_MODE_STATIC); //make sure seg runtime is reset if left in sunrise mode effectCurrent = FX_MODE_SUNRISE; effectSpeed = nightlightDelayMins; effectPalette = 0; diff --git a/wled00/set.cpp b/wled00/set.cpp index 763162f1..41525831 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -22,7 +22,8 @@ bool isAsterisksOnly(const char* str, byte maxLen) if (str[i] == 0) break; if (str[i] != '*') return false; } - return true; + //at this point the password contains asterisks only + return (str[0] != 0); //false on empty string } diff --git a/wled00/usermods_list.cpp b/wled00/usermods_list.cpp index dcecd0ff..90b18074 100644 --- a/wled00/usermods_list.cpp +++ b/wled00/usermods_list.cpp @@ -10,7 +10,9 @@ * \/ \/ \/ */ //#include "usermod_v2_example.h" -//#include "usermod_temperature.h" +#ifdef USERMOD_DALLASTEMPERATURE +#include "../usermods/Temperature/usermod_temperature.h" +#endif //#include "usermod_v2_empty.h" void registerUsermods() @@ -21,6 +23,8 @@ void registerUsermods() * \/ \/ \/ */ //usermods.add(new MyExampleUsermod()); - //usermods.add(new UsermodTemperature()); + #ifdef USERMOD_DALLASTEMPERATURE + usermods.add(new UsermodTemperature()); + #endif //usermods.add(new UsermodRenameMe()); } \ No newline at end of file diff --git a/wled00/wled.h b/wled00/wled.h index ca6ca53d..d5a8114b 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2009070 +#define VERSION 2009100 // ESP8266-01 (blue) got too little storage space to work with WLED. 0.10.2 is the last release supporting this unit.