-
Notifications
You must be signed in to change notification settings - Fork 819
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
remove duplicate code in main\ZgatewayBT.ino #557
remove duplicate code in main\ZgatewayBT.ino #557
Conversation
the ***Discovery functions every time create a new device unless this device is set to white-list before. as a result of this, the devices list contains the same mac multiple times with different flags
because now we have a utility function 'createOrUpdateDevice' we can globally cache this as a single flag
5606c9f
to
118f7f3
Compare
please wait with merge .. I found again a little issue with I want to fix before |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
c / c++ does not allow NULL as function parameter like modern languages
i'm done c / c++ does not allow NULL as function parameter like modern languages |
i dont know why this PR fails in travis-ci .. it build and work local |
…s1d3/ESP32_BLE librarie) this makes the semaphore handling more cleaner and readable
…advertised callbacks with dummy functions for a better readability we can remove this because isDiscovered does not do a devices walk anymore
travis ci builds now works again .. I don't know what is wrong with the enums, maybe someone can give me a hint |
@1technophile: I'm sure that I can merge ZgatewayBT.ino#L496 and ZgatewayBT.ino#L828 together but I didn't have a HM-10/11 for testing. Edit: For clearance, I mean the whole block For example Floyddotnet@c181cd4 |
I have it but not published.
Not in the following weeks unfortunately
It is a good idea, we could maybe do it on a separate PR. Another point to facilitate the maintenance of ZgatewayBT would be to add unit tests. But I didn't had the time to go in deep into this unfortunately. |
did you mean end to end tests? internally i use a combination of node.js and mocha to connect to the broker, send commands and wait for the response. at the moment i am working on the support for LYWSD03. i could clean up and generalize the code for the end-to-end tests a little bit and then make it available. but it will take a while as i can only work on the project on 2-3 days a week. my current roadmap:
|
i was thinking on pushing with some unit test runner raw service data and verify that the corresponding sensors values are the ones expected. Something that can be integrated with travis maybe by creating a separate executable script.
Good news !
That's a huge contribution, thanks ! |
from your request for unit test i understand that you are afraid that the above changes will change the behavior. if this assumption is correct. I have tested the changes with a Mi Jia and a LYWSD02. Both of them are transmitting discovery messages as expected, reporting temperature and humidity. I can also post the serial monitor output for you. |
Unit tests are more an enhancement that I would like to setup in a separate PR, maybe the one gathering both process_data function can be the opportunity to do it. Do you prefer me to review this PR as is or do you want to add other commits to it ? |
No, you can review the PR as it is. Currently, I am working on LYWSD03 support and active BLE connections. It's a bit difficult to structure the code so that it can be compiled with both the ESP32 and HM10 without creating memory leaks. Also, I'm just a recreational c developer, and I occasionally have problems with some features of c / c compiler that don't occur in most high-level languages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First functionnal tests are ok for me, white and black list are working, devices are detected and discovered.
I will go deeper into the code the next days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these important improvments!
All is working properly for me and your code learnt me some tips.
@Floyddotnet For info I'm currently merging the code of HM10 and ESP32 |
👍 i will fetch this changes asap. an update for you: It is definitivly harder to bring LYWSD03 and EQ3 support as i expected. at first i must fix some bugs in the ble libary and then i finish the first version of my LYWSD03 implementation. but then i run in massive stabillity issues like random crashes and unexpected errors. all related with the wifi / ble coexistence mode. if i disable wifi completly, all works fine. so i figure out that i must change some sdk-settings with are not directly available from PlatformIO or Arduino32. Then i switch to the ESP-IDF as framework, make all needed changes and abstractions (luckly not so many) and install Arduino32 as component of ESP-IDF. All my knowlege of the ESP-IDF framework configurations from other projects was partial useless because of some specials in PlatformIO. After getting it working, i realize that this don't solve all issues. so talk with the devs to get a newer version of ESP-IDF (like 4.0 or 4.1) working. this tooks a long time and solves some of the issues but brings new problems with the ble libary (with is dead). then corona lockdown comes and stole all my free time. this is currently the state. i hope my english is not too bad, so that i could make everything understandable. |
Thanks for the update Peter. Don't worry for your english, mine is worst :-) You will find below the PR, it is a work in progress |
Based on my original PR #553 I have further developed the idea to remove duplicate code inside the Bluetooth module step by step to improve the readability and maintainability.
During this, I found a data corruption with is triggered if the white-list is set before the devices are discovered. this is addressed with 92a833e
The last two patches of this series finally reduce the need for device-tree walks and increase the overall speed if many supported ble devices are in range.
Summarizing, these changes save over 141 KB flash size (~9%) and ~600 bytes of memory