Commit Graph

36 Commits

Author SHA1 Message Date
Maxim Prokhorov
ffd23d095b web: print api in namespace
also fixing leftover API dependency issues
2023-04-13 17:34:01 +03:00
Maxim Prokhorov
504bda8299 web: always export arduinojson overrides 2022-10-27 00:55:55 +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
574fbf1960 uart: standalone configuration
- setup uart at boot instead of delaying until some module needs it
  removes global `SERIAL_BAUDRATE` and `DEBUG_PORT` in favour or
  globally accessible numbered port configurations with `MODULE_NAME_PORT`
- automagically enable uart support for sensors that need it
- allow every sensor to configure uart0 (normal and swapped), uart1
  and an optional software-serial mode support with an extra build flag
  remove individual includes across the sensors
- settings queries and runtime port configuration (prefixed with uart)
- update dependencies header to cross-reference used ports at build time
- update deprecations header with serial baudrate notice
2022-09-25 08:26:22 +03:00
Maxim Prokhorov
d32c4b45d0 web: json adapter for our string view
effectively, same thing as `const __FlashStringHelper*`
but, we know the actual size at build time vs. calling `strlen_P`

can't specialize the way things are read until v6; current implemenation
simply attaches arbitrary char pointer to the internal buffer, which is
then read byte-by-byte when writing output json stream

revert to static json buffer class in `/discovery`
will move more things to it, but probably should move to v6 first
2022-09-21 04:21:23 +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
befa961a8e web: strict check for ap connection
also fix invalid header accessor, toString() returns the whole HTTP
request string as `Host: blabla\r\n`
2022-08-21 18:16:41 +03:00
Maxim Prokhorov
567b9d7769 web: also check for ap state 2022-06-01 22:20:25 +03:00
Maxim Prokhorov
2c728074f9 web: image length is a compile time constant 2022-06-01 21:52:18 +03:00
Maxim Prokhorov
ef15c20c04 web: more experiments with captive portal
fixing redirect, authenticate softap connection implicitly
further support needs DHCP helper, at least that's a standard...

plus, pass F(...) strings where String is accepted by the server
2022-06-01 20:14:39 +03:00
Maxim Prokhorov
3d9fbf0469 web: some captive portal pages 2022-06-01 18:33:25 +03:00
Maxim Prokhorov
d4c18a6f52 web: would be a clang warning 2022-02-09 16:00:41 +03:00
Maxim Prokhorov
19963fb8ce system: some unused params 2021-12-18 23:47:20 +03:00
Maxim Prokhorov
f44aab5fdb system: simple deferred reset function
No need for specific delay for each instance, just use a shared one
2021-12-09 01:15:11 +03:00
Maxim Prokhorov
0f34261fab web: use internal millis() call 2021-12-08 13:48:44 +03:00
Maxim Prokhorov
16960067d8 system: some refactoring
There's no need to move a temporary which is already an rvalue

Clean-up some redundant attributes and function in settings.
Make sure C types are proxied to fixed-sized ones, not the other way around.

Clean-up webprint implementation
- use typed duration for the backlog
- don't duplicate members and types for config, just re-use the struct as-is
- don't go over-the-top with const members, just proxy through a method
2021-12-08 13:48:40 +03:00
Maxim Prokhorov
0b64bd0229 core: minimize espurna.h use in headers 2021-10-20 13:07:34 +03:00
Maxim Prokhorov
6eaf88c69b utils: normalize hostname setting usage 2021-10-20 11:38:07 +03:00
Maxim Prokhorov
453157c5db all: more static symbols 2021-08-07 16:49:07 +03:00
Maxim Prokhorov
1600fcc133 settings: hide kv_store from the public header
More concise foreach, generic template code also no longer expands down to ::_read_kv
Also helps with needless inlining happening with recent gcc versions
2021-06-18 17:27:49 +03:00
Maxim Prokhorov
7362eeb8d6 web: dynamic buffer for the config response 2021-04-07 22:56:24 +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
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
c4f0ceb1ae sys: refactor custom reset codes 2021-01-23 21:28:01 +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
9f24e6a325 terminal: make sure API is loaded after the web server
New apiRegister depends on `webServer()` returning a valid object.
2020-12-05 20:32:28 +03:00
Max Prokhorov
8e80a7786c api: rework plain and JSON implementations (#2405)
- match paths through a custom AsyncWebHandler instead of using generic not-found fallback handler
- allow MQTT-like patterns when registering paths (`simple/path`, `path/+/something`, `path/#`)
Replaces `relay/0`, `relay/1` etc. with `relay/+`. Magnitudes are plain paths, but using `/+` in case there's more than 1 magnitude of the same type.
- restore `std::function` as callback container (no more single-byte arg nonsense). Still, limit to 1 type per handler type
- adds JSON handlers which will receive JsonObject root as both input and output. Same logic as plain - GET returns resource data, PUT updates it.
- breaking change to `apiAuthenticate(request)`, it no longer will do `request->send(403)` and expect this to be handled externally.
- allow `Api-Key` header containing the key, works for both GET & PUT plain requests. The only way to set apikey for JSON.
- add `ApiRequest::param` to retrieve both GET and PUT params (aka args), remove ApiBuffer
- remove `API_BUFFER_SIZE`. Allow custom form-data key=value pairs for requests, allow to send basic `String`.
- add `API_JSON_BUFFER_SIZE` for the JSON buffer (both input and output)
- `/apis` replaced with `/api/list`, no longer uses custom handler and is an `apiRegister` callback
- `/api/rpc` custom handler replaced with an `apiRegister` callback

WIP further down:
- no more `webLog` for API requests, unless `webAccessLog` / `WEB_ACCESS_LOG` is set to `1`. This also needs to happen to the other handlers. 
- migrate to ArduinoJson v6, since it become apparent it is actually a good upgrade :)
- actually make use of JSON endpoints more, right now it's just existing GET for sensors and relays
- fork ESPAsyncWebServer to cleanup path parsing and temporary objects attached to the request (also, fix things a lot of things based on PRs there...)
2020-12-05 14:14:38 +03:00
Max Prokhorov
a496308d97 web: prometheus metrics support (#2332)
- (experimental) provide generic way to read magnitude values
- expose /api/metrics with values formatted specifically for prometheus, with relay and sensor data
- small tweaks to sensor init

Example config:
```
scrape_configs:
  - job_name: 'espurna'
    metrics_path: '/api/metrics'
    params:
      apikey: ['apikeyapikey']
    static_configs:
      - targets: ['espurna-blabla.lan:80']
```
Where ESPurna side has
```
apiKey => "apikeyapikey"
apiEnabled => "1"
```
2020-08-30 15:26:16 +03:00
Maxim Prokhorov
3d7449c202 Include library headers in .cpp 2020-07-16 05:27:42 +03:00
Max Prokhorov
3145e8be24 Rework settings (#2282)
* wip based on early draft. todo benchmarking

* fixup eraser, assume keys are unique

* fix cursor copy, test removal at random

* small benchmark via permutations. todo lambdas and novirtual

* fix empty condition / reset

* overwrite optimizations, fix move offsets overflows

* ...erase using 0xff instead of 0

* test the theory with code, different length kv were bugged

* try to check for out-of-bounds writes / reads

* style

* trying to fix mover again

* clarify length, defend against reading len on edge

* fix uncommited rewind change

* prove space assumptions

* more concise traces, fix move condition (agrh!!!)

* slightly more internal knowledge (estimates API?)

* make sure cursor is only valid within the range

* ensure 0 does not blow things

* go back up

* cursor comments

* comments

* rewrite writes through cursor

* in del too

* estimate kv storage requirements, return available size

* move raw erase / move into a method, allow ::set to avoid scanning storage twice

* refactor naming, use in code

* amend storage slicing test

* fix crash handler offsets, cleanup configuration

* start -> begin

* eeprom readiness

* dependencies

* unused

* SPI_FLASH constants for older Core

* vtables -> templates

* less include dependencies

* gcov help, move estimate outside of the class

* writer position can never match, use begin + offset

* tweak save_crash to trigger only once in a serious crash

* doh, header function should be inline

* foreach api, tweak structs for public api

* use test helper class

* when not using foreach, move cursor reset closer to the loop using read_kv

* coverage comments, fix typo in tests decltype

* ensure set() does not break with offset

* make codacy happy again
2020-07-03 22:07:48 +03:00
Max Prokhorov
b8fc8cd1fd Terminal: change command-line parser (#2247)
Change the underlying command line handling:
- switch to a custom parser, inspired by redis / sds
- update terminalRegisterCommand signature, pass only bare minimum
- clean-up `help` & `commands`. update settings `set`, `get` and `del`
- allow our custom test suite to run command-line tests
- clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`)
- send parsing errors to the debug log

As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT`
- MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API.
- Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS.

Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :)
Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
2020-05-25 23:41:37 +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
edb23dbfc4 Convert .ino -> .cpp (#2228)
- general conversion from .ino modules into a separate .cpp files
- clean-up internal headers, place libraries into .h. guard .cpp with _SUPPORT flags 
- fix some instances of shared variables instead of public methods
- tweak build system to still build a single source file via os environment variable ESPURNA_BUILD_SINGLE_SOURCE
2020-04-30 13:55:07 +03:00