Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 21 of 21

Thread: T41 - Homekit mplementation stops after several hours

Threaded View

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    12

    T41 - Homekit mplementation stops after several hours

    Hi all,

    I have a problem with my program and I don’t know how to find the error. I have spend days/weeks finding the error but I have no idea what else to do…

    I have ported my Homekit implementation over to the Teensy 4.1 (with heavy modifications) and it works quite well. Except after a few hours it stops/hangs.

    The code consists of several thousand lines of code, so it is difficult to post the code here. It also uses mbedtls v2.18 and vjmuzik’s NativeEthernet Library, ArduinoJson, TeensyID and a few other libs.

    Additionally to the „normal“ Apple like Homekit, I also implemented something like fakegato to show a graph of the values measured in the past like in the Elgato EVE app. Therefore I use the CircularBuffer library. To get the correct timestamp of each measurement, I use a NTP client and the Timezone library. (Syncing time is every 10 minutes).

    My problem is, if I run the program for several hours, just „measuring“ a dummy BME280 sensor (actually it just generates random numbers) every 5 seconds and stores it as a struct in the CircularBuffer and the buildin LED blinks every second. These values are tied to specific Homekit Accessories, Services and Characteristics which are updated for each measurement.

    There isn’t any other hardware involved except the „LAN Socket Shield“ from PJRC.

    Additionally I write out the free heap, stack and maxstack every second over the Serial. If there would be a memory leak, the free heap value should decrease over time, but it isn’t… The other values are (more or less) constant as well.

    During my tests, there is no connection from clients over network. So all the „heavy“ stuff like SRP and encrypting/decrypting functions aren’t called at all. I do not use the provided Webserver but I have written my own. It will check for new connections each loop.

    I have decreased the „waiting“ times between each measurement (to speed up the things). I would expect, that the program would stop a lot earlier, but it also runs for several hours.

    I tried to avoid Strings and instead switched over to std::string and/or char arrays. The functions called during this tests, don’t use Strings at all.

    I tried several things, like
    • NTP doesn’t seem to have impact, because without NTP it will hang as well
    • I tried to replace all Strings with std::string or char arrays
    • Speed up my program by reducing „waiting“ times (from seconds to 1-2ms)
    • Avoid logging or printing out to Serial
    • Different versions of Teensyduino (1,53 - 1,54 and the Betas)
    • Different compile options like fast, faster and so on
    • changed most of the pointers to smart (shared_ptr) pointers



    But it will still hang/stop after several hours… i would say without any mayor difference.

    I use platformio with the upstream teensy-platform (v1.54) and macOS for compiling. The Teensy 4.1 is connected to a RaspberryPi 4 via USB and I am logging the Serial output via screen and to a file as my test setup.

    There is also no Crash Report after I reset the teensy with tycmd after the program stops/hangs. The last lines on my logs from each test vary in timestamps (= running time) and messages.

    These are the last lines of my latest test using smart ptrs.

    Code:
    [D]  16978136 | 2021-07-17 04:00:25 | HAPFakegato.cpp      [  145] addDataToBuffer | Adding entry for 0CD851-BME280-DUMMY [size=100 bitmask=7] - data length: 6
    [W]  16978136 | 2021-07-17 04:00:25 | HAPFakegato.cpp      [  157] addDataToBuffer | WARNING: Fakegato entry will be overwritten!
    [V]  16978137 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  130] handleImpl | [BME280] - Handle plugin [1]
    [I]  16978137 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  118] changedTemperature | [BME280] Changed temperature: 27.50 >>> 36.30
    [I]  16978137 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  122] changedHumidity | [BME280] Changed humidity: 29.00 >>> 22.00
    [I]  16978137 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  126] changedPressure | [BME280] Changed air pressure: 430 >>> 1060
    [V]  16978138 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  130] handleImpl | [BME280] - Handle plugin [1]
    [I]  16978138 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  118] changedTemperature | [BME280] Changed temperature: 36.30 >>> 28.20
    [I]  16978138 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  122] changedHumidity | [BME280] Changed humidity: 22.00 >>> 35.00
    [I]  16978138 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  126] changedPressure | [BME280] Changed air pressure: 1060 >>> 890
    [D]  16978138 | 2021-07-17 04:00:25 | HAPFakegato.cpp      [  145] addDataToBuffer | Adding entry for 0CD851-BME280-DUMMY [size=100 bitmask=7] - data length: 6
    [W]  16978138 | 2021-07-17 04:00:25 | HAPFakegato.cpp      [  157] addDataToBuffer | WARNING: Fakegato entry will be overwritten!
    [H]  16978139 | 2021-07-17 04:00:25 | HAPServer.cpp        [  926] handle | heap:382544 | mem:113676 | stack:113696 | clients: 0 | queue: 0 
    [V]  16978139 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  130] handleImpl | [BME280] - Handle plugin [1]
    [I]  16978139 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  118] changedTemperature | [BME280] Changed temperature: 28.20 >>> 34.10
    [I]  16978139 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  122] changedHumidity | [BME280] Changed humidity: 35.00 >>> 30.00
    [I]  16978139 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  126] changedPressure | [BME280] Changed air pressure: 890 >>> 600
    [V]  16978140 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  130] handleImpl | [BME280] - Handle plugin [1]
    [I]  16978140 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  118] changedTemperature | [BME280] Changed temperature: 34.10 >>> 35.60
    [I]  16978140 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  122] changedHumidity | [BME280] Changed humidity: 30.00 >>> 25.00
    [I]  16978140 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  126] changedPressure | [BME280] Changed air pressure: 600 >>> 840
    [D]  16978140 | 2021-07-17 04:00:25 | HAPFakegato.cpp      [  145] addDataToBuffer | Adding entry for 0CD851-BME280-DUMMY [size=100 bitmask=7] - data length: 6
    [W]  16978140 | 2021-07-17 04:00:25 | HAPFakegato.cpp      [  157] addDataToBuffer | WARNING: Fakegato entry will be overwritten!
    [V]  16978141 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  130] handleImpl | [BME280] - Handle plugin [1]
    [I]  16978141 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  118] changedTemperature | [BME280] Changed temperature: 35.60 >>> 30.60
    [I]  16978141 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  122] changedHumidity | [BME280] Changed humidity: 25.00 >>> 28.00
    [I]  16978141 | 2021-07-17 04:00:25 | HAPPluginBME280.cpp  [  126] changedPressure | [BME280] Changed air pressure: 840 >>> 310

    Any idea how to find and fix this error would be highly appreciated.

    Link to repository: https://github.com/An00bIS47/Teensy_Homekit


    Thank you very much!
    Last edited by kranfahrer; 07-17-2021 at 07:41 PM. Reason: Added link to repo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •