Skip to content

MQTT implementation #46

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

Closed
carlosatta opened this issue Aug 2, 2019 · 15 comments
Closed

MQTT implementation #46

carlosatta opened this issue Aug 2, 2019 · 15 comments
Assignees

Comments

@carlosatta
Copy link

Hi all,

I'm trying to implement MQTT with Arduino MQTT library (https://github.com/256dpi/arduino-mqtt).

I'm not a C/C++ developer, and I'm stuck with the status page (https://github.com/carlosatta/esp8266-react).

For now I've created the settings and status page and MQTT settings service, but seam impossibile to me read the mqtt connection status inside the MQTTStatus.

Some one can help me please?

@rjwats
Copy link
Owner

rjwats commented Aug 2, 2019

Hi Carlo,

I'm not seeing any of your back end code committed to your 'mqtt' branch can you push it up so I can take a look?

What is the error you are seeing?

Rick

@carlosatta
Copy link
Author

carlosatta commented Aug 3, 2019

Hi,

sorry my fault. Now I've push all the files.

In the file https://github.com/carlosatta/esp8266-react/blob/mqtt/src/MQTTStatus.cpp i would like to read the mqtt connection status, but seems to be always false.

In the file https://github.com/carlosatta/esp8266-react/blob/mqtt/src/MQTTSettingsService.cpp I start the mqtt connection and seems to be all ok and I can change configuration in FE at /mqtt/settings url.

@rjwats
Copy link
Owner

rjwats commented Aug 3, 2019

One possible problem is how you are storing your MQTTClient instances in your objects. These are being passed in as pointers but being dereferenced and values assigned to new variables. Try converting these to pointers.

@carlosatta
Copy link
Author

Done!

If u are interessed in this feature I can clean up my code and make a pullrequest.

Thanks.

@rjwats
Copy link
Owner

rjwats commented Aug 4, 2019

Getting MQTT integrated could be useful yes! Your project looks interesting too!

If you are wondering why this was broken, it was because you effectively make 3 different copies of the client instance when using variables. C isn't like garbage collected languages where you are almost always passing around references - variables are areas of memory.

I want to rework the code so some features can be enabled as build time options. I have a good idea about how to achieve this - there is another issue open for disabling the authentication feature I added recently - a valid feature request.

Feel free to open a PR, it looks like decent work! I might pull it into a branch for later integration once I've addressed making features optional.

Feel free to close this issue down if it's all sorted now :)

@rjwats rjwats mentioned this issue Dec 29, 2019
@rjwats rjwats self-assigned this Feb 23, 2020
@rjwats
Copy link
Owner

rjwats commented Feb 24, 2020

Is it worth trying to support SSL with MQTT?

In my experimenting with async-mqtt-client I have managed to get SSL "working" but it consumes 20k of RAM on the esp8266 which is rather impractical.

In addition it looks like AsyncTCP doesn't yet have SSL support, meaning the MQTT client can't support it under ESP32: marvinroger/async-mqtt-client#164

Is MQTT without SSL a credible offering?

@proddy
Copy link

proddy commented Feb 24, 2020

It does require a lot of additional CPU and RAM which as you said is precious on an ESP8266. In the end I removed it from my implementation as it couldn't get it stable together with my old web interface. There are however implementations that have done it (espurna, tasmota) with a lot of hacking and code.

I would say drop it.

@rjwats
Copy link
Owner

rjwats commented Apr 30, 2020

PR is open which introduces MQTT and WebSockets including an example project which demonstrates the new features:

Feature Branch: https://github.com/rjwats/esp8266-react/tree/ft-mqtt-websockets

PR: #102

I'd be very interested in feedback before I push this change to master as it's a fairly significant diversion for the core of the framework. The change makes the framework more event orientated and factors out the serializer concept from the core classes so data can be serialized in a different ways for different use-cases (I found home assistant usually wanted a different format to the REST endpoints, especially with auto-discovery - it's quite prescriptive).

I think it represents a positive change and provides better internal decoupling (SOLID), but I would love some comments if anyone who's had experience with the framework has time to have a mess around with it.

@lorol
Copy link

lorol commented Apr 30, 2020

Hi @rjwats just a note you may find interesting.
I used an optimized ESPAsyncWebServer fork, based on: https://github.com/sascha432/ESPAsyncWebServer
see the results, first one is the original lib.
NORMAL
OPTIMIZED

@lorol
Copy link

lorol commented Apr 30, 2020

I need to learn a lot until be able to use your great framework, maybe first I need to buy a new computer, because the initial build takes 20-30 min on the one I have.
Also I need to fully understand how to modify/create react UI js, for me it looks just hacking. Somewhat I am missing the advantage of this huge JS stuff buzzwods around. Feel a bit blind - to add a button or menu ... wow is not easy, still source code and building.

But It works. I will play with it, Thanks a lot for WS.

@rjwats
Copy link
Owner

rjwats commented May 1, 2020 via email

@lorol
Copy link

lorol commented May 1, 2020

Hi @rjwats, any practical MQTT testing, guide especially for the mentioned "Home Assistant's auto discovery feature"?
I succeed to to connect the device to free broker (mqtt.eclipse.org), also can run one at home network.
What next? I am bit lost ... and have to go far down.

@rjwats
Copy link
Owner

rjwats commented May 1, 2020 via email

@proddy
Copy link

proddy commented May 1, 2020

@rjwats I'll try out the latest PRs and provide some feedback. I fully support the effort you put into decoupling and serializing the interfaces. Can't beat clean code and it's good source for anyone coming from hobby Arduino C and wanting to learn more on modern OO design patterns and C++11/17. I'm planning to swap out my current web UI with ESP8266-React soon.

MQTT is a wolf is sheep's clothing. I found when I implemented an mqtt service on some on my own projects I ended up writing a library with a lot of code to handle mqtt publish queues, retries, QOS 1/2 acknowledgements etc.

@lorol good find on the memory optimized asyncwebserver fork. True, I'm a bit obsessed when it comes to squeezing out every byte of heap from the ESP8266s and using flash memory where ever possible. I'm actually fed up with the ESP8266s (they are 6 years old now!) and can't wait for those cheap ESP-S2s to hit production.

@rjwats
Copy link
Owner

rjwats commented May 17, 2020

MQTT support added to the framework along with example code.

@rjwats rjwats closed this as completed May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants