-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
(ESP32) refactor device value rendering #16
Comments
made some minor changes
|
I see that the times are now double, as number in minutes and as text "days-hrs-mins". |
haha! our brains think alike. This is what I was planning to do yesterday night but wanted to get the changes in so you could merge your boiler updates. So lets do it. |
Ok, i'll make the change, the boiler enhancement contains 4 times. |
Still thinking of ways to improve this. Now when data is sent to the console or the web it follows these steps:
This is bit wasteful. I'm thinking there should be one function that takes the current device values and builds the json structure, so it's only done once and used everywher. For example the export_value() takes an additional parameter
Advantages
Disadvantages
Then we save some heap memory |
@MichaelDvP I'm working on some changes here, moving all the logic that generates the JSON for Web and MQTT back to the EMSDevices base class. It saves a lot of stack memory, removes 200 lines of code and makes it easier to extend. All device variables (e..g currSelTemp) is registered just like we do with the telegram handlers and the base class handles the formatting. Hopefully, we'll also have less nested DynamicJson objects freeing up Heap. The downside is that it changes almost all the code, so backporting PRs is time-consuming. I'm adding your changes manually each time. Which also means it's probably buggy. What do you think about this approach?
|
I agree. Make a release and the refactoring based on this. Fixes and changes in a temporary new dev can be ported later. |
great, you can decide when 2.1.1 -> 2.2 -> main/stable as you've done most of the changes. Let me know and I'll do the merge. There's a github actions script that does this. I'll also update the documentation. |
I think, freeze 2.1.1 now, take it as base, wait a day for possible feedback to the latest changes and if there is no massive issue release. |
@MichaelDvP another opinion: shall we drop MQTT single mode? Just use either Nested or Home Assistant. It really simplifies the code. |
I like the single, mainly because of dallassensors, we discussed that before. Also thermostat with smaller packages for main data and hc (RC35) is nice, but not necessary. We can drop, but i will always have a dallas format with unique id in my system. |
What I meant is that we remove the MQTT format options. There is just one, which is for everyone, that is nested for thermostat/mixer and does what you want Dallas to do. No choices. Then there is an option like 'Home Assistant?' which when enabled will do the extra bits needed to make HA work. The only problem may be the different ways Dallas is been shown, then in that case have a 'Dallas MQTT format' option. Reason I'm asking is that is greatly simplifies the new code I'm writing for all the EMS devices (not dallas) |
Make it nested and i add a checkbox to mqtt settings |
got it. |
another thing, looking at the mixer, the topics are either |
oh forget that. It's only for single mode. I remember we now collect all the mixer payloads, combine them and send them as |
Yes, nested it's {hc1:{},wwc1:{}}, and it's possible to have all in one system (device 0x20-0x27 hc1-8, 0x28, 0x29: wwc1, 2 |
@proddy: I think most issues solved now, but need a few additions. BTW: as mentioned in 628 and 635 there seems to be somthing wrong in github for the dev-branch: source download points to 2.10.-main, from here. and here |
Hi @MichaelDvP , I've changed (or touched) almost every single file with my 2.3 build so an auto merge PR will probably fail. It's better if you push all your changes directly to the dev branch and when you're happy I can merge into the main branch as 2.2 stable. Then I'll manually try and merge into the fb-632-refactorvalues branch. |
pushed some quite big changes to the fb-632-refactorvalues branch. I had to touch a lot of the code, and made many fixes and improvements along the way. Roughly what's new is
Tested with simulations with an ESP32 and it seems to work. But the boiler code fails when registering on an ESP8266. I need to debug and find out why. I think we're running out of memory heap perhaps. |
and forgot to mention @MichaelDvP , still need to manually merge in your latest changes from |
Yes, its a big problem on the ESP8266 and I'm worried, and angry too! I need to measure how much physical memory the new device value table struct is using. I was hoping very little since it only contains pointers to flash memory. By the way for my testing I used the standalone version (make file and no ESP) and also an isolated ESP8266 without anything attached (just the USB) and simulating a Boiler using I'll continue this week with fine tuning |
I'll test with esp32 later. There are a lot of changes and i need some time to understand all. First look, maybe i'm wrong, but the prefix (tag) is stored as string for each value? And boiler tags are long and nearly the same for all values. Store only I can add the b7-changes manually. |
I think I'll just a bitmap, it only takes a byte and have masks. Then in the logic I determine the behaviour based on the device_id. |
I was wrong, i tested with shortend strings but it has no effect, It's always the same boiler string and the value-register is only a pointer to it. |
yes the std::string uses a & (a reference). I could haved used a && with a |
okay, so the new device value registry eats up so much memory is mind boggling. My test environment:
So registering just 38 entries takes up 6000 bytes of heap memory. Which is strange since the struct only contains pointers. This is why it's failing. Now I need to analyze why. |
doing some memory profiling. Using the steps above
conclusions is that the std::vector takes a lot of memory. 2800 bytes for 38 objects. I will experiment with a lightweight implementation of a list and also a dynamic array to see how that helps. |
I've been spending quite some time in understanding how the heap works on an ESP8266 with an effort to reduce it so the implementation to register all the device values doesn't explode the ESP8266. For the core of EMS-ESP I really need only two containers, a queue for the incoming Rx, outgoing Tx and outgoing MQTT messages and a fixed dynamic array for storing 2D data like the MQTT commands, Telegram handlers and these new device values. for queues I'm using the C++ STL container implementation that comes with Arduino called For the array I was using Since there is a lot of overhead in these containers I wrote my own lightweight single-threaded containers. Here are the benchmarking results with storing 200 structs (class elements):
In the struct itself, uint8_t's obviously take 1 byte, flash strings 4 bytes and function pointers using With these new changes I think I can reduce memory by 10-15%. I'll try later and see what it looks like... |
Pushed in my latest efforts. Replaced all the std:: containers with home grown queues and arrays, thinking it would help. Now the heap is allocated up front, but problem is that it takes up too much on the ESP8266 so its explodes and crashes. I did manage to make some minor improvements along the way, like using C++17 and better optimizations that helped reduce the binary RAM from 50.5% to 48.4% and the Flash from 93% down to 86%. Also bugs and others things in the EMS-ESP code which I've now forgotten. Note, there is still a memory leak somewhere, which you can see when compiling with EMSESP_DEBUG. I suspect this is in Some next things to try are
If I can't get it working then I'm going to give up, and re-write a version 3.0 using ESP-IDF and not stupid Arduino's which takes up more than half the memory. |
the coding is complete. Been running stable for a few days. I'll rename the branch to v2.3 and start to extend with new features. The 2.2 dev branch should be renamed to as this will be the last minor release, only ESP8266 patches and bug fixes. |
Just to let you know and to prevent double work, i started to test the refactored build on bbqkees esp32 prototype. |
Hi @MichaelDvP great that you're testing the ESP32 too. Please go ahead and submit anything directly to the branch. I will rename that branch shortly and call it something more meaningful like |
actually @MichaelDvP best wait until I've moved the branch. I'm about to push a lot of new changes, mainly renaming the wifi functions |
I also wait for feedback to |
For the record, I'm experiencing frequent restarts. It could be memory related so monitoring and will spend some time debugging to try and chase the root cause. |
Memory was really low in the first ETH implementation, now it's much better, but i have only tested with wifi-only. I'm trying to connect the 8266 v2.2.1 buspowered and the esp32 by servicejack. Different device-ids, mqtt-base, etc. but this makes a lot of issues on ems and mqtt. Ems works best if both on the same id (0x0B) and one is set to tx_mode 0. Another issue, the system uptime in v3 counts after some 10 hours suddenly +50 days. Maybe something in memory addressing. |
Thanks for the feedback @MichaelDvP . I've been monitoring the memory with Grafana and haven't seen any more drops so I think its ok now. The restarts I was experiencing were most likely caused by Wifi reconnects. I'll also test running multiple devices (one ESP8266 and one ESP32) to see if I can fix the MQTT issues you're seeing. I would had expected with different hostnames and client-IDs, and HA disabled, it should work. Haven't see the issue with the +50 days yet: {"status":"connected","rssi":92,"uptime":"001+11:43:03.642","uptime_sec":128583,"mqttfails":0,"rxsent":83632,"rxfails":14,"txread":19305,"txwrite":3,"txfails":0,"freemem":109884} If you could merge in the MQTT base and Mixer fixes, I'll rename the branch to v3-esp32 or something. I've also started looking into alternative libraries for Web and MQTT which don't use AsyncTCP and customized for the ESP32 which will gives us TLS/SSL. |
Ok, mixer, base and dallas-fails added, also a few fixes for roomctrl and master-thermostat. I'll also push a new version (v2.2.1b1) with base and sensor-fails, also changes time to datetime and split boiler_info to be compatible with v3. |
thanks for those changes. i didn't mention earlier that using the Ethernet libraries uses 20Kb of heap too, if activated. |
going to rename the branch |
there's a lot of code duplication in the device libraries so I'm working through to clean up the code, moving functions back to the base class. One of the changes is in the way the device information is printed to the shell which is very similar to how we create the data to send to the web. I propose
I've tested with Boiler with good results so far.
The text was updated successfully, but these errors were encountered: