Commit Graph

565 Commits

Author SHA1 Message Date
Maxim Prokhorov
4d157ccd5b ha: discovery refactoring
- retain setting
- generate topic and message in the discovery object instead of
creating them all at once
- re-implement relays, lights and sensors discovery
- rework name normalization, use relative magnitude indexes
- replace original lights code with schema: json, subscribe to a special
topic to handle lights instead of using the common API
(still wip - colors, hs, temperature settings)

resolve #630
resolve #1564
resolve #2403
2021-01-26 01:02:49 +03:00
Maxim Prokhorov
021f0afb86 sys: clean-up system-specific functions
- shrink utils source file, move heartbeat and boot management into system
- improvise with 'heartbeat' functionality. include scheduler implementation that will
manage the per-module heartbeat callbacks with individual 'mode' and
'interval' settings. current ones are mqtt (including relays, lights, thermostat), debug and
influxdb. preserve heartbeat NONE, ONCE and REPEAT, REPEAT_STATUS is effectively a hbReport & status bit.
- mqtt heartbeat is managed through mqttHeartbeat() callbacks
- tweak mqtt callbacks to use lists instead of the vector, slighly reducing the size of the .bin
- update WebUI, include report setting and update hbMode values
- make sure general.h settings include new heartbeat,
move constant definitions outside of the header
- correctly include dependencies through the .cpp, avoid leaking
internal details.
- as a side-effect, base headers are no longer included recursively
2021-01-24 03:38:02 +03:00
Maxim Prokhorov
8df23392a9 webui: clean-up cfd6e36dbe
update to terser v5
replace gulp-remove-code with a rough equivalent in the gulpscript itself
replace gulp-inline with gulp-inline-source-html
remove base64 modules as redundant when running inline-source (does both)
remove crass as redundant when running inline-source (uses csso)
fixup jquery source map comment (but still keep the actual file)

at least now this seems stable enough to start more of the ui tweaking
2021-01-16 20:40:23 +03:00
Maxim Prokhorov
e7f97c09e4 webui: some more version bumps
pure-css 1.0.0 -> 2.0.3
datatable 1.10.16 -> 1.10.23
generic jquery-slim -> custom jquery/jquery@a32cf6324f slim build with an addition of -sizzle

does not seem to be breaking anything (yet)
2021-01-15 23:54:16 +03:00
Maxim Prokhorov
df24cf0036 webui: fix missing files and bump jquery 2021-01-15 23:18:15 +03:00
Maxim Prokhorov
3e0291e534 webui: bump old deps 2021-01-15 23:06:19 +03:00
Maxim Prokhorov
808981ca39 webui: update colorpicker
ref. https://github.com/xoseperez/espurna/issues/1132#issuecomment-431868924
it is slightly bigger, but better looking and no jquery dependency

rework colorpicker style as well, hide to prevent sending garbage when
lights are off. update lights module to send `lightState()` and separate
state from status payloads

yes, input[type="color"] is an option, but it does not look good
2021-01-15 22:46:55 +03:00
Maxim Prokhorov
cfd6e36dbe webui: use terser as js minifier
support es6 syntax
use js comment style in custom.js
only minify the custom.js

using 4.x branch, since 5.x wants async / await and more changes to the gulp script
2021-01-15 22:45:44 +03:00
Max Prokhorov
8ceeebdb24 providers: relays, lights and buttons refactoring (#2414)
- gpio module now tracks the known providers (right now, hardware and mcp expander)
- refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions
- refactored button module to use gpio provider instead of referencing types itself
- removed dual & stm code from buttons, migrate both to relay module
- added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did)  
- relays runtime configuration keys
- relay command now shows configured relays and current & target statuses
- refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead
- remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT
- allow to bind rf codes to real relays
- drop tuya-specific lights provider, remove tuya code from relays and lights modules
- integrate tuya via relay listeners and providers, use lights custom provider
- implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle)
- lights custom provider (global, not per-pin) and state listeners
- remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT
- lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT
- refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing
- transition time + step parameter for the lightUpdate
- report mask parameter for the lightUpdate
- minor fixes across the board

resolve #2222
2021-01-14 10:39:18 +03:00
Maxim Prokhorov
2a2650f769 webui: fit title on one line 2021-01-04 06:27:03 +03:00
Maxim Prokhorov
f0f6f1b8c9 utils: simplify version + revision into just version 2021-01-04 06:05:04 +03:00
DmitryBlinov
5aeb24f263 garland: new module (#2408)
Port of https://github.com/Vasil-Pahomov/ArWs2812 from Arduino to ESP8266
Implementing garland of WS2812

Co-authored-by: Dmitry Blinov <dblinov@blackberry.com>
2020-12-24 17:44:59 +03:00
Maxim Prokhorov
aec13cef63 ntp: clean-up
resolve #2327, #2220

- remove legacy support in the webui
- format datetime strings on the device, use NTP panel to display them both
- migrate from the old ntpOffset + ntpDST + ntpRegion to ntpTZ
2020-09-30 11:41:18 +03:00
Max Prokhorov
d63228ef50 wifi: update to justwifi development version (#2347)
- support 32 byte hostname / ssid
- support 64 byte passphrase
- slightly reduce amount of memory allocations
- tweak initialization paths to call persistent(false) as early as possible
2020-09-10 01:05:02 +03:00
Max Prokhorov
7b57274d1f sensor: Add PZEM004T V3.0 (#2283)
Add new V3.0 version of PZEM004T, not tested. Default to factory default address 0xf8, configurable through pzemv30Addr 8-bit number
Add 'frequency' measurement & 'hz' unit
Add pz.address that configures address
Implemented energy reset

Right now we only support a single device. No way to test this properly (mostly, how exactly we need to connect this stuff), so left as not implemented.
2020-07-03 23:25:33 +03:00
Max Prokhorov
d9cb35f781 sensor: streamline correction settings (#2265)
* wip

* template common operation

* more

* ui

* fix naming issues

* remove old constraints

* oops

* dummy sensor

* rearrange bmx280 magnitudes
2020-05-31 05:49:34 +03:00
Eric Chauvet
21e75bef51 Kingart curtain switch UI support (#2250)
* Completed kingart curtain switch support:
Added Web UI controls and view in status
Added power up behaviour (nothing, close, open, last position)
Added curtain style (Roller, etc...) for UI status and to be used in MQTT

* Checked commit before PR. Added html gulp static files generated.

* Corrected a code refactor error which make the MQTT messages not handling position from received messages. Added comment to debug tab to show how to enable debug

* Use the maximum compression for gzip. A byte is a byte :)

* Update code/espurna/curtain_kingart.cpp

Co-authored-by: Max Prokhorov <prokhorov.max@outlook.com>

* Variable name prefix update
Added public set position function and curtain count

* Added Scheduler new type : curtain

* Add curtain schedule support and correct the 12h bug when adding a slot (00:00 after refresh). Default Hour is 12h

* Code cleaning.
Schedule support.
Light support is having an issue with new schedules corrected here.

* I let do better by the specialists

* Curtain init statues

* Coding style corrections

* Removed debug stuff from now - will be back later with the right way

* rebuild webui

* revert 435f1c5e03 schHour default, rebuild ui

Co-authored-by: Eric Chauvet <eric.chauvet@test-tree.com>
Co-authored-by: Max Prokhorov <prokhorov.max@outlook.com>
2020-05-18 02:19:50 +03:00
Max Prokhorov
cae50fa544 sensor/emon: refactoring (#2213)
- Update sensor classes to support a generic way to store energy values
- Update sensor conversion code to deal with units and not magnitudes
- Add magnitude<->unit for sensors, generic way of defining used unit. Convert from sensor magnitude unit to the one used for display.
- Reset energy value based on index through external means (MQTT, HTTP)
- Rework energy timestamping, update webui with 'last saved' value

While this solves the energy conversion issues and we are finally seeing the real value, what I don't really like:
- KilowattHour and WattHour are separate enum tags, thus sort-of are different types altogether
- Conversion code in Energy object should probably use some generic 'ratio' calculation? (https://en.cppreference.com/w/cpp/numeric/ratio/ratio)
- We are still using runtime checks to do calculations and depend that sensor outputs only one specific value type.

Consider this a fix for energy display / storage and preliminary work on sensor.ino
Further sensor refactoring... soon.
2020-04-08 00:37:26 +03:00
Max Prokhorov
83339605aa webui: ledGPIO is a list (#2202) 2020-03-30 13:41:11 +03:00
Max Prokhorov
917ce8de83 Optional Web(UI) OTA (#2190)
* web: optional OTA support

* add prototype

* hide under websupport
2020-03-20 21:05:04 +03:00
Max Prokhorov
80825590a5 LED Updates (#2170)
* support GPIO setting in WebUI
* experimental led pattern support
* support loading settings in setup() (not yet fully working)
2020-03-13 07:01:14 +03:00
Max Prokhorov
ba3e6267e6 Button pin provider & runtime settings (#2162)
* wip

* cleanup buttons-through-serial code, remove hw mention from button module

* remove wip

* implement mqtt settings

* fixup struct members, dual no longer allocates debouncer

* add missing debounceevent lib

* fix missing event_handler, update names

* fix namespace

* drop lib

* fix int<->bool comparison

* Move gpio16 handling from DigitalPin to EventHandler

* Cleanup debounceevent headers

* Don't expect system headers to be included

* re 70b54c489f - no allocation, for real

* Adjust settings names

* dont retain by default

* unused

* typo

* Fix length type (ref 6017ad9474)

* Move pin class outside of debounce lib, lowercase ns

* move event handling inside of button_t

* refactor config. ..._MODE -> _CONFIG, ..._MODE_... -> ..._ACTION_...

* fix test

* naming

* move indexed value to header

* refactor actions into direct opts

* fix webui, fix buttons not respecting old user setting

* change button config format from bitmask to a struct, adjust settings conversion

* proxy some more header defautls, fix web kv

* gpiopin

* adjust webui func to support every setting

* clarify single-return event->string

* fix dual setting

* fix dual packet condition, de-duplicate funcs

* fix bogus warning
2020-03-13 04:42:40 +03:00
foxman69
bc1fb0ba38 WebUI: alert when WS closes (#2131)
* Added alert when websocket closes and trying to trigger it faster

* Added window before function...

* Changed from setTimeout to SetInterval

* Fixed position of if statement

* formatting

* images

Co-authored-by: Max Prokhorov <prokhorov.max@outlook.com>
2020-02-09 01:41:14 +03:00
Sammy BAUER
f73917decc Configure Thingspeak URL at runtime (#2124)
* Permit thingspeak urn edit

* Update thinkspeak.ino

* Update index.html

* Replace Host, Port, and URL with Address in Thingspeak

* Create AsyncThingspeak object

Create AsyncThingspeak object to contain the url of the component.

* replace pointer by class member

Thingspeak class improvement to answer Max's question:
why use a pointer when it can be a class member?
So now address parameter isn't a pointer anymore.

* Update Thingspeak address on post
2020-02-09 01:15:27 +03:00
Max Prokhorov
ba3ec47ed0 NTP: use sntp app from lwip on latest Cores, replace ntpclientlib (#2132)
* ntp: try using sntp app from lwip, drop ntpclientlib

* fix display

* thermostat: fix day and month getters

* test build sizes with scheduler

* use system timers for once-a-minute scheduling, no polling

* tick

* avoid timestamps, use tm

* drop utc rpn operator, add utc_hour and utc_dow

* try to build with old implementation too

* dep

* notify ws

* progmem

* cleanup types

* offset tm values by 1 to match existing schedules

* avoid using ntpclientlib with rpn

* test. show debug strings in sch

* fix secureclient

* consts, fix unsyncing when changing tz (and not triggering sntp after reinit for some reason)

* startup time in seconds

* same delay as lwip

* header

* assume build timestamp is unixtime

* cache server value

* fmt

* typo

* handle dhcp request

* rename

* web

* TZ.h

* add notice about what alias means

* fix disabling NTP_SUPPORT

* scheduled ticker

* same behaviour as old module

* rollback rpn dependency check, utc_ prefixes

* ...

* comments, refactor naming
2020-02-04 06:17:40 +03:00
Max Prokhorov
298ce8cac2 Refactor get/set/del/hasSetting (#2048)
* experimental: refactor get/set/del/hasSetting

* sensors

* lights

* cleaup

* r

* tuya

* fixup! sensors

* fixup! tuya

* header defaults types

* fix lights

* setup already checks for max

* helper for flashstring

* fix overload

* oops

* refactor includes

* warnings

* test with migrate

* add ids in a separate file

* cleanup

rev: crash

rev: domoticz

rev: encoder

rev: loopdelay

rev: hass

rev: i2c

rev2: hass

rev: mqtt

rev: rfm69

rev: relay

rev: rpn

rev: settings setup

rev: hb settings

rev: telnet preprocessor fix

rev: settings wrap

rev: tspk bool style

rev: wifi types

rev: util hb

rev: settings

fixup! rev: settings

* rev: cleanup wifi injections based on new getters

* hasSetting now can return true for empty key

* show hardcoded network in web

* oops

* fix ws referencing wrong index

* ensure empty strings are written

* c/p

* use experimental schema style for payload, mark network as not deletable

* allow to customize converter

* shorter syntax, try using with wifi

* use proper #if syntax to handle definitions that are missing

* fixup ota sc checks getter, cast schEnabled to bool

* add utils header to sensors
2020-01-20 16:39:35 +03:00
foxman69
e3887da8a0 WebUI: Fix scheduler panel tabindex= values (#2096)
* added data-settings-max value to html

* fixed: use the value and not the defenition of the function

* the schedules variable already starts from 0 not need to increment

* another misuse of function as variable
2020-01-13 14:33:28 +03:00
Max Prokhorov
4f5e9fa1b7 OTA: verify data stream and properly handle errors (#2067)
* webui: improve updater error message

* ota: properly check updater state and finalize on errors

* finish up ota handling refactor

* fail web upgrade when cannot find magic byte

* send updater status with no payload arg and always send payload with

* mention magic byte and flash mode in webui

* gzip magic

* make async ota at least usable. timeouts, show errors, try harder to find data after headers

* simplify setup and destruction

* cleanup class instantiations for ota and url

* handle default case of magicflashchipsize

* shorter

* blobs
2019-12-21 00:19:15 +03:00
Max Prokhorov
43cf926468 ha: try to avoid conflict with useCSS (#2075) 2019-12-21 00:07:10 +03:00
Max Prokhorov
0f02256860 Small fixes (#2071)
* web: fix rfb node generator syntax, do not send as basic settings

* ha: allocate discovery object later
2019-12-19 00:56:29 +03:00
Max Prokhorov
8e7854b04e WebUI fix change detection of input elements (#1986)
- use setOriginalsFromValues function right after elements had changed and
**only** with those elements
- add checkbox handling to setOriginalsFromValues to match hasChanged
- apply hasChanged after value is set to refresh originals after saving
- change parts that already set 'original' attribute manually

This was sort-of broken, because original attr never worked as intended. 
Also fix possible OOM for large WebUI images, since sending full config each time means that we need more memory to buffer and parse it.
2019-12-18 17:45:51 +03:00
foxman69
5cf687ffc1 WebUI: Fixed small aesthetic problem (#2038)
* Fixed small esthetic problem

* Changed to legend
2019-12-09 09:22:51 +03:00
Max Prokhorov
2ef21d840d WebUI: fix some issues
- fix colorpicker variable name
- var msg and var pre for debug messages
- add gpio16 to gpio list, remove unused template code
- fix lightfox endif matching rfbridge instead of lightfox
- formatting
2019-12-09 09:10:40 +03:00
Max Prokhorov
15accf8090 web: check sch_last existence (#2050) 2019-12-09 07:40:36 +03:00
Maxim Prokhorov
812c3ea8a0 web: init relay selectors inside relayConfig 2019-11-25 23:35:28 +03:00
Max Prokhorov
9a5698b342 Add TUYA_SUPPORT (#1997)
- add experimental `relayDummy` to configure dummy relays at runtime
- add tuya-generic-dimmer #1729
- cleanup broker interface to allow Tuya module to properly receive events, modify broker methods to allow different function signatures
- add basic tests for Tuya frame and data protocol
2019-11-21 01:14:17 +03:00
Max Prokhorov
ab186e057e Add missing / not implemented default getSettings values (#1996)
* scheduler: match webui defaults

* relay: inverse error condition

* api: simplify apikey handling

* thingspeak: use apikey default value

* web: fix checkbox value for haschanged

* fixup! scheduler: match webui defaults
2019-11-18 02:48:22 +03:00
Max Prokhorov
849f8cf920 Rules RPN (#1984)
* RPN rules (WIP)

* RPN rules web interface, MQTT inputs

* Stickyness, rpn.ops,...

* Perform light updates only when value changes

* Improve wsSend performance

* Revert PR test

* Check TERMINAL_SUPPORT for _rpnInitCommands and remove unused variable

* Fix merge

* formatting

* disable by default (?)

* changelog

* comment

* remove debug function wrappers in favour of var activation

* fixup! comment
2019-11-10 07:01:50 +03:00
James
d177634a70 Telaire T6613 Support (#1956)
* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Updated copyright string

* Buffer from 6 bytes to 8 bytes

Current gcc-4 does not mark this as warning, but gcc-9 notices the 3 char size requirement. Buffer should be 8

* Use 5000ppm max
2019-11-06 14:32:58 +03:00
foxman69
4343457b9e Support restore last schedule (#1948)
* Added restore last schedule support

* Merged RestoreLastScheduleState function into the _schCheck function

* handle lights in restore action

* hide webui chbox when not using scheduler

* use settings instead of struct member, hide under ifdef scheduler_support

* relayLastSchedule uses SCHEDULER_RESTORE_LAST_SCHEDULE as default

* Changed all the variable names to be the same so there would be no confusions

* Fixed client side to create an array from relayLastschedule

* Fixed cosmetic issue with the toggle display in webui

* Fixed variable name and disabled comparison at the end

* Added another check if the switch type is light provider

* Changed variables naming

* Naming mistake
2019-11-06 14:25:42 +03:00
Max Prokhorov
6d9d4ae149 light: provide mired warm / cold limits to webui 2019-10-15 19:14:22 +03:00
Xose Pérez
8b7eea6c72 ESPurna base image for Tuya Convert 2019-10-11 17:44:47 +02:00
Max Prokhorov
deb465763f Fix WiFi scan results in Web (#1913)
* web: re-add wifi scan action, send as json array

* ws: forcibly inline send functions
2019-09-20 15:37:54 +03:00
Max Prokhorov
a2688ec376 lights: don't show v for hsv picker, use brightness instead 2019-09-10 12:39:28 +03:00
Max Prokhorov
f8deb535b5 lights: selector typo 2019-09-10 12:36:09 +03:00
Max Prokhorov
8dbd25c548 lights: initColor args 2019-09-10 12:35:12 +03:00
Max Prokhorov
e233fd5b08 web: move hsv picker conversions into functions 2019-09-07 12:48:35 +03:00
Max Prokhorov
0bf07f166e web: update to jquery 3.4.1 and wheelcolorpicker 3.0.8 2019-09-07 12:37:31 +03:00
Max Prokhorov
68270310c7 web: parse host query via browser api, logging 2019-09-06 14:37:39 +03:00
foxman69
d66b8a9bed Syncronize js when saving configuration (#1863)
* Syncronize js when saving important data

* update webui
2019-08-27 01:15:24 +03:00