Open wezm opened 2 years ago
Sounds like an interesting project, but would probably require quite a bit of time and dedication. Would you be interested in opening a PR for this @wezm?
No not at the moment.
Just for reference, there is a no_std capable MQTT client implementation at https://github.com/obabec/rust-mqtt. It seems to be MQTT v5 only, so it's for sure not a drop-in replacement for rumqtt. I didn't do a detailed feature comparison.
Does anybody can point me direction how to port client to no_std environments?
Add #![no_std]
to lib.rs
and compile for a target without libstd
. E.g. cargo build --target arm-unknown-linux-gnueabihf
you will probably get a lot of errors that need to be addressed.
Just for reference, there is a no_std capable MQTT client implementation at https://github.com/obabec/rust-mqtt.
I'm also in search of a no_std
mqtt client (ideally optionally compatible with embassy for async). It looks like another option may be: https://github.com/00imvj00/mqttrs
Add #![no_std] to lib.rs and compile for a target without libstd. E.g. cargo build --target arm-unknown-linux-gnueabihf
Here's what this looks like for me (only adding the #![no_std]
and compiling for an esp32c3):
$ cargo build --target riscv32imc-unknown-none-elf |& grep '^error\[' | sort | uniq -c | sort -n
1 error[E0405]: cannot find trait `Clone` in this scope
1 error[E0405]: cannot find trait `Iterator` in this scope
1 error[E0405]: cannot find trait `Send` in this scope
1 error[E0405]: cannot find trait `Sync` in this scope
1 error[E0412]: cannot find type `Box` in this scope
1 error[E0412]: cannot find type `MaybeUninitSlice` in module `sys`
1 error[E0412]: cannot find type `Waker` in module `sys`
1 error[E0425]: cannot find function `accept` in module `sys`
1 error[E0425]: cannot find function `bind` in module `sys`
1 error[E0425]: cannot find function `connect` in module `sys`
1 error[E0425]: cannot find function `from_in6_addr` in module `crate::sys`
1 error[E0425]: cannot find function `from_in_addr` in module `crate::sys`
1 error[E0425]: cannot find function `getpeername` in module `sys`
1 error[E0425]: cannot find function `getsockname` in module `sys`
1 error[E0425]: cannot find function `keepalive_time` in module `sys`
1 error[E0425]: cannot find function `listen` in module `sys`
1 error[E0425]: cannot find function `msghdr_flags` in module `sys`
1 error[E0425]: cannot find function `peek_sender` in module `sys`
1 error[E0425]: cannot find function `poll_connect` in module `sys`
1 error[E0425]: cannot find function `recv_from_vectored` in module `sys`
1 error[E0425]: cannot find function `recv_from` in module `sys`
1 error[E0425]: cannot find function `recv_vectored` in module `sys`
1 error[E0425]: cannot find function `recv` in module `sys`
1 error[E0425]: cannot find function `send_to_vectored` in module `sys`
1 error[E0425]: cannot find function `send_to` in module `sys`
1 error[E0425]: cannot find function `send_vectored` in module `sys`
1 error[E0425]: cannot find function `send` in module `sys`
1 error[E0425]: cannot find function `sendmsg` in module `sys`
1 error[E0425]: cannot find function `set_msghdr_flags` in module `sys`
1 error[E0425]: cannot find function `set_nonblocking` in module `sys`
1 error[E0425]: cannot find function `set_reuseaddr` in this scope
1 error[E0425]: cannot find function `set_tcp_keepalive` in module `sys`
1 error[E0425]: cannot find function `shutdown` in module `sys`
1 error[E0425]: cannot find function `socket_as_raw` in module `sys`
1 error[E0425]: cannot find function `socket_from_raw` in module `sys`
1 error[E0425]: cannot find function `socket_into_raw` in module `sys`
1 error[E0425]: cannot find function `socket` in module `sys`
1 error[E0425]: cannot find function `to_in6_addr` in module `crate::sys`
1 error[E0425]: cannot find function `to_in_addr` in module `crate::sys`
1 error[E0425]: cannot find function `try_clone` in module `sys`
1 error[E0425]: cannot find function `unix_sockaddr` in module `crate::sys`
1 error[E0425]: cannot find value `AF_INET6` in module `sys`
1 error[E0425]: cannot find value `AF_INET` in module `sys`
1 error[E0425]: cannot find value `AF_UNIX` in module `sys`
1 error[E0425]: cannot find value `IPPROTO_ICMPV6` in module `sys`
1 error[E0425]: cannot find value `IPPROTO_ICMP` in module `sys`
1 error[E0425]: cannot find value `IPPROTO_UDP` in module `sys`
1 error[E0425]: cannot find value `IPV6_ADD_MEMBERSHIP` in module `sys`
1 error[E0425]: cannot find value `IPV6_DROP_MEMBERSHIP` in module `sys`
1 error[E0425]: cannot find value `IP_ADD_SOURCE_MEMBERSHIP` in module `sys`
1 error[E0425]: cannot find value `IP_DROP_SOURCE_MEMBERSHIP` in module `sys`
1 error[E0425]: cannot find value `MSG_TRUNC` in module `sys`
1 error[E0425]: cannot find value `SOCK_DGRAM` in module `sys`
1 error[E0425]: cannot find value `SOCK_RAW` in module `sys`
1 error[E0425]: cannot find value `SOCK_SEQPACKET` in module `sys`
1 error[E0425]: cannot find value `SOCK_STREAM` in module `sys`
1 error[E0425]: cannot find value `SO_ERROR` in module `sys`
1 error[E0425]: cannot find value `SO_TYPE` in module `sys`
1 error[E0425]: cannot find value `from_in_addr` in module `sys`
1 error[E0432]: unresolved import `crate::sys::IoSourceState`
1 error[E0432]: unresolved import `sys::c_int`
1 error[E0432]: unresolved imports `crate::sys::c_int`, `crate::sys::getsockopt`, `crate::sys::setsockopt`, `crate::sys::Bool`
1 error[E0432]: unresolved imports `crate::sys::c_int`, `crate::sys::sa_family_t`, `crate::sys::sockaddr`, `crate::sys::sockaddr_in`, `crate::sys::sockaddr_in6`, `crate::sys::sockaddr_storage`, `crate::sys::socklen_t`, `crate::sys::AF_INET`, `crate::sys::AF_INET6`, `crate::sys::AF_UNIX`
1 error[E0433]: failed to resolve: could not find `Events` in `sys`
1 error[E0433]: failed to resolve: could not find `MaybeUninitSlice` in `sys`
1 error[E0433]: failed to resolve: could not find `Selector` in `sys`
1 error[E0433]: failed to resolve: could not find `Waker` in `sys`
1 error[E0433]: failed to resolve: could not find `tcp` in `sys`
1 error[E0433]: failed to resolve: use of undeclared type `Default`
1 error[E0433]: failed to resolve: use of undeclared type `From`
1 error[E0463]: can't find crate for `alloc`
1 error[E0463]: can't find crate for `compiler_builtins`
1 error[E0583]: file not found for module `sys`
2 error[E0405]: cannot find trait `Eq` in this scope
2 error[E0405]: cannot find trait `IntoIterator` in this scope
2 error[E0412]: cannot find type `Events` in module `sys`
2 error[E0412]: cannot find type `Selector` in module `sys`
2 error[E0412]: cannot find type `msghdr` in module `sys`
2 error[E0422]: cannot find struct, variant or union type `IpMreqSource` in module `sys`
2 error[E0422]: cannot find struct, variant or union type `IpMreq` in module `sys`
2 error[E0422]: cannot find struct, variant or union type `Ipv6Mreq` in module `sys`
2 error[E0422]: cannot find struct, variant or union type `linger` in module `sys`
2 error[E0425]: cannot find function `set_msghdr_control` in module `sys`
2 error[E0425]: cannot find function `set_msghdr_iov` in module `sys`
2 error[E0425]: cannot find function `set_msghdr_name` in module `sys`
2 error[E0425]: cannot find function `set_timeout_opt` in module `sys`
2 error[E0425]: cannot find function `timeout_opt` in module `sys`
2 error[E0425]: cannot find function `to_in6_addr` in module `sys`
2 error[E0425]: cannot find function `to_mreqn` in module `sys`
2 error[E0425]: cannot find value `IPV6_MULTICAST_HOPS` in module `sys`
2 error[E0425]: cannot find value `IPV6_MULTICAST_IF` in module `sys`
2 error[E0425]: cannot find value `IPV6_MULTICAST_LOOP` in module `sys`
2 error[E0425]: cannot find value `IPV6_RECVTCLASS` in module `sys`
2 error[E0425]: cannot find value `IPV6_UNICAST_HOPS` in module `sys`
2 error[E0425]: cannot find value `IPV6_V6ONLY` in module `sys`
2 error[E0425]: cannot find value `IP_ADD_MEMBERSHIP` in module `sys`
2 error[E0425]: cannot find value `IP_DROP_MEMBERSHIP` in module `sys`
2 error[E0425]: cannot find value `IP_HDRINCL` in module `sys`
2 error[E0425]: cannot find value `IP_MULTICAST_IF` in module `sys`
2 error[E0425]: cannot find value `IP_MULTICAST_LOOP` in module `sys`
2 error[E0425]: cannot find value `IP_MULTICAST_TTL` in module `sys`
2 error[E0425]: cannot find value `IP_RECVTOS` in module `sys`
2 error[E0425]: cannot find value `IP_TOS` in module `sys`
2 error[E0425]: cannot find value `IP_TTL` in module `sys`
2 error[E0425]: cannot find value `MSG_OOB` in module `sys`
2 error[E0425]: cannot find value `MSG_PEEK` in module `sys`
2 error[E0425]: cannot find value `SO_BROADCAST` in module `sys`
2 error[E0425]: cannot find value `SO_KEEPALIVE` in module `sys`
2 error[E0425]: cannot find value `SO_LINGER` in module `sys`
2 error[E0425]: cannot find value `SO_OOBINLINE` in module `sys`
2 error[E0425]: cannot find value `SO_RCVBUF` in module `sys`
2 error[E0425]: cannot find value `SO_RCVTIMEO` in module `sys`
2 error[E0425]: cannot find value `SO_REUSEADDR` in module `sys`
2 error[E0425]: cannot find value `SO_SNDBUF` in module `sys`
2 error[E0425]: cannot find value `SO_SNDTIMEO` in module `sys`
2 error[E0425]: cannot find value `TCP_NODELAY` in module `sys`
2 error[E0425]: cannot find value `stream` in this scope
2 error[E0432]: unresolved import `crate::sys::tcp`
2 error[E0433]: failed to resolve: could not find `udp` in `sys`
3 error[E0405]: cannot find trait `PartialEq` in this scope
3 error[E0412]: cannot find type `Socket` in module `sys`
3 error[E0412]: cannot find type `c_int` in module `sys`
3 error[E0412]: cannot find type `linger` in module `sys`
3 error[E0425]: cannot find value `IPPROTO_TCP` in module `sys`
4 error[E0412]: cannot find type `Event` in module `sys`
4 error[E0425]: cannot find value `listener` in this scope
9 error[E0405]: cannot find trait `AsRef` in this scope
9 error[E0405]: cannot find trait `TryFrom` in this scope
10 error[E0405]: cannot find trait `FnOnce` in this scope
10 error[E0405]: cannot find trait `Sized` in this scope
10 error[E0433]: failed to resolve: could not find `event` in `sys`
10 error[E0531]: cannot find tuple struct or tuple variant `Some` in this scope
11 error[E0425]: cannot find function `to_in_addr` in module `sys`
11 error[E0531]: cannot find tuple struct or tuple variant `Err` in this scope
11 error[E0531]: cannot find tuple struct or tuple variant `Ok` in this scope
13 error[E0425]: cannot find value `None` in this scope
14 error[E0425]: cannot find value `IPPROTO_IPV6` in module `sys`
17 error[E0425]: cannot find function, tuple struct or tuple variant `Some` in this scope
18 error[E0463]: can't find crate for `core`
20 error[E0425]: cannot find function, tuple struct or tuple variant `Err` in this scope
20 error[E0425]: cannot find value `IPPROTO_IP` in module `sys`
20 error[E0425]: cannot find value `SOL_SOCKET` in module `sys`
22 error[E0412]: cannot find type `Result` in this scope
29 error[E0425]: cannot find function, tuple struct or tuple variant `Ok` in this scope
42 error[E0405]: cannot find trait `From` in this scope
45 error[E0412]: cannot find type `Option` in this scope
67 error[E0463]: can't find crate for `std`
Another option: https://github.com/keithduncan/embedded-mqtt -- no commits in 3 yrs though.
EDIT: Also https://github.com/BlackbirdHQ/mqttrust, no commits in 2 yrs
_Opening this issue in response to this comment on Lobsters._
Since MQTT is frequently used in IoT environments with microcontrollers publishing data to a broker it would be nice if it were possible to use the rumqtt client in no_std environments.
no_std
only has access to core and thus by default lacks threads, networking, files, heap allocation etc. There are various crates that provide/abstract over these missing pieces: