Commit Graph

63 Commits

Author SHA1 Message Date
Maxim Prokhorov
2f6d7ce3d3 system: light and deep sleep api
see #2578

* deep sleep api without ESP class dependency
* rf + cpu light sleep for cases when deep sleep cannot be used
* generic time-based light sleep; nonos does not halt cpu,
  unlike the wakeup variant. timers also keep going, so
  this has to be used with extra care

pending some 'deferred' variant and before and after sleep actions
2023-03-15 17:06:02 +03:00
Maxim Prokhorov
28f3b7da84 wifi: turned off on boot 2023-03-10 01:00:20 +03:00
Maxim Prokhorov
0ab8c855e2 wifi: revert to no fpm settings 2023-03-10 00:59:19 +03:00
Maxim Prokhorov
670b5d68d5 wifi: both light and modem sleep modes are used 2023-02-05 00:49:35 +03:00
Maxim Prokhorov
9789bba923 wifi: shorter keys for forced sleep 2023-02-05 00:44:04 +03:00
Maxim Prokhorov
bb4e74d03f wifi: experiment with forced light sleep
see #2578

make TurnOff action select sleep mode from available settings
wifi.off and wifi.on commands in addition to existing AP & STA

overriding buttons is... problematic?
e.g. selecting LO trigger and existing hw pushbutton GPIO,
we are most likely to trigger long-click event
2023-02-04 21:57:44 +03:00
Maxim Prokhorov
f387b864da relay: scheduling from system timer does not work
also queue fallback check instead of resolving it in the timer
resolve #2571
2023-01-11 05:47:17 +03:00
Maxim Prokhorov
d85ddad6da system: de-dup progmem strings
c/p PSTR attribute from Core files
dostring declaration with a macro instead of a scary looking boilerplate

saves varying amount of code space, mostly deals with our key and cmd strings
2022-10-23 03:19:07 +03:00
Maxim Prokhorov
0970269033 util: more string views for internal funcs 2022-10-23 03:18:57 +03:00
Maxim Prokhorov
510d68d079 system: fixup timers and loop callbacks
* globally accessible system timer class; help out with our internal
  scheduling by always using strongly typed duration and dynamic
  time adjustment for durations longer than system limits
  (see `os_timer_t` documentation)
* our own class for scheduled callbacks which are either choosing a
  simple function pointer or std function wrapper, depending on the type
  passed into the constructor. specifically for scheduled functions,
  this allows us to filter globally scheduled functions and push them to
  the front of the queue when necessary to ensure certain order of calls
* replace Ticker instances with SystemTimer
* allow types {h, cpp} in unit tests
2022-10-23 03:18:57 +03:00
Maxim Prokhorov
3d580f3577 terminal: __FlashStringHelper -> StringView
- clean-up comparison routines and get rid of most of the casts
- reduces total number of calls to terminalRegisterCommand
  replace with a func accepting list of commands, which in
  turn get instantiated as constexpr PROGMEM arrays
- reduce ram fragmentation, since we don't need to alloc as much
- reduce flash consumption b/c of lambda -> standalone func conversion
2022-09-25 06:14:54 +03:00
Maxim Prokhorov
af12762eb6 wifi: fix blocking-delay oopsie
blockingDelay uses inverse logic; passed function should return false
when the condition is satisfied
only broken on 2.7.x, 3.x.x skips the check
2022-09-21 04:31:20 +03:00
Maxim Prokhorov
78cd6556f0 system: build time constants and settings
get rid of board module, replace with system calls for hostname, board
and password. move boot (quirks) handlers to system as well
espurna::build { ... } namespace for our app const values
2022-09-21 04:21:23 +03:00
Maxim Prokhorov
3e36438748 settings: key check with string view
make our string comparisons nicer
also clean-up namespaces for storage access
2022-08-29 04:37:58 +03:00
Maxim Prokhorov
16fcee1786 Fix namespacing scope, export StringView
rework more namespaces to use `espurna` root
makes internal references much easier (and shorter)

view class is not specific to settings, could use it across the app
remove duplicate code from IR
2022-08-25 00:41:26 +03:00
Maxim Prokhorov
567b9d7769 web: also check for ap state 2022-06-01 22:20:25 +03:00
Maxim Prokhorov
a64631ebd6 wifi: opmode can be changed directly 2022-06-01 18:34:25 +03:00
Maxim Prokhorov
6a0d6b0c49 sns: more flash strings 2022-05-25 05:07:04 +03:00
Maxim Prokhorov
2338f54cf5 wifi: show the current config via terminal 2022-01-31 16:32:04 +03:00
Maxim Prokhorov
058c6344f3 wifi: missing scan settings query 2022-01-30 20:48:54 +03:00
Maxim Prokhorov
e213b58db2 settings: continue refactoring internal constants
Settling on naming 'options' for enumerations (...possibly, everything
else in the future, would that make sense to store for 'setting' object)

Update terminal commands that were reporting status to also report a
full list of 'indexed' settings for the specific entity
Also updates the WebUI outputs which are (hopefuly) are already handled
as-is through the .js processing pipeline and the .html properties
receiving certain special string values

