PerMalmberg / Smooth

C++ framework for embedded programming on top of Espressif's ESP-IDF.
Apache License 2.0
325 stars 30 forks source link

MQTT user/password authentication #168

Open Paul-Simpson opened 2 years ago

Paul-Simpson commented 2 years ago

Hello,

Again, thank you for sharing this framework with the world.

I'm returning to my project and since updating to IDF4.2 and Moquitto 6.0.1, I'm having connection issues with MQTT.

I think it might be something to do with authentication, so I've tried adding a user/passwd but don't see anywhere to do that. Unless I'm missing something, Smooth does support that? I also looked to see if Smooth supports SSL/TLS encryption. Is ConnectToBrokerState.cpp the right place to look at? Btw, have you implemented your own MQTT protocol from the group up?

Many thanks again for any advice or help,

Paul

Paul-Simpson commented 2 years ago

I've found .../mqtt/packet/Connect.cpp - where the MQTT connect packet is being built up. Looking into this and will revert.

PerMalmberg commented 2 years ago

Got to head to bed now, but I'll try to help you out tomorrow.

On Thu, 28 Oct 2021, 21:21 Psim, @.***> wrote:

I've found .../mqtt/packet/Connect.cpp - looks like user/passwd need to be inserted here? Any pointers would be welcome and I'll happily give it a go!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PerMalmberg/Smooth/issues/168#issuecomment-954132273, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAU2LLEV3HYMPMYCMLJJQYTUJGWGPANCNFSM5G3PG5JA .

PerMalmberg commented 2 years ago

There is actually a fork that adds username and password, as well as TLS for mqtt. I've not had the time to engage that author to verify the functionality of those additions and merge them back into this main repo, but if you're willing to I'm more than happy to accept a PR with tests for it.

Paul-Simpson commented 2 years ago

Thank you - that is great news. I was wading through the TLS and MQTT protocols and thinking it's a non-trivial amount of work to implement from a standing start. I'll take a look at the fork over the weekend.

Paul-Simpson commented 2 years ago

Update: The fork looks promising, however, I'm having trouble compiling it with:

../lib/smooth/include/smooth/core/network/Wifi.h:31:10: fatal error: wifi_provisioning/manager.h: No such file or directory

include <wifi_provisioning/manager.h>

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

errors. I've checked that WiFi is turned on in "make menuconfig". I've been googling but have not found anything that helped me. I'm not sure if this rings any bells with you?

PerMalmberg commented 2 years ago

I'm guessing it is part of ESP-IDF?

Paul-Simpson commented 2 years ago

Yes. I can see the file. Vscode can even follow the include link. I'll look further into it.

Paul-Simpson commented 2 years ago

Hi, quick update. I've been looking at the luuvt mqtts fork. It works well with ESP-IDF 4.2.x, but I'm seeing compile errors when using with 4.3 or 4.4. The errors are:

In file included from /Users/paulsimpson/esp/esp-idf/components/driver/include/driver/gpio.h:16,
                 from ../externals/smooth/lib/smooth/include/smooth/core/io/spi/Master.h:24,
                 from ../externals/smooth/lib/smooth/include/smooth/application/io/spi/BME280SPI.h:30,
                 from ../externals/smooth/lib/smooth/application/io/spi/BME280SPI.cpp:19:
/Users/paulsimpson/esp/esp-idf/components/hal/include/hal/spi_types.h: In function 'constexpr spi_event_t operator~(spi_event_t)':
/Users/paulsimpson/esp/esp-idf/components/esp_common/include/esp_attr.h:123:79: error: use of old-style cast to 'uint32_t' {aka 'unsigned int'} [-Werror=old-style-cast]
 FORCE_INLINE_ATTR constexpr TYPE operator~ (TYPE a) { return (TYPE)~(INT_TYPE)a; } \
                                                                               ^
/Users/paulsimpson/esp/esp-idf/components/esp_common/include/esp_attr.h:135:29: note: in expansion of macro 'FLAG_ATTR_IMPL'
 #define FLAG_ATTR_U32(TYPE) FLAG_ATTR_IMPL(TYPE, uint32_t)
                             ^~~~~~~~~~~~~~
/Users/paulsimpson/esp/esp-idf/components/esp_common/include/esp_attr.h:136:19: note: in expansion of macro 'FLAG_ATTR_U32'
 #define FLAG_ATTR FLAG_ATTR_U32
                   ^~~~~~~~~~~~~

...is this something that you have seen before? I'm pretty green to PR's etc on GitHub, so please don't be afraid to spell out how I can be of help getting this fixed and in a state where I can PR it. Best Wishes, Paul

PerMalmberg commented 2 years ago

I think this original repo is compatible with 4.3 and 4.4, if I remember correctly another contributor made PR to fix it.

If you can compile this original Smooth repo with them, it's probably easiest to simply look at what luuvt has done and make new PR with those changes and any improvements on top.

I've been busy with other things for the last two years so I don't have the environment, nor the time, to investigate it myself.

Paul-Simpson commented 2 years ago

Hey - thanks for the pointers. I looked into this issue some more. The latest Smooth compiles just fine with 4.4, so I will look at how I can bring the luuvt mqtts changes into the latest Smooth and then PR that as you suggest.

Aside from the issue, I must say that I'm learning positively a lot from your code and architecture. :) Out of interest (and please feel free not to answer if you're busy) would you have structured it in the same way if you were to start again? I'm asking not because I see any issues, but because by the time I finished building a project, many lessons have been learnt along the way.

PerMalmberg commented 2 years ago

Out of interest (and please feel free not to answer if you're busy) would you have structured it in the same way if you were to start again?

Yes, and no. As with every software project, you learn things as it progresses and there are always things that can be done better. Smooth is actually based on similar software system that I developed and is running on thousands of systems at airports all over the world. I've you've ever landed on any major airport, it has likely affected you :) That one had a different OS, different requirements and was not something I wrote as a spare-time project, but the overall idea is the same.