Skip to content

Full blazoncek fork merge - #2610

Closed
Aircoookie wants to merge 33 commits into
mainfrom
blazoncek-merge-working
Closed

Aircoookie wants to merge 33 commits into
mainfrom
blazoncek-merge-working

Conversation

@Aircoookie

Copy link
Copy Markdown
Member

Introduces all features and fixes of @blazoncek dev branch.
PR for feedback and adjustments.

@blazoncek blazoncek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the uncommented changes are cosmetic or bugfixes (including all usermods).
applyPreset()/handlePresets() may need special treatment as may refreshLightCapabilities().

else temp.add(F("°F"));
temp.add(degC ? F("°C") : F("°F"));

JsonObject sensor = root[F("sensor")];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about adding sensor data to info object a while. This is it.

PSTR("~ %02d-%02d %02d:%02d:%02d ~"),
month(localTime), day(localTime),
hour(localTime), minute(localTime), second(localTime));
cacheInvalidate++; // force reload of presets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tries to circumvent occasional browser caching issues.

Comment thread wled00/FX.h
inline bool isOffRefreshRequired(void) {return _isOffRefreshRequired;}
};

extern const char JSON_mode_names[];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to cpp. Saved a few bytes on my tests.

Comment thread wled00/FX_fcn.cpp Outdated
}
if (correctWB && type != TYPE_ANALOG_1CH) capabilities |= 0x04; //white balance correction (uses CCT slider)
uint8_t aWM = Bus::getAutoWhiteMode()<255 ? Bus::getAutoWhiteMode() : bus->getAWMode();
bool whiteSlider = (awm == RGBW_MODE_DUAL || awm == RGBW_MODE_MANUAL_ONLY) || (aWM == RGBW_MODE_DUAL || aWM == RGBW_MODE_MANUAL_ONLY); // white slider allowed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may need fine-tuning.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer sure awm (instance->autoWhiteMode) is needed here since Bus::getAutoWhiteMode() returns the same value. Global override.

Comment thread wled00/json.cpp
//if none selected, apply to the main segment
if (!didSet) deserializeSegment(segVar, strip.getMainSegmentId(), presetId);
//TODO: not sure if it is good idea to change first active but unselected segment
//if (!didSet) deserializeSegment(segVar, strip.getMainSegmentId(), presetId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may uncomment this but IMO if no segments are selected it should not apply.

Comment thread wled00/json.cpp
root[F("fxcount")] = strip.getModeCount();
root[F("palcount")] = strip.getPaletteCount();

JsonArray ledmaps = root.createNestedArray(F("maps"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows selection of ledmap within preset.

Comment thread wled00/presets.cpp Outdated
return true;
}

void handlePresets()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was originally applyPreset().

@blazoncek blazoncek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see there are no major or breaking changes except async preset loading.
Changes in UI loading have been thoroughly tested with plenty of ESP8266 units with various network signal strengths.

infoArr.add(F("disabled"));
}

JsonObject sensor = root[F("sensor")];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sensor info object we talked about (exposing sensor info to integrations).

Comment thread wled00/FX_fcn.cpp
uint16_t count = defCounts[(i < defNumCounts) ? i : defNumCounts -1];
prevLen += count;
BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, DEFAULT_LED_COLOR_ORDER);
BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, DEFAULT_LED_COLOR_ORDER, false, 0, RGBW_MODE_MANUAL_ONLY);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are free to change to DUAL if you wish.

Comment thread wled00/bus_manager.h
uint8_t autoWhite;
uint8_t pins[5] = {LEDPIN, 255, 255, 255, 255};
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0) {
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0, byte aw=RGBW_MODE_MANUAL_ONLY) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can as well be DUAL.

Comment thread wled00/bus_wrapper.h
//#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi20MhzMethod>
//#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801SpiMethod> // 10MHz
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod> //slower, more compatible
#if defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==40000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps adding runtime selection in the future.

Comment thread wled00/cfg.cpp
// initialize LED pins and lengths prior to other HW (except for ethernet)
JsonObject hw_led = hw["led"];

uint8_t autoWhiteMode = RGBW_MODE_MANUAL_ONLY;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this to stay MANUAL.

Comment thread wled00/json.cpp

root[F("mainseg")] = strip.getMainSegmentId();

bool selectedSegmentsOnly = root[F("sc")] | false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New feature to allow saving only selected segments to preset.

Comment thread wled00/json.cpp
}
}

void serializeModeData(JsonArray fxdata)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handlers for SR extensions to mode/effect data.

Comment thread wled00/presets.cpp
static volatile byte callModeToApply = 0;
static volatile bool checkPlaylist = false;

bool applyPreset(byte index, byte callMode, bool fromJson)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest change: async preset loading.

Comment thread wled00/wled.cpp
yield();
#endif

handlePresets();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async preset loading entry point.

Comment thread wled00/wled.cpp
}

// 15min PIN time-out
if (strlen(settingsPIN)>0 && millis() - lastEditTime > 900000) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be made customizable at some point.

@blazoncek

Copy link
Copy Markdown
Contributor

@Aircoookie any progress on this?

A few main points to test:

  • auto-white global override/per pin setting
  • settings PIN code/protection
  • slider control (effect defaults, slider visibility & name, palette hiding & defaults)
  • ESP8266 web stress test
  • HA integration (CCT & sensor info)
  • UI across different devices (I only have Apple, FF & Safari)

Also, it may be good to add Play and Pause glyphs to Wicons font.

@Aircoookie

Copy link
Copy Markdown
Member Author

Thank you for the latest additions! :)
I have to be honest that I will likely not find the time/energy to get to this in the next 14 days. New study course is absolutely mental, I am thinking about canceling it since I have 0 time left for WLED :(
Would you make another branch with just the new UI (the 3 files index.js/css/htm only, you do not have to include the ESP side code to make it actually work). That might make it a little easier, I'm basically trying to get the diff between this branch and main down piece by piece until I can merge it completely 👍

@Aircoookie

Copy link
Copy Markdown
Member Author

Reason I can't just copy UI files myself is that I would get attribution for all your changes which is not fair imo. And I did not find an easy option to merge only some files (without creating a huge change set by reverting changes to all other files)

blazoncek and others added 9 commits April 12, 2022 15:57
- auto segments selected
- slider data added to data-opt
Bugfix for HTTP API preset.
WS multiple broadcast fix.
Turning segment on/off will not reset currentPreset/cause stateChanged.
- Changed boot load order (info must be present before presets are loaded because pmt is required), this fixes new presets not appearing after page reload
- Fixed repeat segments turning off regression
- Added Update button to info section
Yellow connection indicator on pending request (turn red on actual failure/timeout)
- keep .staytop/.staybot sticky
- .fnd inheritance
Cleanup.
Added new holidays.
Do not redirect back to main page but immediately to intended page
Make PIN work on /update page
Comment thread wled00/wled_server.cpp Resolved
Fix OTA lock
Fix OTA lock not locking edit page
Remove reboot requirement for changing OTA lock
Slight Flash string optimization
Comment thread tools/cdata.js Resolved
Comment thread wled00/wled_server.cpp Resolved
Comment thread wled00/wled_server.cpp
});

createEditHandler(correctPIN);
createEditHandler(correctPIN && !otaLock);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTA lock should have no influence on ability to visit /edit page.
Security setting cannot be changed using /edit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/edit page is able to set (not retrieve sec) arbitrary settings, but more critically, able to alter the pages displayed to the browser, which is a security risk. It can even be seen as a form of OTA update :)
PIN is an adequate protection, but if the user has OTA lock active before and after the update, they would still expect /edit to be locked. I will change the label of OTA to make clear that it also locks edit though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I fail to understand how a user can update if OTA is locked? If you mean serially then all measures are irrelevant since with physical access anything is possible.
If OTA is locked it will prevent any kind of updates (not true ATM due to bug) to firmware even if PIN is entered and that should be the main purpose of it IMO (which also holds for WiFi settings).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can't update the firmware, but they can arbitrarily change the index.htm served to clients.

Regarding ArduinoOTA: I think it should stay separate from OTA lock - most common use case for OTA lock is allowing access to port 80 only. This allows local updates via ArduinoOTA without having to unlock OTA each time. If ArduinoOTA is disabled via the checkbox and OTA locked, it can't be re-enabled without the correct OTA password. Should add a note though that ArduinoOTA will remain active unless disabled manually.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that locking OTA should be consistent for both options: web update and Arduino OTA. Otherwise an adversary can update firmware even if a user thinks he/she locked OTA updates and considers WLED secure.

/edit page is able to set (not retrieve sec) arbitrary settings, but more critically, able to alter the pages displayed to the browser

Locking settings (and /edit) using PIN code should be sufficient for most cases where WLED can be put to public use (with the warning about non encrypted transfer). Removing fake index.htm can be done without too much effort in case when adversary intercepted PIN and uploaded fake index.htm. Combined with OTA lock it can prevent most malicious attacks (except carefully planned ones) even with plain HTTP. I would not expect /edit to be locked when OTA is disabled/locked. It has become a feature that was suggested as a help in case of many problem solving options. It will also prevent uploading ledmaps and such which should not be a condition of OTA lock.

PIN in itself will also prevent updating OTA and will lend a grace period of 15 minutes (when entered) in which time you can do OTA (Arduino or web) if you need to update.

@Aircoookie Aircoookie mentioned this pull request May 3, 2022
@blazoncek blazoncek linked an issue May 5, 2022 that may be closed by this pull request
1 task done
@blazoncek

Copy link
Copy Markdown
Contributor

I have an update on async preset loading.

WLED UI knows content of a preset so instead of sending "ps":X it can send complete JSON API for a preset (including HTTP API if that is the case) and alongside just notify core that preset has been applied (i.e. "pt":X).
In such case a call to applyPreset() is not needed and correct state can be returned immediately to caller (ie UI).
For other preset loading events a normal async loading does not constitute a problem since the caller (button, usermod, ...) does not care.

If an external source (i.e. not WLED UI) wants to change a preset by using preset ID I cannot see a reason why would it require a returned state to reflect exact preset content immediately since it can subscribe to websockets or periodically request a state to get the correct state at any given time (since WLED state may change from another source and in such case it would maintain incorrect state internally after another source changed WLED state).

So I would propose to change WLED UI to send complete preset API to WLED and pass a preset ID alongside API ("pt" from above). This may simplify preset loading and issues tied to it.

@blazoncek

Copy link
Copy Markdown
Contributor

This has been superseded by #2737
Closing.

@blazoncek blazoncek closed this Aug 18, 2022
@blazoncek
blazoncek deleted the blazoncek-merge-working branch August 30, 2022 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants