Skip to content

Rework backend add MQTT and WebSocket support #102

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

Merged
merged 37 commits into from
May 14, 2020
Merged

Conversation

rjwats
Copy link
Owner

@rjwats rjwats commented Apr 7, 2020

  • Update back end to add MQTT and WebSocket support
  • Update demo project to demonstrate MQTT and WebSockets

Update back end to add MQTT and WebSocket support
Update demo project to demonstrate MQTT and WebSockets
@saniyo
Copy link

saniyo commented Apr 7, 2020

Is there a common way how to stream data via WS, as you did in your old led project?
Sometimes it's necessary to stream and receive data from WS and bypass the settings module. it's just thoughts aloud.

@rjwats
Copy link
Owner Author

rjwats commented Apr 7, 2020 via email

@rjwats
Copy link
Owner Author

rjwats commented Apr 7, 2020

I still have to implement security on the WS connection (probably using the "JWT as query parameter" approach) and improve the documentation.

Any input at this stage is really welcomed!

@saniyo
Copy link

saniyo commented Apr 8, 2020

I still have to implement security on the WS connection (probably using the "JWT as query parameter" approach) and improve the documentation.

Any input at this stage is really welcomed!

Having added the security, please leave an ability to switch off the security feature for WS packets debug. Thanks.

@rjwats rjwats force-pushed the ft-mqtt-websockets branch from 56a505d to c33479a Compare April 26, 2020 22:22
This was referenced Apr 30, 2020
Copy link

@philip-searle philip-searle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me; just a few minor typos that caught my eye. Splitting the serialization out from the service/endpoint code is a good change; significantly simplifies them and allows the serializer to be reused across REST/WS/MQTT handlers.

Make allowRemove work as expected
@rjwats
Copy link
Owner Author

rjwats commented May 5, 2020

Working on a weather station project this weekend I realized that I missed a significant use-case.

When reading from sensors you may have Endpoints/WebSockets/Brokers which will only ever source data - GET only Endpoint/Transmit only WebSocket/Publish only MQTT. In this situation you never externally update the sensor data, only read updates from it. The framework does not facilitate this nicely.

In my weather station branch I played around with improving this by separating out the GET from the POST and the Pub from the Sub (introducing more class types). I think this might be a good change and provides another decoupling improvement.

Going to continue looking at this after work today.

@rjwats rjwats force-pushed the ft-mqtt-websockets branch from 19d61b0 to c44d4af Compare May 6, 2020 23:41
@rjwats
Copy link
Owner Author

rjwats commented May 8, 2020 via email

@rjwats
Copy link
Owner Author

rjwats commented May 8, 2020

@kasedy Thanks for the great feedback - I've made your suggested changes in this branch.

@rjwats
Copy link
Owner Author

rjwats commented May 8, 2020

A naming question, for those with opinions on the subject:

Do the names "SettingsService", "SettingsEndpoint", "SettingsXxx" still make sense?

Early on in the framework, "settings" were just about the only thing I was dealing with in the SettingsService class. Now, "SettingsService" has become more of an event-driven conduit for data (might be: settings, sensor data, state etc...) I'm not sure the names really make sense now.

I thought "DataBus" (sounds a bit "enterprisey") or "DataService"? I'm quite familiar with the current names now but I wonder if there are better ones. Seeing as this PR introduces such a lot of changes this might be the right time to do that too if we can find better names.

@rjwats
Copy link
Owner Author

rjwats commented May 10, 2020

LGTM

I eager to see WebSocketTx / WebSocketRx changes. It would be nice to migrate MQTT / WiFi / AP status pages to sockets. Right now it annoying to refresh them constantly.

Regarding the status endpoints: I hadn't thought about that really, but yes, we could push status changes to the UI. Currently most of the status endpoints are read on request rather than managed with events, though this could be changed.

I've added an issue (#104) to the backlog because I think this might be a nice change, probably after this PR goes back to master.

@kasedy
Copy link
Contributor

kasedy commented May 10, 2020

@rjwats, can you give me contributor access? I would like to participate in the development. It would reduce turn around time for small fixes and improvements. If you have questions please find my email in profile.

@kasedy
Copy link
Contributor

kasedy commented May 10, 2020

Proposal: move base classes to separate directory lib/framework/base
SettingsDeserializer.h
SettingsEndpoint.h
SettingsPersistence.h
SettingsSerializer.h
SettingsService.h
SettingsSocket.h

@rjwats
Copy link
Owner Author

rjwats commented May 10, 2020

Proposal: move base classes to separate directory lib/framework/base
SettingsDeserializer.h
SettingsEndpoint.h
SettingsPersistence.h
SettingsSerializer.h
SettingsService.h
SettingsSocket.h

Yes, I had that in mind too. Have split "core" and "util" from "framework".

That, and some of renames discussed above (PR back to this branch) for separate review:

#105

rjwats added 8 commits May 11, 2020 23:19
Introduce asymmetrical implementations of HTTP, MQTT, and WebSockets
Rename core feature types (SettingsEndpoint, SettingsBroker and SettingsSocket)
Rename SettingsService to StatefulService
rename socketPath to webSocketPath in back-end
@rjwats
Copy link
Owner Author

rjwats commented May 12, 2020

Think that's all the renames done for now... I'll get the README updated tomorrow then this PR can go back to master.

Shout if you spot anything super critical. After this it would be good to do a round of tidyups, then get on with the "feature service" to allow features to be disabled at build time.

@rjwats
Copy link
Owner Author

rjwats commented May 13, 2020

@proddy @kasedy I'm thinking PROGMEM_WWW should be the default now. I rarely deploy the interface separately any more. It would mean also enabling "min_spiffs.csv" for env:node32s by default.

What do you think?

@proddy
Copy link

proddy commented May 13, 2020

yup, do it. progmem all the way! BTW I don't think you ever checked-in your min_spiffs.csv. Also note SPIFFS will be depreciated on the ESP8266 soon and replaced with LittleFS. What I did on one of my projects is replace all the SPIFFS.* calls with a nasty define, like:

#if defined(ESP8266)
#include <FS.h>
#include <LittleFS.h>
#define EMSESP_FS LittleFS
#elif defined(ESP32)
#include <SPIFFS.h>
#define EMSESP_FS SPIFFS
#endif

@rjwats
Copy link
Owner Author

rjwats commented May 13, 2020

Thanks @proddy, agreed - PROGMEM is the way!

min_spiffs.csv is provided by the arduino-esp32 core thankfully so you can just reference it. I had however, carefully calculated a suitable partition table before discovering it though, wasted effort :(

Thx for the info on the deprecation of SPIFFS. The internals rely on the FS abstraction so, like you say, it's easy to swap out.

@rjwats rjwats merged commit a1f4e57 into master May 14, 2020
@rjwats rjwats deleted the ft-mqtt-websockets branch May 29, 2020 19:59
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

Successfully merging this pull request may close these issues.

5 participants