Commit Graph

70 Commits

Author SHA1 Message Date
Maxim Prokhorov
9211dcd785 system: lock reent object in ctor 2023-01-18 06:14:34 +03:00
Maxim Prokhorov
312c3ef2ba test: bump esp8266 version used for unit tests 2022-12-12 15:13:25 +03:00
Maxim Prokhorov
24c3ff8954 test: arduinojson header 2022-12-12 14:29:22 +03:00
Maxim Prokhorov
e53e25c8bb test: utils 2022-12-12 14:25:01 +03:00
Maxim Prokhorov
74ad71bf74 tests: fix device-only macro 2022-10-23 05:45:42 +03:00
Maxim Prokhorov
639b558100 settings: raw erase fixes
solves edge-case when we move our storage nearby a previously erased kv,
causing it to be treated as a key or a value with length 255 (... 0x00 0xff)

also stop set() from erasing data when it is not possible to store it in
the first place

additional test case similar to permutations one, make sure keys don't
disappear while we write to the storage a lot of times and possibly
introduce the two cases above
2022-10-23 03:18:57 +03:00
Maxim Prokhorov
a11942fd7b mqtt: string views in API and internal callbacks
* stateless callbacks for mqttRegister. no module uses the lambda / std
  func with captures or otherwise, so it is kind of pointless to have it
* make sure we know topic and payload length at all invocations and
  not constantly trying to re-parse the same string over and over again
* clean-up api related to string parsing and make sure we allow
  stringview as input
* clean-up id / unsigned number parsing to work with views instead of
  using a generic strto{,u}l; sometimes this works, sometimes doesn't.
  as noticed previously with IR implementation, it *will* parse until
  the '\0' is found in the input and we can't interpret parts of the
  string without doing a copy for the strtoul
* fixing additional bugs caught in ifan, leds, sensors and lights that
  were causing build failures. plus, more range-based parsing code for
  the same reason as described above
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
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
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
7fc8ccdf72 system: fix view comparison
note that it is equality, not byte comparison based on
memcmp or strcmp return values
2022-09-21 04:31:20 +03:00
Maxim Prokhorov
5bc55cd1a5 hw: core -> minimal 2022-09-21 04:21:23 +03:00
Maxim Prokhorov
677f368cfa test: bump esp8266 version used for unit tests 2022-09-08 13:39:26 +03:00
Maxim Prokhorov
5f67212935 test: generate compile_commands.json 2022-09-08 13:39:26 +03:00
Maxim Prokhorov
2a5756e1b5 terminal: fix escaped characters parsing
also fix test entry incorrectly using an already escaped string
2022-09-08 13:39:26 +03:00
Maxim Prokhorov
ef202109e7 terminal: remove shared output
Make every available call site 'private'
e.g. typing command in telnet no longer prints to serial or WebUI

Serial input is now optional, see `TERMINAL_SERIAL_SUPPORT`.
Telnet using async server is a proper Print implementation now.
WebUI, MQTT and HTTP input is allowed to inject multiple lines at once.

Modernize our helper classes and remove legacy 2.3.0 quirks.
Replace global Terminal object and allow to separately
split, parse ARGV list and perform command search and invocation with
standalone function calls.
(but, notice that we still depend on a globally shared 'commands' list)

This greatly reduces used RAM (but, slightly increases our ROM).

Update our test suite to use namespaces and new calling convention.
2022-09-08 13:39:11 +03:00
Maxim Prokhorov
ff19c0889d test: fix namespaces 2022-08-29 06:01:21 +03:00
hamed
660d8c339b sns: add INA219 (current / power monitor)
resolves #2501

Co-Authored-by: Maxim Prokhorov <prokhorov.max@outlook.com>
2022-05-18 21:22:32 +03:00
Maxim Prokhorov
c04cdff200 sns: build flag for dummy sensor 2022-05-06 18:56:54 +03:00
Xose Pérez
1c9553176d hw: add support for PM1006 (IKEA Vindriktning) (#2505)
IKEA Vindriktning Air Quality Sensor
https://www.ikea.com/gb/en/p/vindriktning-air-quality-sensor-80515910/
2022-05-06 14:37:49 +03:00
Maxim Prokhorov
456d1cc586 ci: reference dump() method for the settings storage 2022-02-11 13:53:34 +03:00
Maxim Prokhorov
c37bbb42a6 ci: make sure ctest prints it's failures 2022-02-11 13:53:05 +03:00
Maxim Prokhorov
eaa2e370eb ci: use esp8266 mock framework
Resolve the issue with the UnixHostDuino not really being compatible
with the esp8266 Core String (...and the rest of the Core, as well)

Port the CMakeLists.txt from the rpnlib and update it use FetchContent
instead of either manually fetching dependencies or using PIO artifacts
Caching is *expected* to work, but might need slight adjustments
2022-01-13 04:04:37 +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
a0e090489b terminal: get rid of ctx.argc
No need to duplicate argv::size()
2021-12-08 17:42:12 +03:00
Maxim Prokhorov
c95ea71c18 core: clean-up const(expr) qualifiers 2021-10-24 15:30:04 +03:00
Maxim Prokhorov
001ec79c8e ir: clean-up and refactoring of the existing module
- provide a queue for the outgoing messages, don't depend on the MQTT
  callback implementation details and always postpone the actual transfer.
- generate user input parsers using re2c, adds special PlatformIO build handlers
- add terminal command to show GPIO info and send a simple payload
- rework button<->action presets into value<->terminal command presets and custom ones
  through the use of `irCmd<VALUE>` settings, where the VALUE is taken from the simple payload
  (yet, it does not understand repeated codes, but that's something to add later *or* use rpnlib)
- add tx message integration for the relay module via `irRelayOn#` and `irRelayOff#`
- rework simple payload to include 'repeats' value for the 'IRsend::send()'
  also adds internal 'series', 'delay' and includes full 64bit 'value'
  (as uppercase HEX, instead of decimal)
- rework raw payload to use 'series' instead of 'repeats', and provide a
  clear distinction between the usec time and the options of the message
  by moving the required options to the front and separating them using ':'
  (just like the simple variant)
- make RX and TX pin a runtime setting, make RX and TX support a build flag
- small test framework to check whether internal string encode<->decode works

Also updates the hexEncode & hexDecode implementations to use
'iterators' instead of just pointer + index.
2021-10-03 20:44:58 +03:00
Maxim Prokhorov
f748b6487c test: also check for small core webui 2021-09-03 15:23:19 +03:00
Maxim Prokhorov
921bf08483 settings: no need to test ::keys() 2021-08-12 10:49:09 +03:00
Maxim Prokhorov
c34acf1748 ci: latest Core and split webui test into a separate job 2021-06-20 17:25:20 +03:00
Xose Pérez
bb7ffe9b3c sensor: add support for SmartMeasure SM300D2-VO2 air quality multi-sensor (#2447)
* Support for SmartMeasure SM300D2-VO2 air quality multi-sensor

* Fix temperature sign, using hexDecode

* Update README.md
2021-05-12 16:24:59 +03:00
Maxim Prokhorov
4d8dc5d2a6 system: finish up cleaning broker code 2021-03-31 09:41:05 +03:00
Maxim Prokhorov
ec220b7dd1 settings: clean-up helper classes & functions
Move inline classes into a separate file.
Make serialize() into a basic function, support numeric conversions with base option
Refactor numeric conversions and add some more helper functions for the
build flags.
2021-03-31 09:41:04 +03:00
Maxim Prokhorov
7434ea3878 lights: finish up provider settings
get rid of LIGHT_CHANNELS, but keep channel setting for the my92xx
also clean up recent changes, channel command did not actually work
2021-02-10 20:05:13 +03:00
Maxim Prokhorov
34d63c155d lights: refactor my92xx mapping build flags 2021-02-06 04:44:25 +03:00
Maxim Prokhorov
e50b6fe79a mdns: clean-up 2021-01-24 03:38:02 +03:00
Maxim Prokhorov
a40eca30ad ifan: refactor into a separate module 2021-01-14 14:10:45 +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
15e3806b28 libs: renormalize line endings
Garland merge updated .gitattributes, fixup the difference before
merging anything else :>
2020-12-30 21:49:17 +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
e6dc5051ba test: update terminal strings 2020-12-05 22:03:32 +03:00
Maxim Prokhorov
63b6f46752 Fix superfluous whitespaces and line endings
resolve #2310
2020-09-30 10:14:25 +03:00
Max Prokhorov
c7a95bf53f buttons: resistor ladder / analog buttons support (#2357)
- Buttons events source as button property instead of a global one
- Rename events source -> provider for all settings, consistent with the other things like relay and light providers
- AnalogPin to read between a certain analogRead() range
Trying to follow defaults here - analog 'press' is digital LOW, default value is HIGH, so no additional cfg entries are needed besides pin, level and changing evt source
- (debug) Refactor gpio command, add adc to show analogRead(pin)
- (debug) Add button command

Implemented based on:
https://gitter.im/tinkerman-cat/espurna?at=5f5d44c8df4af236f902e25d
https://gitter.im/tinkerman-cat/espurna?at=5f60e7f1f969413294e95370
2020-09-24 07:51:36 +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
f890a06fc5 rfb refactoring
- RF_... -> RFB_...
- rework rcswitch integration, support variable length payload
- rework rfbridge parser (not tested)
- rework settings scanning routine when trying to match rf payload
  with the relay ID
- update build tests
2020-08-23 11:48:50 +03:00
Rui Marinho
6266930a4d sns: Add BME680 (#2295)
Add support for BME680 using libalgobsec proprietary algorithms for precise Indoor Air Quality (IAQ) measurement. Unlike traditional CO2 sensors - and good ones are expensive - it measures nearly all VOCs compounds in the air (plus other gases) and compensates those measurements with its built-in temperature and humidity sensors to determine indoor air quality.

Co-authored-by: Max Prokhorov <prokhorov.max@outlook.com>
2020-08-02 09:12:38 +03:00
Maxim Prokhorov
a2e0d243cb settings: internal storage fixes
- revert unintended change to include 2 bytes as part of empty value
  fixes compatibility with old versions including Embedis and having empty values
- overwrite now empty space when moving
- re-shuffle internal logic to be more strict with cursor oob read / writes
- update comments
2020-07-16 05:27:42 +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
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