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

no_std support #53

Closed
jiayihu opened this issue Nov 20, 2020 · 18 comments
Closed

no_std support #53

jiayihu opened this issue Nov 20, 2020 · 18 comments

Comments

@jiayihu
Copy link
Contributor

jiayihu commented Nov 20, 2020

Is there any plan to support no_std with this crate since CoAP is heavily used in embedded? There is coap-lite but it's unmaintaned and it handles only packet parsing and creation

@Covertness
Copy link
Owner

Can you tell me what would you do in the embedded device?

@jiayihu
Copy link
Contributor Author

jiayihu commented Nov 21, 2020

I'm currently using a MCU called STM32F407 with 512KB flash and 128KB RAM and this lib currently weights too much
Screenshot 2020-11-21 at 12 55 16. I don't have all the std library or the tokio runtime, some embedded apps don't even have a heap. I'm currently using smoltcp as network stack.
Regarding the usage of CoAP, I'm using it as base protocol for REST api calls to the board to get a description of the resources and other operations like reading data or sending a WASM module.

I've already managed to integrate CoAP using coap-lite and you can see the result here, although it's at its very early stage. I made my own fork and copied to relevant implementation of CoAPRequest and CoapResponse from this crate. At first I thought about making the changes in this repo and submit a PR, but I feel there's too much work for me. This crate is very much relying on crates like bincode, serde and tokio without actually being necessary IMO. For instance I feel it should be out of the crate the responsibility of connecting to a UDP socket.

@Covertness
Copy link
Owner

I think you just need a CoAP message packaging library. The coap-lite fit you well. This library was made for people easy to setup a CoAP server/client.

@jiayihu
Copy link
Contributor Author

jiayihu commented Nov 22, 2020

It would be nice to separate this lib into two crates maybe, one with only message packing with no_std support and another one easy to setup. This would avoid fragmentation of libraries, for instance RFC 8516 has been recently added here and it's missing in coap-lite. In the current situation people like me have to make a fork of coap-lite and try to catch up with any changes that have been made to the packaging modules, creating "yet another fork" that will be forgotten. What do you think? This would also require not much work in this crate and without breaking changes

@Covertness
Copy link
Owner

That sounds like a good idea. I will do it later. Or can you implement the no_std crate and then I use it to packing message ?

@jiayihu
Copy link
Contributor Author

jiayihu commented Nov 23, 2020

Do you mean creating a separate branch where I transform this repo into a workspace and add the no_std crate? Then you add another crate on top of it with tokio (I think serde and bincode won't be needed if you are only encoding/decoding to binary, which is already done in no_std without dependencies)

@Covertness
Copy link
Owner

I think you create a new repo would be better. And I update this repo based on your repo.

@jiayihu
Copy link
Contributor Author

jiayihu commented Nov 23, 2020

My fork is already available at https://github.com/jiayihu/coap-lite where I pushed the latest changes including CoAPResponse and CoAPRequest based on the impl in this crate. I skipped IsMessage though because it seemed a non-necessary indirection.
The fork is no_std compliant without using bincode and serde for binary conversion to [u8]

@Covertness
Copy link
Owner

Can you upload it to https://crates.io/ ? After that I can import it into my repo.

@jiayihu
Copy link
Contributor Author

jiayihu commented Nov 24, 2020

Wouldn't be more correct if you did it? In the end it's practically code that you wrote and you should take credit for it. You would also have more freedom in changes. I can make PRs if I feel something more is needed. Let's also hear if @martindisch is active, I could just make a PR to his already published crate

@martindisch
Copy link

That's neat, I originally repurposed this implementation into coap-lite because I was working with STM32F3 and STM32F4 too. You could absolutely just make a PR to my repository. But consider that I made a couple of changes to the original code, so this implementation and mine might have digressed quite a bit, making it harder to integrate coap-lite here.

@jiayihu
Copy link
Contributor Author

jiayihu commented Nov 24, 2020

I don't think much work is needed because coap-lite deals only with the packet layer and the main difference is the absense of serde and bincode. The other structs and methods are the same, when I added CoapResponse and CoapRequest in my fork I just had to copy some methods from this crate which had been added meanwhile. That being said, I'm going then to open a PR for you @martindisch . Then let's see if this crate can be based on coap-lite to unify the work 😄

@Covertness
Copy link
Owner

Waiting the pr: martindisch/coap-lite#1

@martindisch
Copy link

Merged and published Version 0.3.1 on crates.io. Thank you!

@Covertness
Copy link
Owner

@martindisch
Copy link

Will do, I'll release a new version once I've merged martindisch/coap-lite#2.

@martindisch
Copy link

Version 0.3.2 is now published, with the Observe option port by @jiayihu. It also publicly exports the ObserveOption enum.

@Covertness
Copy link
Owner

Covertness commented Dec 7, 2020

Thanks. I created #54 for this issue. Any reviews are welcome.

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

3 participants