Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Willow Application Server #211

Merged
merged 132 commits into from
Aug 17, 2023
Merged

Willow Application Server #211

merged 132 commits into from
Aug 17, 2023

Commits on Aug 16, 2023

  1. main: increase TWDT timeout to 30s for multinet

    We keep hitting Task Watchdog Timer timeouts when running multinet.
    Let's increase the TWDT timeout to 30s when using multinet.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    a6521c6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1243a88 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d487b2c View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b7249c3 View commit details
    Browse the repository at this point in the history
  5. network: set hostname based on MAC address

    This is rather ugly, as we need a valid esp_netif_t pointer to set the
    hostname, but we only get this after starting the Wi-Fi peripheral.
    We also need to set the hostname before the Wi-Fi is connected,
    otherwise the hostname from sdkconfig will be used.
    
    There is a chance that Wi-Fi connects before we can set the hostname,
    but it's probably very small. We could check if the Wi-Fi peripheral is
    connected before setting the hostname, and disconnect it, set the
    hostname, and then reconnect, but this is even uglier.
    
    We can probably improve this by not using ESP-ADF's Wi-Fi peripheral,
    but that would require a lot of new code.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    e5c37ca View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    a3fe733 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    491d4ab View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    cac31c4 View commit details
    Browse the repository at this point in the history
  9. config: parse config with cJSON

    And print parsed config.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    51faba0 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    8b4d786 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    57bd525 View commit details
    Browse the repository at this point in the history
  12. was: add function to request config

    If there is no config file on the flash, we want to request it from WAS
    during boot. Add a function for that and call it if config_read returns
    NULL.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    b3d3323 View commit details
    Browse the repository at this point in the history
  13. main: parse config early

    If we want to use config values from the config file, we need to parse
    it early. Parse it after initializing the display, SPIFFS, and UI.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    d3fb7d4 View commit details
    Browse the repository at this point in the history
  14. config: request config after Wi-Fi and WAS init

    Requesting config before causes a crash.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    34aef36 View commit details
    Browse the repository at this point in the history
  15. was: reinit WebSocket client when closed

    It appears the WebSocket client does not automatically reconnect after
    WEBSOCKET_EVENT_CLOSED.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    016bd5c View commit details
    Browse the repository at this point in the history
  16. config: add config_get functions for types we use

    For this we need to make the cJSON pointer a global variable.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    7e8ddaa View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    19cc6b9 View commit details
    Browse the repository at this point in the history
  18. treewide: use config_get_char for SR mode

    And parse config before initializing UI for a correct startup message.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    4466c0b View commit details
    Browse the repository at this point in the history
  19. treewide: use config_get_char for audio response type

    And drop the conditional in hdl_ev_hs. The function pointer will point
    to noop() if audio response type is none.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    023306c View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    b774160 View commit details
    Browse the repository at this point in the history
  21. hass: use config_get

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    ee71c77 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    9f0efd0 View commit details
    Browse the repository at this point in the history
  23. openhab: use config_get

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    f96f8c1 View commit details
    Browse the repository at this point in the history
  24. rest: use config_get

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    f7e6585 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    34143d1 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    50eab5d View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    76f12a1 View commit details
    Browse the repository at this point in the history
  28. was: add deinit function

    Add a deinit function to avoid WebSocket client errors when calling
    esp_restart to reload config or finish OTA.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    be63741 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    a80f2d0 View commit details
    Browse the repository at this point in the history
  30. shared: move timer variables to timer.h

    In new source files we're defining a different TAG variable instead of
    using the one from shared.h. This causes redefinition errors if we
    include shared.h.
    
    Move timer variables to timer.h so we don't need to include shared.h to
    be able to control timers.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    212187f View commit details
    Browse the repository at this point in the history
  31. ota: add OTA support

    Once you've done an OTA and use `./utils.sh flash`, you might still boot
    from ota_1 partition so you will not boot what you just flashed. This
    can lead to serious WTF moments. You can use otatool to force the boot
    partition to ota_0.
    
    otatool.py switch_ota_partition --slot 0
    
    Unfortunately esptool does not support that, and otatool is part of
    ESP-IDF, so this should be done in the container and we need to pass the
    device node to the container again.
    
    As we enabled app rollback in the bootloader, a full flash is required.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    ebb85b8 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    47d61c0 View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    8e6efc9 View commit details
    Browse the repository at this point in the history
  34. main: read Wi-Fi credentials from NVS

    Add a state enum to track where we are in the boot phase. When we fail
    to read the Wi-Fi credentials from NVS, we skip connecting to Wi-Fi and
    WAS, and wait forever.
    
    As of this commit, the NVS partition will need to have a namezone "WIFI"
    with 2 keys "PSK" and "SSID", or you will no longer be able to connected
    to Wi-Fi.
    
    NVS partition can be generated with the instructions in NOTES.md, or on
    https://www.linux-ipv6.be/esp-nvs/ (temp URL).
    
    The resulting NVS partition can then be flashed with this command:
    esptool.py --port /dev/ttyACM0 write_flash 0x9000 ~/tmp/nvs.bin
    
    Alternatively, you can use https://espressif.github.io/esptool-js/.
    Make sure to set the offset to 0x9000.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    eb7c05f View commit details
    Browse the repository at this point in the history
  35. Support generating NVS partition with build wifi configuration and me…

    …rging nvs into full firmware image
    kristiankielhofner authored and stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    9864adb View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    4c236f6 View commit details
    Browse the repository at this point in the history
  37. treewide: use 5 lines instead of repositioning

    We're currently repositioning line 3 to print stuff in the middle of the
    screen. This requires us to keep track of when we have to reposition it
    again. To make our lives easier, just use 5 lines instead and use line 3
    for things that go in the middle.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    97d6998 View commit details
    Browse the repository at this point in the history
  38. system: add delayed restart function

    Right now we instantly restart after a config or OTA update. Add a
    delayed restart function so we can print a message on the display and
    give the user time to actually see it.
    
    And use it in config and ota.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    321b797 View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    8dca591 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    6f86ddf View commit details
    Browse the repository at this point in the history
  41. main: get WAS URL from NVS

    Aside from Wi-Fi credentials, having the WAS URL is also a hard
    requirement. Include the WAS URL in NVS and read it from there in main.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    3683102 View commit details
    Browse the repository at this point in the history
  42. treewide: set TAG per source file

    Currently setting a TAG in source files that include shared.h we get
    redefintion errors. Solve this removing TAG from shared.h and setting a
    TAG per source file where ESP_LOG macros are used.
    
    As esp_log_level_set only supports "*" but not "WILLOW/*", we need to
    set the log level for all these tags. To not further bloat main.c with
    all these calls, move logging initialization to log.c.
    
    Oneliner to generate the calls:
    
    git grep "static const char" | awk '{ print $6 }' | sed 's/;$//' | sort | while read f ; do printf "    esp_log_level_set(%s, WILLOW_LOG_LEVEL);\n" "$f"; done
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    fc475c5 View commit details
    Browse the repository at this point in the history
  43. endpoint/hass: handle more WebSocket events

    While working on WAS it turned out the ESP WebSocket client does not
    reconnect when the WebSocket connection is being closed. Improve the HA
    WebSocket event handling to reconnect when the WebSocket connection is
    closed, and to avoid logging useless messages like this:
    
    I (01:39:19.220) WILLOW/HASS: WS event ID: 1
    I (01:39:29.223) WILLOW/HASS: WS event ID: 4
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    cea0970 View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    486c1cb View commit details
    Browse the repository at this point in the history
  45. Set Willow colors

    kristiankielhofner authored and stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    e8f6169 View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    eb94b61 View commit details
    Browse the repository at this point in the history
  47. Configuration menu
    Copy the full SHA
    8e52170 View commit details
    Browse the repository at this point in the history
  48. Configuration menu
    Copy the full SHA
    c45ca22 View commit details
    Browse the repository at this point in the history
  49. audio: add a deinit_audio function

    And call it before starting OTA.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    235e8ab View commit details
    Browse the repository at this point in the history
  50. endpoint/hass: add a deinit_hass function

    And call it before starting OTA.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    80f79bf View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    5ffa30b View commit details
    Browse the repository at this point in the history
  52. Configuration menu
    Copy the full SHA
    00f5edc View commit details
    Browse the repository at this point in the history
  53. Configuration menu
    Copy the full SHA
    87c57a3 View commit details
    Browse the repository at this point in the history
  54. Configuration menu
    Copy the full SHA
    613584d View commit details
    Browse the repository at this point in the history
  55. Configuration menu
    Copy the full SHA
    fbbc7b4 View commit details
    Browse the repository at this point in the history
  56. Configuration menu
    Copy the full SHA
    8c119f8 View commit details
    Browse the repository at this point in the history
  57. Configuration menu
    Copy the full SHA
    5e20228 View commit details
    Browse the repository at this point in the history
  58. Configuration menu
    Copy the full SHA
    94d3914 View commit details
    Browse the repository at this point in the history
  59. Always print version

    kristiankielhofner authored and stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    4bee33f View commit details
    Browse the repository at this point in the history
  60. Add WAV files for TT

    kristiankielhofner authored and stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    32fc36d View commit details
    Browse the repository at this point in the history
  61. Configuration menu
    Copy the full SHA
    448946f View commit details
    Browse the repository at this point in the history
  62. display: use config_get_int for display brightness

    For this to work we need to move display initialization to run after
    loading the config from SPIFFS.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    67ea078 View commit details
    Browse the repository at this point in the history
  63. Configuration menu
    Copy the full SHA
    0f3797a View commit details
    Browse the repository at this point in the history
  64. audio: add null checks in deinit_audio

    If a device has no config, we don't setup any audio. The device will ask
    WAS for a config, WAS calls deinit_audio, and we get a null pointer
    dereference. Add null checks to avoid this.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    e01c0c5 View commit details
    Browse the repository at this point in the history
  65. was: handle NVS message

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    e06ac04 View commit details
    Browse the repository at this point in the history
  66. main: wait indefinitely after requesting config

    If we're requesting a config from WAS it means we don't have a valid
    config. Continuing after requesting the config doesn't make sense, as it
    will cause a lot of errors. Since we're restarting after receiving the
    config from WAS anyway, let's just wait indefinitely in the main task
    after requesting config from WAS.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    902ef2f View commit details
    Browse the repository at this point in the history
  67. audio: check mute status during boot

    When booting with mute enabled, audio_board_init failes, and throws a
    whole lot of errors before it does. Check mute status before calling
    audio_board_init. If mute is enabled, print a message on the display to
    inform the user to unmute to continue, and check the GPIO status in a
    loop until the user unmutes, then continue boot.
    
    Fixes #192.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    d70e56b View commit details
    Browse the repository at this point in the history
  68. ui: add ui_pr_err function

    And use it where appropriate. This is an initial attempt to reduce the
    various lvgl calls all over the place.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    47dcbf2 View commit details
    Browse the repository at this point in the history
  69. Configuration menu
    Copy the full SHA
    a8c36dc View commit details
    Browse the repository at this point in the history
  70. shared: move state to system

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    9207132 View commit details
    Browse the repository at this point in the history
  71. shared: drop unused include

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    eddaae5 View commit details
    Browse the repository at this point in the history
  72. Configuration menu
    Copy the full SHA
    9e73222 View commit details
    Browse the repository at this point in the history
  73. Configuration menu
    Copy the full SHA
    842486a View commit details
    Browse the repository at this point in the history
  74. utils.sh: use willow branch from our ESP-ADF fork

    Instead of maintaining and applying patches for ESP-ADF in the Willow
    repository we will clone ESP-ADF from our fork. The willow branch has
    our required changes.
    
    We are in the process of submitting those changes upstream, but until
    we've done so, and all changes are accepted, this is a much cleaner way
    of maintaining and using our ESP-ADF changes.
    
    Drop the patches directory and do_patch function since we no longer
    need them.
    
    This will require build-docker and ./utils.sh destroy.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    fb949d2 View commit details
    Browse the repository at this point in the history
  75. Configuration menu
    Copy the full SHA
    ff020d9 View commit details
    Browse the repository at this point in the history
  76. speech_commands: get multinet commands from WAS

    We now have an experiment multinet command editor in WAS. It can pull
    entities from HA, generate commands for those entities, with the option
    to add/modify/delete them.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    89fff5a View commit details
    Browse the repository at this point in the history
  77. utils.sh: improve automatic git version

    On tagged commit, this will use the tag. We also don't need to manually
    append the -dirty tag.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    7b3b496 View commit details
    Browse the repository at this point in the history
  78. CI: don't generate speech commands

    This needs work; we need to cleanly disable MultiNet everywhere, and
    ideally print an error message that MultiNet is not supported with
    release images for now.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    ebcd913 View commit details
    Browse the repository at this point in the history
  79. CI: build and push willow-build container

    This will be used to build and publish Willow images.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    74a9e79 View commit details
    Browse the repository at this point in the history
  80. CI: build Willow dist

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    2281d8d View commit details
    Browse the repository at this point in the history
  81. CI: publish release on tag

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    cc20db8 View commit details
    Browse the repository at this point in the history
  82. CI: always build container

    Ideally we would only build a container when there are changes to the
    Dockerfile or the workflow config that builds the container.
    Unfortunately GH actions is so incredibly inflexbile that this seems
    impossible.
    
    As we need to have a build container with a tag corresponding to the git
    branch or tag, when we create a new branch or tag, we need to build the
    container first, before we can start the dist build. But the
    documentation for the push event states this:
    
    > If you use both the branches filter and the paths filter, the workflow will only run when both filters are satisfied.
    
    It doesn't mention anything about "OR".
    
    So to not further lose time with GH actions, just build the container
    anyway. It's a shame this is so needlessly complex that people have to
    resort to workaround that waste CPU cycles.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    d8bbf2d View commit details
    Browse the repository at this point in the history
  83. CI: use single workflow

    As it seems to be completely impossible to add any kind of usable
    dependency between different workflows, let's move everything to a
    single workflow instead.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    17af6b2 View commit details
    Browse the repository at this point in the history
  84. CI: fix breakage on duplicate container image tags

    With the default configuration, the docker/metadata-action uses multiple
    tags, in the following order:
    
      type=schedule
      type=ref,event=branch
      type=ref,event=tag
      type=ref,event=pr
    
    We don't use schedule, and when we build for a tag, we want to use the
    git tag rather than the branch name as container image tag first, so we
    can use index 0 of the tags array to later select which container image
    we use to do the Willow dist build.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    6c744f7 View commit details
    Browse the repository at this point in the history
  85. CI: don't unzip artifact

    Apparently the artifact is unzipped by the download action.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    655a283 View commit details
    Browse the repository at this point in the history
  86. CI: add /willow to git safe directories

    Even though we run things as root inside the container and /willow is
    owned by root, we get the following error:
    
    fatal: detected dubious ownership in repository at '/willow'
    To add an exception for this directory, call:
    
    	git config --global --add safe.directory /willow
    
    Most likely because of this, we get an empty Willow verion:
    
      Willow build version:
    
    Add /willow to the safe directories to fix this.
    
    Ideally we should not run as root, but that's something to optimize
    later.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    6acd811 View commit details
    Browse the repository at this point in the history
  87. CI: run on pull_request and push with tag

    Running on push was to test during development. Switch to run on pull
    request, and on push with tag now that we're almost ready for merge.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    d67c242 View commit details
    Browse the repository at this point in the history
  88. ota: update screen before deinit and OTA

    Also add a short delay before starting OTA, to let deinit settle down.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    7c05bff View commit details
    Browse the repository at this point in the history
  89. Configuration menu
    Copy the full SHA
    fa1f6ab View commit details
    Browse the repository at this point in the history
  90. Configuration menu
    Copy the full SHA
    943c61d View commit details
    Browse the repository at this point in the history
  91. Configuration menu
    Copy the full SHA
    c10b1ab View commit details
    Browse the repository at this point in the history
  92. Configuration menu
    Copy the full SHA
    40c27b5 View commit details
    Browse the repository at this point in the history
  93. Configuration menu
    Copy the full SHA
    05659a1 View commit details
    Browse the repository at this point in the history
  94. Default config update - use display refresh period of 10ms and use es…

    …p32s3 optimized mem copy/set
    kristiankielhofner authored and stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    98bbe3c View commit details
    Browse the repository at this point in the history
  95. Configuration menu
    Copy the full SHA
    979865c View commit details
    Browse the repository at this point in the history
  96. Configuration menu
    Copy the full SHA
    1b69eef View commit details
    Browse the repository at this point in the history
  97. CI: also publish OTA images

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    2b55c1a View commit details
    Browse the repository at this point in the history
  98. was: add EFUSE mac address to hello message

    While we already have the MAC address in the hostname, this is not very
    flexible. If users want to use custom hostnames, we can no longer get
    the MAC address from it.
    
    As the ESP32 does not have a unique serial number, but it is programmed
    with a unique MAC address at manufacture, the MAC address from the EFUSE
    is the most reliable unique identifier. If we want to keep a persistent
    inventory in WAS, we will need a unique identifier.
    
    Therefore, add the MAC address from the EFUSE in the hello message.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    da5282d View commit details
    Browse the repository at this point in the history
  99. hass: increase WebSocket buffer size

    In commit 2bc77a4 ("hass: increase WebSocket buffer size") we
    increased the WebSocket buffer size to 4096 byte, because responses over
    encrypted WebSocket would be truncated at 4092 byte. While looking into
    this again, it appears this truncation is no longer happening.
    
    Since I'm hitting this 4096 byte limit with the Home Assistant intent
    "how many lights are on?", let's increase this buffer size.
    
    My Home Assistant has 44 light entities, and the WebSocket message
    containing the response to that intent is 4691 byte. As we allocate
    memory in SPIRAM by default, we don't have to worry too much about
    making the buffer too large, but at the same time we shouldn't impact
    performance too much.
    
    Let's settle on a 16384 byte buffer for now.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    665d005 View commit details
    Browse the repository at this point in the history
  100. treewide: improve LVGL locking

    We sometimes hit a deadlock when calling lvgl_port_lock(0). Calling
    lvgl_port_lock with argument 0 will wait indefinitely for the semaphore
    to become available, hence greatly increasing the risk to deadlock.
    
    Limit the time to wait for the LVGL lock to 500ms to avoid deadlocking.
    Since we do not wait indefinitely anymore, there is a change we will not
    be able to get the lock. Hence, we should check the return status of the
    lvgl_port_lock calls, and skip LVGL calls if we don't have the lock.
    
    With this change, we will not update the screen in rare occasions, but
    not locking up is far more important than correctly printing everything
    to the screen.
    
    Finally, move some non-LVGL calls outside of the conditional, to avoid
    not playing an audio response or logging to the console in case we
    cannot get the lock.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    24710d1 View commit details
    Browse the repository at this point in the history
  101. was: add restart command

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    7d35a08 View commit details
    Browse the repository at this point in the history
  102. Configuration menu
    Copy the full SHA
    02f90a4 View commit details
    Browse the repository at this point in the history
  103. Configuration menu
    Copy the full SHA
    99ceff9 View commit details
    Browse the repository at this point in the history
  104. audio: set volume after start_rec

    We set volume to 0 in i2s_stream_cfg_t in start_rec. Move the call to
    set volume to the value in willow.json after the call to start_rec to
    make sure we actually set the volume to the configured value.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    b3dacd2 View commit details
    Browse the repository at this point in the history
  105. audio: add event queue to ESP Audio

    The reason ESP Audio's async play appeared to not play anything is
    because we disable the power amplifier right after the esp_audio_play
    call. As this call immediately returns, we're disabling the PA before
    ESP Audio actually plays the audio.
    
    Add an event queue so we can move disabling the PA out of the play_audio
    functions into an event handler.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    8df4192 View commit details
    Browse the repository at this point in the history
  106. audio: add ESP Audio event callback

    And have it disable the power amplifier for events PAUSED, STOPPED,
    FINISHED and ERROR.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    92ff8bc View commit details
    Browse the repository at this point in the history
  107. Configuration menu
    Copy the full SHA
    ffc10e1 View commit details
    Browse the repository at this point in the history
  108. Configuration menu
    Copy the full SHA
    67be27e View commit details
    Browse the repository at this point in the history
  109. Configuration menu
    Copy the full SHA
    eb7c489 View commit details
    Browse the repository at this point in the history
  110. Configuration menu
    Copy the full SHA
    9d33856 View commit details
    Browse the repository at this point in the history
  111. audio: get LVGL lock before hiding cancel button

    Fixes: dc3f443 ("main: add cancel button")
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    279b8d0 View commit details
    Browse the repository at this point in the history
  112. audio: make recording variable volatile

    We're modifying the recording variable in one task, and we read it in
    another. Make the variable volatile, to be sure we don't read an
    optimized or cached value.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    0c0531f View commit details
    Browse the repository at this point in the history
  113. audio: rework audio recorder event handling

    Don't send STOP on WAKE when we're already recording, just avoid sending
    START again, and let the STOP on WAKE END trigger everything.
    
    Don't stop streaming to WIS when reading from the recorder returns 0.
    This should avoid early cut-off when something can't keep up for some
    reason.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    9e49850 View commit details
    Browse the repository at this point in the history
  114. audio: increase HTTP stream task stack size

    During a torture run with WIS over HTTPS we've seen the following crash:
    
    ***ERROR*** A stack overflow in task http_stream_writer has been detected.
    
    Increase the task stack size to avoid this.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    c1cfea6 View commit details
    Browse the repository at this point in the history
  115. hass: add extra checks in cb_ws_event

    During a torture run with heap poisoning enabled, the following crash
    was observed:
    
    Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
    
    Core  1 register dump:
    PC      : 0x4038abca  PS      : 0x00060033  A0      : 0x8038b847  A1      : 0x3fcc9150
    A2      : 0x3d800014  A3      : 0x0000000c  A4      : 0x3d800038  A5      : 0x3d800274
    A6      : 0x00060023  A7      : 0x00000000  A8      : 0x3d800014  A9      : 0x00000394
    A10     : 0x3d9a28f4  A11     : 0x00000038  A12     : 0xabba1234  A13     : 0x00000003
    A14     : 0x0000001e  A15     : 0x3d80007c  SAR     : 0x0000001f  EXCCAUSE: 0x0000001d
    EXCVADDR: 0xabba1240  LBEG    : 0x400570e8  LEND    : 0x400570f3  LCOUNT  : 0x00000000
    
    /opt/esp/idf/components/heap/heap_tlsf.c:206
    /opt/esp/idf/components/heap/multi_heap.c:187
    /opt/esp/idf/components/heap/multi_heap_poisoning.c:234
    /opt/esp/idf/components/heap/multi_heap_poisoning.c:229
    /opt/esp/idf/components/heap/heap_caps.c:175
    /opt/esp/idf/components/heap/heap_caps.c:239
    /opt/esp/idf/components/newlib/heap.c:24
    /opt/esp/idf/components/json/cJSON/cJSON.c:243
    /opt/esp/idf/components/json/cJSON/cJSON.c:1633
    /opt/esp/idf/components/json/cJSON/cJSON.c:1674
    /opt/esp/idf/components/json/cJSON/cJSON.c:1674
    /opt/esp/idf/components/json/cJSON/cJSON.c:1116
    /opt/esp/idf/components/json/cJSON/cJSON.c:1087
    /opt/esp/idf/components/json/cJSON/cJSON.c:1173
    /willow/main/endpoint/hass.c:58
    /opt/esp/idf/components/esp_event/esp_event.c:145
    /opt/esp/idf/components/esp_websocket_client/esp_websocket_client.c:155
    /opt/esp/idf/components/esp_websocket_client/esp_websocket_client.c:555
    
    Line 59 in hass.c is cJSON_Parse(resp). Let's add a few extra checks to
    make sure we do not call cJSON_Parse on garbage data.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    3a70703 View commit details
    Browse the repository at this point in the history
  116. treewide: disable text LVGL text scrolling

    We're regularly observing LVGL using 100% CPU with scrolling text.
    This seems to cause all kinds of random behaviour. Disable it for now.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    8249106 View commit details
    Browse the repository at this point in the history
  117. sdkconfig: disable mbedTLS hw SHA acceleration

    We've observed the following crash:
    
    Guru Meditation Error: Core  0 panic'ed (Double exception).
    
    Core  0 register dump:
    PC      : 0x4038424a  PS      : 0x00040936  A0      : 0x820e7897  A1      : 0x3d9a74b0
    A2      : 0x00000000  A3      : 0x3d9a74f0  A4      : 0x00000000  A5      : 0x00000000
    A6      : 0x00000000  A7      : 0x00000000  A8      : 0x820ed3f3  A9      : 0x3d9a7490
    A10     : 0x00000003  A11     : 0x3d99ecd4  A12     : 0x00000000  A13     : 0x00000000
    A14     : 0x3d9a74f0  A15     : 0x00000000  SAR     : 0x00000019  EXCCAUSE: 0x00000002
    EXCVADDR: 0xfffffff0  LBEG    : 0x42148bf1  LEND    : 0x42148bfc  LCOUNT  : 0x00000000
    
    Backtrace: 0x40384247:0x3d9a74b0 0x420e7894:0x00000000 |<-CORRUPTED
    
    /opt/esp/tools/xtensa-esp32s3-elf/esp-2021r2-patch5-8.4.0/xtensa-esp32s3-elf/bin/xtensa-esp32s3-elf-addr2line -e build/willow.elf 0x40384247:0x3d9a74b0 0x420e7894:0x00000000
    /opt/esp/idf/components/freertos/port/xtensa/xtensa_context.S:194
    /opt/esp/idf/components/mbedtls/mbedtls/library/md.c:601
    
    On this line, mbedtls_sha512_finish_ret is called. Let's disable SHA
    hardware acceleration, as we're suspecting this causes issues.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    4a6bb8f View commit details
    Browse the repository at this point in the history
  118. hass: increase WebSocket client task stack size

    We've experienced the following crash during boot after disabling SHA
    hardware acceleration:
    
    ***ERROR*** A stack overflow in task websocket_task has been detected.
    
    Increase the task stack size to avoid this.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    31f2b3c View commit details
    Browse the repository at this point in the history
  119. openhab: fix potential NULL pointer dereference

    Found with clang-tidy:
    /willow/main/endpoint/openhab.c:70:9: warning: Null pointer passed as 1st argument to string length function [clang-analyzer-unix.cstring.NullArg]
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    61baad0 View commit details
    Browse the repository at this point in the history
  120. openhab: fix memory leak

    Found with clang-tidy.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    d0319b7 View commit details
    Browse the repository at this point in the history
  121. was: prevent nvs_commit call with uninitialized value

    Found with clang-tidy:
    /willow/main/was.c:104:21: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    fc143c9 View commit details
    Browse the repository at this point in the history
  122. audio: check if CONFIG_TASK_WDT_PANIC is defined

    And define it to the same value used in sdkconfig.willow if it doesn't.
    Fixes the following error running clang-check:
    
    /willow/main/audio.c:655:42: error: use of undeclared identifier 'CONFIG_TASK_WDT_PANIC' [clang-diagnostic-error]
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    4db0cb2 View commit details
    Browse the repository at this point in the history
  123. hass: don't store hass_set_http_auth return value

    Fixes the following clang-tidy warnings:
    /willow/main/endpoint/hass.c:278:5: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]
    /willow/main/endpoint/hass.c:278:5: note: Value stored to 'ret' is never read
    /willow/main/endpoint/hass.c:319:5: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]
    /willow/main/endpoint/hass.c:319:5: note: Value stored to 'ret' is never read
    
    We print an error message in hass_set_http_auth so we don't need to
    print an error message in the callers.
    
    We might consider returning early in the caller when hass_set_http_auth
    returns false, or changing the function to void if we keep the current
    behaviour. Not sure which one would be best, so let's just fix the
    warnings for now.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    70c1470 View commit details
    Browse the repository at this point in the history
  124. display: cast audio_board_lcd_init return value

    The audio_board_lcd_init returns a void pointer so we need to cast it to
    esp_lcd_panel_handle_t.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    9f3f86e View commit details
    Browse the repository at this point in the history
  125. audio: check recording for WAKEUP_START event

    Saying wake word when VAD_END/WAKEUP_END hasn't been trigger yet causes
    multiple session timers to start. Let's do like we do for VAD_START and
    do nothing when we're already recording.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    c8ff9f3 View commit details
    Browse the repository at this point in the history
  126. audio: do not terminate audio pipeline

    Terminating the audio pipeline will destroy the tasks for the elements
    in the pipeline, so the tasks have to be recreated every time we stream
    to WIS. This isn't very efficient, and it doesn't appear to be needed.
    We also suspect this could leak memory, and sometimes causes this error:
    
    E (16:45:01.400) AUDIO_PIPELINE: audio_pipeline_resume failed
    
    After this error, the device is no longer able to stream to WIS.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    60f8a3e View commit details
    Browse the repository at this point in the history
  127. audio: properly deinit audio

    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    260ae64 View commit details
    Browse the repository at this point in the history
  128. audio: use ESP_AUDIO_PREFER_SPEED

    The ESP_AUDIO_PREFER_MEM mode seems to destroy and recreate its element
    tasks on every run. This is not very efficient, and as we have plenty of
    free memory, we can perfectly use the ESP_AUDIO_PREFER_SPEED mode
    instead.
    
    TTS log of 2nd wake before this change:
    
    I (02:13:12.437) WILLOW/AUDIO: Using WIS TTS URL 'https://wis.local:19000/api/tts?format=WAV&speaker=CLB&text=0'
    I (02:13:12.450) AUDIO_PIPELINE: audio_pipeline_unlinked
    W (02:13:12.454) AUDIO_PIPELINE: There are no listener registered
    I (02:13:12.461) AUDIO_PIPELINE: link el->rb, el:0x3d9f7c78, tag:IN_http, rb:0x3db20950
    I (02:13:12.470) AUDIO_PIPELINE: link el->rb, el:0x3d9f8484, tag:DEC_auto, rb:0x3db20988
    I (02:13:12.478) AUDIO_PIPELINE: link el->rb, el:0x3db1968c, tag:Audio_forge, rb:0x3db132cc
    I (02:13:12.488) AUDIO_ELEMENT: [IN_http-0x3d9f7c78] Element task created
    I (02:13:12.495) AUDIO_ELEMENT: [IN_http] AEL_MSG_CMD_RESUME,state:1
    I (02:13:12.503) AUDIO_ELEMENT: [DEC_auto-0x3d9f8484] Element task created
    I (02:13:12.509) AUDIO_ELEMENT: [DEC_auto] AEL_MSG_CMD_RESUME,state:1
    I (02:13:13.285) AUDIO_ELEMENT: [Audio_forge-0x3db1968c] Element task created
    I (02:13:13.285) AUDIO_ELEMENT: [Audio_forge] AEL_MSG_CMD_RESUME,state:1
    I (02:13:13.289) AUDIO_ELEMENT: [OUT_iis-0x3da17d48] Element task created
    I (02:13:13.297) AUDIO_ELEMENT: [OUT_iis] AEL_MSG_CMD_RESUME,state:1
    I (02:13:13.308) AUDIO_ELEMENT: IN-[IN_http] AEL_IO_DONE,0
    I (02:13:13.310) AUDIO_ELEMENT: IN-[DEC_auto] AEL_IO_DONE,-2
    I (02:13:13.785) AUDIO_ELEMENT: IN-[Audio_forge] AEL_IO_DONE,-2
    I (02:13:13.933) AUDIO_ELEMENT: IN-[OUT_iis] AEL_IO_DONE,-2
    I (02:13:14.340) AUDIO_ELEMENT: [http_stream_writer] AEL_MSG_CMD_PAUSE
    
    TTS log of 2nd wake after this change:
    
    I (02:18:19.707) WILLOW/AUDIO: Using WIS TTS URL 'https://wis.local:19000/api/tts?format=WAV&speaker=CLB&text=0'
    I (02:18:19.718) AUDIO_ELEMENT: [IN_http] AEL_MSG_CMD_RESUME,state:1
    I (02:18:19.725) AUDIO_ELEMENT: [DEC_auto] AEL_MSG_CMD_RESUME,state:1
    I (02:18:20.513) AUDIO_ELEMENT: [Audio_forge] AEL_MSG_CMD_RESUME,state:1
    I (02:18:20.514) AUDIO_ELEMENT: [OUT_iis] AEL_MSG_CMD_RESUME,state:1
    I (02:18:20.525) AUDIO_ELEMENT: IN-[IN_http] AEL_IO_DONE,0
    I (02:18:20.526) AUDIO_ELEMENT: IN-[DEC_auto] AEL_IO_DONE,-2
    I (02:18:20.996) AUDIO_ELEMENT: IN-[Audio_forge] AEL_IO_DONE,-2
    I (02:18:21.146) AUDIO_ELEMENT: IN-[OUT_iis] AEL_IO_DONE,-2
    I (02:18:21.616) AUDIO_ELEMENT: [http_stream_writer] AEL_MSG_CMD_PAUSE
    
    This also appears to work around the following observed behavior with
    task heap debugging using esp_dump_per_task_heap_info:
    
    Task: main -> CAP_8BIT: 1392004 CAP_32BIT: 0
    Task: esp_periph -> CAP_8BIT: 25296 CAP_32BIT: 0
    Task: wifi -> CAP_8BIT: 105068 CAP_32BIT: 0
    Task: Pre-Scheduler allocs -> CAP_8BIT: 4068 CAP_32BIT: 0
    Task: ipc0 -> CAP_8BIT: 30028 CAP_32BIT: 0
    Task: tiT -> CAP_8BIT: 2908 CAP_32BIT: 0
    Task: sys_evt -> CAP_8BIT: 100 CAP_32BIT: 0
    Task: websocket_task -> CAP_8BIT: 724 CAP_32BIT: 0
    Task: websocket_task -> CAP_8BIT: 25708 CAP_32BIT: 0
    Task: i2s_stream_read -> CAP_8BIT: 2048 CAP_32BIT: 0
    Task: at_read -> CAP_8BIT: 10584 CAP_32BIT: 0
    Task: feed_task -> CAP_8BIT: 8192 CAP_32BIT: 0
    Task: ipc1 -> CAP_8BIT: 24 CAP_32BIT: 0
    Task: btm_rrm_t -> CAP_8BIT: 100 CAP_32BIT: 0
    Task: esp_timer -> CAP_8BIT: 208 CAP_32BIT: 0
    Task: media_task -> CAP_8BIT: 41456 CAP_32BIT: 0
    Task: recorder_task -> CAP_8BIT: 24 CAP_32BIT: 0
    Task: http_stream_wri -> CAP_8BIT: 4904 CAP_32BIT: 0
    Task: ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
    
    Tasks like the latter would appear randomly, sometimes with a short
    sequence of binary data for task name, but regularly with multiple lines
    (100+) full of it, eventually slowing things down so badly that the TWDT
    triggers a restart.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    a59ed46 View commit details
    Browse the repository at this point in the history
  129. sdkconfig: enable SPIRAM_RODATA and SPIRAM_FETCH_INSTRUCTIONS

    We're still able to lock up the display. When this happens, the audio
    being sent to WIS is often incomplete. Enable SPIRAM_RODATA and
    SPIRAM_FETCH_INSTRUCTIONS to hopefully finally fix this.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    4f1765c View commit details
    Browse the repository at this point in the history
  130. timer: force stop recorder on session timer expiry

    We only stop the audio pipeline to stream to WIS when the session timer
    expires. VAD_END and WAKE_END will potentially trigger afterwards. If
    this happens when a new stream to WIS was already started, all kinds of
    weirdness can occur. Force stop the recorder when the session timer
    expires to avoid this.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    7dae952 View commit details
    Browse the repository at this point in the history
  131. sdkconfig: enable LCD_RGB_ISR_IRAM_SAFE

    We were still able to lock up the display, with both our custom font and
    montserat. Enable LCD_RGB_ISR_IRAM_SAFE to test if this helps.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    95e976b View commit details
    Browse the repository at this point in the history
  132. sdkconfig: disable AES HW acceleration

    During several torture runs, the following error appeared sporadically:
    
    E (23:45:27.704) esp-tls-mbedtls: read error :-0x7180:
    E (23:45:27.705) TRANSPORT_BASE: esp_tls_conn_read error, errno=Success
    
    Disabling AES hardware acceleration seems to fix those.
    stintel committed Aug 16, 2023
    Configuration menu
    Copy the full SHA
    b15610b View commit details
    Browse the repository at this point in the history