Skip to content
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

ESP32 Support (or just no_std in general) #1163

Open
sebadob opened this issue Nov 20, 2023 · 5 comments
Open

ESP32 Support (or just no_std in general) #1163

sebadob opened this issue Nov 20, 2023 · 5 comments
Labels
proposal Enhancement idea or proposal

Comments

@sebadob
Copy link

sebadob commented Nov 20, 2023

Proposed change

Recently, Rust on ESP32 and embedded devices in general has made huge steps forward. By now, we can even execute std Rust and fully async runtimes like tokio on just an ESP32 device.

I don't know, if this would even be possible without huge changes internally, but would it somehow be possible to introduce a new feature flag, which would reduce the dependencies as much as possible and, more important, get rid of any dependencies that pull in ring ? There are wrappers and all sorts of things, that make it possible to just use TLS directly on these devices already with HTTP or WS connections. If possible, it would be a huge advantage I guess, if async_nats could use something like https://esp-rs.github.io/esp-idf-svc/esp_idf_svc/tls/struct.EspTls.html instead of bringing its own TLS suite, which pulls in ring.

The existing libraries have all sorts of functionalities built-it and you can use mqtt right away without needing to add anything else, but it would be so much more convenient if we could use Nats directly without configuring the mqtt bridge.

Use case

Make it possible to build all kinds of embedded / IoT devices from microcontrollers with direct NATS support instead of bridging between MQTT and NATS.

Contribution

I have never worked with the internals of this crate so far, but I could give it a shot. It would actually depend on the answer from someone who knows the code, if it makes sense as a "good first issue".

Edit:

... or maybe an integration with https://github.com/drogue-iot/embedded-tls can be done.
I think at this point, the only missing part to make it work in embedded systems is TLS.

@sebadob sebadob added the proposal Enhancement idea or proposal label Nov 20, 2023
@Jarema
Copy link
Member

Jarema commented Nov 23, 2023

Hey!

That is an interesting opportunity to pursue.
The embedded-tls crate looks interesting and it does seem to support async API, but it's also narked as a work in progress, which sounds scary for such sensitive thing as TLS.
On the other hand the EspTls seem to by sync only, though I might be wrong here, as I just did a quick check.

Feel free to experiment on a fork and let us know. The TLS code is referred in very few places in the codebase, so despite this issue sounding like a low level stuff, it might be pretty easy to pick it up.

However, keep in mind that we have to be careful when enabling/disabling TLS related features and dependencies, so no promises that it would be merged.

@paolobarbolini
Copy link
Contributor

What do we think about using rustls with the third-party mbedtls crypto backend?
https://github.com/fortanix/rustls-mbedtls-provider

@Jarema
Copy link
Member

Jarema commented Jan 30, 2024

I looked at it briefly and it looks like a promising option @paolobarbolini

@sebadob
Copy link
Author

sebadob commented Mar 15, 2024

I had a few more thoughts about this.
WebSocket is almost always available on embedded no_std devices, natively.
We can run Nats with WebSocket enabled.

Would it be possible to make async_nats work over WebSocket with a feature flag? Maybe with only basic support without stream configuration, since you would usually do this from a bigger server anyway instead of from IoT devices.
Maybe we could use the already existing logic and structs from inside native embedded on message handlers.
This would mean someone would need to do a bit more manual work to set it up, but maybe also make it possible to use the crate in environments like WASM and so on?

@sebadob sebadob changed the title ESP32 Support ESP32 Support (or just no_std in general) Mar 15, 2024
@Jarema
Copy link
Member

Jarema commented Mar 15, 2024

Websockets are planned.
Should be possible by swapping the transport as other clients do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

3 participants