-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
replace AsyncMqttClient with espMqttClient #1178
Comments
Seems to work with only liitle renamings/changes:
Codesize with the lib is 15k less, but free heap is 7k lower and maxAlloc is 8k lower. Maybe the memory consumption cn be tuned. |
That was quick! The heap memory usage is a shame. Does this happen when the library is instantiated or after it's being used with a few publishes? One thing I saw which is worth checking out is the TLS support, which sits on top of the Wifi/Network layer. Would be good to see if that works for us, also with Ethernet. |
The memory usage is also with mqtt disabled. I've pushed this test to my dev, you can check. It's only the esp build, the standalone needs more work for a dummy lib. |
The memory usage is mainly the extra task with 5k stacksize, there is a option to skip the extra task an handle _mqttClient.loop() in our MqttSettings-loop. Then heap is identical with async-mqtt-client. |
Qos2 is broken, sending a lot of PUBCOMP with increasing message id. Also leaking memory, i think the PUBCOMP are all kept in queue. I've found where the wrong PUBCOMP is generated, but removing this ends up in sending repeated PUBREL with message-id counting up and eating memory. I'll open an issue on the bertmelis repo when i knew a bit more what's wrong. BTW: There is also mqtt integrated in IDF: https://github.com/espressif/esp-mqtt with tls and mqtt 5 support, but i think it needs a lot af changes. |
I've been itching to move to the native IDF libs for both mqtt and the webserver (see me-no-dev/ESPAsyncWebServer#1287) |
|
I think i've fixed the qos2 bug. BTW: i've also added the "Apply changes" button to the manage users page. It's not perfect, not comparing any change, only checking for save/cancel from edit-user dialog. |
nice work. Is it using asynctcp or not asynchronous anymore (i.e. calling from the loop? |
It's not async: I've added a queue-size output to the espmqtt-lib and will try to only use the queue ot the library. |
I've changed mqtt.cpp to only use the espMqttClient queue, removed the ems-esp queue and the qos resends, this is done by the lib. Sendout is much faster. |
I'll check it out. Looks promising! Should we also look at adding TLS? |
My normal broker is iobroker.mqtt and can not handle secure connections. I have to setup a new mosquitto to check. |
This is something we can try later then. I have mosquitto with TLS so would be easy for me to test. First though is completing the axios->alova port in the web front-end (which will save 20KB in flash) |
Hi @MichaelDvP - shall we prepare a merge? Your dev looks and works great and I have my web re-write using Alova instead of Axios. Together these to PRs will save 17K in Flash. Shall I make a new branch called |
Merged my alova port into dev2 before:
after:
Only saves 4188 bytes in Flash. Not as impressive as your espMqttClient |
With the extra language we are here:
|
In the discussion about reconnect i see that tbnobody uses normal/tls connections this way:
and configs here https://github.com/tbnobody/OpenDTU/blob/9b0d2ff25f48fd39155894351d4069fba5900efa/src/MqttSettings.cpp#L104-L126 I think this is the way to implement usecure/secure clients on demand. Should i make a test? |
Yes! Adding TLS has been on our list for a while. I would create and hardcode the certificate and use And to test I would download a local copy of mosquitto.exe, setup a config file, add the certs, and run it manually from Windows (not as a service). http://www.steves-internet-guide.com/mosquitto-tls/ BTW I was looking at tbnobody's (Thomas Basler) OpenDTU project, interesting that we followed the same path on the front-end and back-end, yet also quite different approaches to solving some problems. Many of the features between our projects are also similar (web log, api, update etc). Maybe some ideas we can exchange later. Anwyay would be good to reach out and connect with this guy. |
I've updated my dev2 with optional Mqtt-TLS. |
nice! I'll check. I think for now we can hardcode a default CA and later, if needed, make it editable. |
There is already an input field for the certificate, leave it blank to disable security. Changing the certificate needs and triggers a reboot. Certificate input is only the certificate, the begin/end lines are added in code. |
I've setup a local Mosquitto broker configured for TLS, generated the cerst and keys and tested locally and the MQTT TLS works. But EMS-ESP fails to connect. So I hardcoded the CA into the code to see if that was the problem, but it still fails. So will need to go deeper and debug. It's not a library issue as the example https://github.com/bertmelis/espMqttClient/blob/main/examples/tls-esp32/tls-esp32.ino works. |
Same here, setup mosquitto on a raspberry 3b with tls, tested positive with mqtt-explorer. No connection with ems-esp. Also with hardcoded certificate (do we need |
I added my test to a GH repo here: https://github.com/proddy/mqtt-test It uses the same logic as you coded, with espMqttClientSecure and espMqttClient using the static casts and it works fine. So the problem is somewhere in the EMS-ESP code. Perhaps the order it's initiated? The hardcoded \n in the CA string is needed. |
Played a bit with your mqtt-test, thank for making this:
I'll update my dev2. |
ah, good now that it works. I'll test again. I also put the A few other ideas
|
Sorry, i have to do some more tests, not working correctly. |
With your mqtt-test i always get with hardcoded certificate
when removing the \n from header or footer it gives
so format is right, but verification failed. Seems my mosquitto installation is wrong. I thought it's working because mqtt-explorer connects with tsl and this certificate set, but if i change the certificate in mqtt-explorer it also connects. (insecure). |
Can I help with testing? For my mosquitto setup I used the scripts at http://www.steves-internet-guide.com/download/ssl-certificate-shell-scripts-linux/ and did
and my mosquitto.conf is just
And to test I used, on Windows:
|
I've made a mistake generating the certificates, now with FQDN |
Ok, updated my dev2. TLS is only for esp32-S3, the esp32 version compiles to fit 2M partition. Certificate is striped down to pure certificate after input, just copy&paste the cert to the input field, header/footer/cr/lf/blanks are removed. |
works fine, both with a CA and using "insecure", I'll leave it on for a few hours and monitor. Great work! What I did find is
I'll work on #1218 so then the TLS web input can be disabled if the firmware is not compiled for an S3. |
Leaving blank connects to a standard broker with emsMqttClient, |
Changed to no restart needed. Also check for port and set cert to unsecure if port>8800 and empty cert. |
great. I've done #1218 so you can add a disabled flag to the MQTTSettings page and check for |
Thanks, but i think the feature.platform ist not needed for the mqttSettings. Check only in .ccp file is only one single file to change if we add to other platforms and leaving rootCA undefined works. |
if you build on platformio 5.3.0 for a 4MB ESP32, it'll show the TLS box in the Web, when the option is technically unavailable? |
Actually the tsl-box is only shown on ESP32-S3 platform. |
ah I see. nice! |
happy for you to merge your dev2 into the ems-esp repo when you're ready |
closing! A fabulous addition. Thanks again Michael for picking this one up. |
@MichaelDvP I had to make some very minor changes to espMqttClient to allow it to compile on Linux and OSX. They don't impact the ESP platform. I'll mention this to Bert or do a minor PR on his repo later. Changes are all marked as "// modified by proddy for EMS-ESP compiling standalone" and in |
If you do the PR, there are also some small changes from me in the Mqtt lib.
|
looks nice. Also the current async-mqtt has a queue and processes qos, works also direct sending. The ems-esp queue is only usefull to queue before connected. But the new lib looks good. We should test it.
Originally posted by @MichaelDvP in #605 (comment)
The text was updated successfully, but these errors were encountered: