-
Notifications
You must be signed in to change notification settings - Fork 12
Add go-idiomatic ESP-NOW wrappers #44
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
625f220
Add ESP-NOW wrappers
sparques 8c712f6
address compile error
sparques e9140b1
add go-idiomatic io.PacketConn interface for ESPNow + a streaming ada…
sparques 96e4b1b
bound error range
sparques e6f5730
Merge upstream/main
sparques 818e898
add examples/espnow/main.go
sparques File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,68 @@ | ||
| // Package espradio provides support for the ESP32-S2 and ESP32-S3 microcontrollers. | ||
| // It is based on the ESP-IDF framework and provides access to Wi-Fi and Bluetooth. | ||
| // The package is designed to be used with the TinyGo compiler. | ||
| // Package espradio provides wireless support for Espressif microcontrollers | ||
| // when used with the TinyGo compiler. | ||
| // | ||
| // The package wraps the Espressif Wi-Fi blobs and exposes both lower-level | ||
| // 1:1 bindings and higher-level Go APIs for common use cases such as: | ||
| // | ||
| // - station and soft-AP Wi-Fi | ||
| // - scanning | ||
| // - raw Ethernet/netdev integration | ||
| // - ESP-NOW datagram communication | ||
| // | ||
| // ESP-NOW can be used directly through the thin wrapper functions, or through | ||
| // the higher-level managed API returned by NewESPNow. The managed API maps each | ||
| // remote peer to a Peer that implements net.PacketConn. | ||
| // | ||
| // For applications that prefer a stream-like API over packet-oriented reads and | ||
| // writes, Peer can also be wrapped with PeerStream via peer.Stream(). | ||
| // | ||
| // Example usage: | ||
| // | ||
| // func main() { | ||
| // if err := espradio.Enable(espradio.Config{}); err != nil { | ||
| // panic(err) | ||
| // } | ||
| // if err := espradio.Start(); err != nil { | ||
| // panic(err) | ||
| // } | ||
| // | ||
| // now, err := espradio.NewESPNow(espradio.ESPNowConfig{}) | ||
| // if err != nil { | ||
| // panic(err) | ||
| // } | ||
| // defer now.Close() | ||
| // | ||
| // peer, err := now.AddPeer(espradio.PeerConfig{ | ||
| // Address: espradio.ESPNowAddr{0x24, 0x6f, 0x28, 0xaa, 0xbb, 0xcc}, | ||
| // If: espradio.WiFiInterfaceSTA, | ||
| // }) | ||
| // if err != nil { | ||
| // panic(err) | ||
| // } | ||
| // defer peer.Close() | ||
| // | ||
| // if _, err := peer.WriteTo([]byte("hello"), nil); err != nil { | ||
| // panic(err) | ||
| // } | ||
| // | ||
| // buf := make([]byte, espradio.ESPNowMaxDataLength) | ||
| // n, addr, err := peer.ReadFrom(buf) | ||
| // if err != nil { | ||
| // panic(err) | ||
| // } | ||
| // println("received", n, "bytes from", addr.String()) | ||
| // | ||
| // stream := peer.Stream() | ||
| // if _, err := stream.Write([]byte("streamed payload")); err != nil { | ||
| // panic(err) | ||
| // } | ||
| // | ||
| // broadcast, err := now.Broadcast() | ||
| // if err != nil { | ||
| // panic(err) | ||
| // } | ||
| // if _, err := broadcast.WriteTo([]byte("announcement"), nil); err != nil { | ||
| // panic(err) | ||
| // } | ||
| // } | ||
| package espradio // import "tinygo.org/x/espradio" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add this as an example in
examples/espnow? That should also build that example as part of the smoke tests. Also makes it a lot easier to try it and use it for things.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example added.