More namespacing and save ~2KiB of RAM by reducing the amount of loaded keys strings
However, ROM side of things may suffer b/c of template specializations for the
generic conversion functions when there are many different types involved.
2021-12-30 02:03:03 +03:00
Maxim Prokhorov
514bc938c2 settings: rework string<->enum conversion
Make sure we seamlessly handle 'convert' for the number and the string version.
And since it is a two-way map, update 'serialize' to use it as well instead of
either a simple static_cast<int> or duplicating the same strings used in 'convert'

Only string literals or static vars can be used in constexpr context,
but those can still be shoved into the flash region via PROGMEM.
Notably, PSTR(...) inside of a lambda is not a constexpr.

Some quirks to work out
- we don't 'enumerate' things through compiler, enum values may go
  missing since it is not a switch-case
- 'get' default value via query still requires us to know the settings
  key in the first place. and it still needs an explicit call to
  'serialize'
- sensor units are stringified as their display value.
  but, this also avoids two different 'string' versions of those
- EnumOptions struct instance may also be in PROGMEM, but one needs
  to be very careful to only allow aligned access to it's members
  (which currently means we can't use 8bit or 16bit 'enum class'es)
2021-12-23 12:51:43 +03:00
Maxim Prokhorov
19963fb8ce system: some unused params 2021-12-18 23:47:20 +03:00
Maxim Prokhorov
79e4fac010 wifi: make sure settings are in namespaces
Localize build constants & settings use, no need to prefix where
namespacing already does this (and also removes some duplicates)
2021-12-18 23:40:53 +03:00
Maxim Prokhorov
2f580a37a2 terminal: context is a temporary
Make sure it could be moved further along, and the values inside of it
can be safely moved as well.

Also fixup commands that were missing ctx in OK / Error.
2021-12-08 18:05:25 +03:00
Maxim Prokhorov
a8cf30832e wifi: use internal types for timeouts
For this, keep things as milliseconds (at least for now)

Make sure to use __builtin_strlen in constexpr context
Remove `has*()` functions that are no longer used

Update WebUI callback to use EnumerableConfig
2021-12-08 13:48:44 +03:00
Maxim Prokhorov
0fdad17635 pzem004: fix single-source build
```
In file included from espurna\espurna_single_source.cpp:62:
espurna\wifi.cpp:282:38: error: specialization of 'T settings::internal::convert(const String&) [with T = IPAddress]' after instantiation
  282 | IPAddress convert(const String& value) {
      |                                      ^
```
2021-11-23 02:36:28 +03:00
Maxim Prokhorov
56caa18d22 wifi: fix fallback triggering ap without checking the setting first 2021-11-23 02:36:28 +03:00
Maxim Prokhorov
a2c02a38e5 hardware: tweak core and core-webui targets
given that relay, button and led settings may be hardcoded,
explicitly remove from -core and -core-webui
restore telnet debugging though, since the terminal output needs it

for -core-webui, disables mdns and the generic webui server + webui blob
per 56f74cfe, make the resulting .bin even smaller
2021-10-20 13:26:12 +03:00
Maxim Prokhorov
6eaf88c69b utils: normalize hostname setting usage 2021-10-20 11:38:07 +03:00
Maxim Prokhorov
6f132ef3c5 webui: debug SEND button should be type=submit
ref. #2476
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
5aa43d4bf1 all: suppress -Wunused-function for serialization helpers 2021-08-16 07:31:00 +03:00
Maxim Prokhorov
7d7bbef2d1 wifi: clean-up
Value init Mac array, both compiler versions support this.
Named constants for conversion function lengths / sizes.
2021-08-12 17:26:48 +03:00
Maxim Prokhorov
c5f70286d1 wifi: allow to set bssid and channel from settings
For when scanning is disabled. Remove uniqueness requirement, since
settings may contain multiple SSID with different BSSID values.

wifi::Mac conversion helpers for both xxxxxxxxxx and xx:xx:xx:xx:xx:xx
2021-08-06 13:21:39 +03:00
Maxim Prokhorov
2012a90592 wifi: no need for template 2021-08-05 18:25:04 +03:00
Maxim Prokhorov
f0f7dcc874 wifi: sort and filter by rssi only when actually connecting
Generate initial connection list with all suitable networks, not only the best ones.
When scanning for a better network, remove results with worse rssi.

Don't remove extra scan results in the delayed scan function,
allow consumer to filter by itself.
2021-08-05 17:46:51 +03:00
Maxim Prokhorov
27f701773f settings: simplify migrateVersion() checks in modules
Just `if (version < N)` instead of `if (version && (version < N))`
Fix existing functions that were not checking for `version > 0`
2021-08-02 07:50:52 +03:00
Maxim Prokhorov
dde5f374dd wifi: rework (re)connection and softAp logic
Immediatly try to connect when reloading settings and previous attempt
had failed. Because of locking, previously this caused a soft-lock of the
internal loop that required waiting for the long Reconnect timeout to
expire first.

Refactor the module to include namespace { ... } and move build settings into .cpp
Saves ~1.5Kb and also allows gcc to issue unused warnings for declared functions.

As a side-effect of refactoring, (temporarily?) remove softAp leases support.
Current Core moved dhcps support into a C++ code, forcing internal logic
to reference a specific object. Better to wait a bit until that
stabilizes and try again. Plus, it is not currently available in the esp-idf.
2021-08-02 07:14:19 +03:00
Maxim Prokhorov
fa3deeffbf webui: remove jquery dependencies and clean-up websocket API
Refactor WebUI:
- remove jquery dependency from the base custom.js and use vanilla JS
- remove jquery + jquery-datatables dependency from the RFM69 module
- replace jquery-datatables handlers with pure-css table + some basic cell filtering
  (may be incomplete, but tbh it is not worth additional 50Kb to the .bin size)
- introduce a common way to notify about the app errors, show small text notification
  at the top of the page instead of relying on user to find out about errors by using the Web Developer Tools
- replace <span name=...> with <span data-settings-key=...>
- replace <div> templates with <template>, disallowing modification
  without an explicit DOM clone
- run `eslint` on html/custom.js and `html-validate` on html/index.html,
  and fix issues detected by both tools

Streamline settings group handling in custom.js & index.html
- drop module-specific button-add-... in favour of button-add-settings-group
- only enforce data-settings-max requirement when the property actually exists
- re-create label for=... and input id=... when settings group is
  modified, so checkboxes refer to the correct element
- introduce additional data-... properties to generalize settings group additions
- introduce Enumerable object to track some common list elements for
  <select>, allow to re-create <option> list when messages come in
  different order

Minor fixes that also came with this:
- fix relay code incorrectly parsing the payload, causing no relay names
  to be displayed in the SWITCHES panel
- fix scheduler code accidentally combining keys b/c of the way C parses
  string literals on separate lines, without any commas in-between
- thermostat should not reference tmpUnit directly in the webui, replace with
  module-specific thermostatUnit that is handled on the device itself
- fix index.html initial setup invalid adminPass ids
- fix index.html layout when removing specific schedules
2021-07-18 23:30:32 +03:00
Maxim Prokhorov
2c91a44334 wifi: handle static config without WiFi::config
Referencing currently used code for the NONOS, plus some Core-specific
things to handle lwip1.4 <-> lwip2 layer

Saves a bit of code handling Arduino WiFi Shield compatibility,
which we don't really need
2021-04-25 02:01:14 +03:00
Maxim Prokhorov
9f64684656 wifi: try to workaround unexpected STAMODE_DISCONNECTED event
Or, at least try to.
wifi_station_disconnect() queues the event, but receiving it will confuse the
connection loop waiting for the one right after wifi_station_connect()

Event SSID is the last connected one, reason is REASON_AUTH_FAIL (202)
Simply switch contexts to allow the event handler to run.
2021-04-25 02:01:14 +03:00
Maxim Prokhorov
976176cfaa ws: use the same type for the schema keys array
Plus, it's not really a constexpr in this context
2021-04-15 21:41:39 +03:00
Maxim Prokhorov
1488c088d8 mdns: more strict check for older Core and wifi mode fixes 2021-04-15 21:41:39 +03:00
Maxim Prokhorov
32ccab920e wifi: fix builds without terminal 2021-04-12 01:55:10 +03:00
Maxim Prokhorov
3ebd8d1cc3 wifi: naming 2021-04-12 01:54:33 +03:00
Maxim Prokhorov
302700867e wifi: use event as trigger for the connection loop
SDK status is an unreliable source of info even when connecting.
Make sure to register both GotIp and onDisconnected and wait for the
events in the wait-loop, checking which one arrived first.

Plus, make sure the connection task object was actually created, before
proceeding with the connect-loop.
2021-04-12 01:47:03 +03:00
Maxim Prokhorov
6cdef8994b wifi: correct number of retries 2021-04-12 01:42:29 +03:00
Maxim Prokhorov
22fbfbb6eb wifi: cannot depend on the sleep value 2021-04-07 03:53:40 +03:00
Maxim Prokhorov
7ea735548b debug: rework boot info and terminal commands
- reduce info lines on boot
- more compact `info` command. show versions, modules and crash info when there is one
- add `storage` command to display flash layout (experimental)
- display full chip id aka MAC, including the oui
- fix telnet never printing the crash data b/c telnet in not yet authorized
- fix eeprom size not reflecting the space used by the backup sectors
- use static flash strings when possible for the fw info
2021-04-07 03:53:40 +03:00
Maxim Prokhorov
612e22c992 wifi: avoid getting stuck in the WaitConnected state
Perform actual checks in the connect() method.
Make sure empty SSID, too-big SSID, too-small or too-big passphrases fail it and force a retry.
Fixes the comment that claimed the WiFi.begin() result was checked...

Local copy of the ::begin, since it is easier to work with the SDK API directly.
2021-04-03 20:34:34 +03:00