Documentation
¶
Overview ¶
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.
Index ¶
- Constants
- func ArenaStats() (used, capacity uint32)
- func Connect(cfg STAConfig) error
- func DebugISRCount() uint32
- func Enable(config Config) error
- func NetifRxStats() (uint32, uint32)
- func SniffCountOnChannel(channel uint8, duration time.Duration) (uint32, error)
- func Start() error
- func StartAP(cfg APConfig) error
- type APConfig
- type AccessPoint
- type Config
- type ConnectResult
- type DHCPConfig
- type Error
- type EthernetDevice
- type LogLevel
- type NetDev
- func (nd *NetDev) EthPoll(buf []byte) (bool, error)
- func (nd *NetDev) HardwareAddr6() (mac [6]byte, _ error)
- func (nd *NetDev) MaxFrameSize() int
- func (nd *NetDev) NetFlags() net.Flags
- func (nd *NetDev) SendEthFrame(frame []byte) error
- func (nd *NetDev) SetEthRecvHandler(handler func(pkt []byte) error)
- type STAConfig
- type Stack
- type StackConfig
Constants ¶
const ( LogLevelNone = C.WIFI_LOG_NONE LogLevelError = C.WIFI_LOG_ERROR LogLevelWarning = C.WIFI_LOG_WARNING LogLevelInfo = C.WIFI_LOG_INFO LogLevelDebug = C.WIFI_LOG_DEBUG LogLevelVerbose = C.WIFI_LOG_VERBOSE )
const MaxFrameSize = 1518
const Version = "0.1.0-dev"
Version is the current version of the espradio library.
Variables ¶
This section is empty.
Functions ¶
func ArenaStats ¶
func ArenaStats() (used, capacity uint32)
ArenaStats returns the current arena usage and capacity in bytes.
func Connect ¶
Connect configures STA credentials and initiates association. Blocks until CONNECTED, DISCONNECTED or timeout.
func DebugISRCount ¶
func DebugISRCount() uint32
DebugISRCount returns the number of WiFi ISR invocations (for debugging).
func NetifRxStats ¶
NetifRxStats returns (callback_count, drop_count) from the C ring buffer.
func SniffCountOnChannel ¶
func Start ¶
func Start() error
Start starts the Wi-Fi driver and connects to the AP if in station mode. Blocks until the driver is ready. Start is separate from Enable to allow configuration (e.g. country code) before starting, and to allow scanning without starting the driver. Start calls schedOnce in a loop to let the blob process its internal startup sequence (posting events, etc.) before Start returns.
Types ¶
type AccessPoint ¶
AccessPoint represents a Wi-Fi access point discovered during scanning.
func Scan ¶
func Scan() ([]AccessPoint, error)
Scan performs a single Wi-Fi scan pass and returns the list of discovered access points.
type Config ¶
type Config struct {
Logging LogLevel
// ArenaPoolSize overrides the default per-target arena pool size (bytes).
// Zero means use the target default.
ArenaPoolSize int
}
Config configures the radio and its driver.
type ConnectResult ¶
ConnectResult represents the result of a connection attempt.
type DHCPConfig ¶
DHCPConfig configures DHCP address acquisition.
type EthernetDevice ¶
type EthernetDevice interface {
// SendEthFrame transmits a complete Ethernet frame.
// The frame includes the Ethernet header but NOT the FCS/CRC
// trailer (device or stack handles CRC as appropriate).
// SendEthFrame blocks until the transmission is queued succesfully
// or finished sending. Should not be called concurrently
// unless user is sure the driver supports it.
SendEthFrame(frame []byte) error
// SetRecvHandler registers the function called when an Ethernet
// frame is received. After the callback returns the buffer is reused.
// The callback may or may not be called from an interrupt context
// so the callback should return fast, ideally copy the packet
// to a buffer to be processed outside the ISR.
//
// We don't use a channel for several reasons:
// - Near impossible for channel sender to know lifetime of the buffer;
// when is it finished being used?
// - Hard to determine best "channel full" semantics
SetEthRecvHandler(handler func(pkt []byte) error)
// EthPoll services the device. For poll-based devices (e.g. CYW43439
// over SPI), reads from the bus and invokes the handler for each
// received frame. Behaviour for interrupt driven devices is undefined
// at the moment.
EthPoll(buf []byte) (bool, error)
// HardwareAddr6 returns the device's 6-byte MAC address.
// For PHY-only devices, returns the MAC provided at configuration.
HardwareAddr6() ([6]byte, error)
// MaxFrameSize returns the max complete Ethernet frame size
// (including headers and any overhead) for buffer allocation.
// MTU can be calculated doing:
// // mfu-(14+4+4) for:
// // ethernet header+ethernet CRC if present+ethernet VLAN overhead for VLAN support.
// mtu := dev.MaxFrameSize() - ethernet.MaxOverheadSize
MaxFrameSize() int
// NetFlags offers ability to provide user with notice of the device state.
// May be also used to encode functioning such as if the device needs FCS/CRC encoding appended
// to the ethernet packet. WIP.
NetFlags() net.Flags
}
EthernetDevice is WIP of how ethernet device API design.
Device-specific initialization (WiFi join, PHY auto-negotiation, firmware loading) must complete BEFORE the device is used as a stack endpoint.
type NetDev ¶
type NetDev struct {
// contains filtered or unexported fields
}
NetDev provides raw Ethernet frame I/O over the WiFi STA interface.
func StartNetDev ¶
StartNetDev registers the STA RX callback and starts the receive pump.
func StartNetDevAP ¶
StartNetDevAP registers the AP RX callback and starts the receive pump.
func (*NetDev) EthPoll ¶
EthPoll checks for a received Ethernet frame and calls the receive handler if one is available. EthPoll returns (true, nil) if a frame was received and the handler was called, (false, nil) if no frame was available, or (false, err) if an error occurred.
func (*NetDev) HardwareAddr6 ¶
HardwareAddr6 returns the 6-byte MAC address of the WiFi interface.
func (*NetDev) MaxFrameSize ¶
MaxFrameSize returns the maximum Ethernet frame size supported by the driver, including the Ethernet header but excluding CRC.
func (*NetDev) NetFlags ¶
NetFlags returns the network interface flags for this device. The flags indicate that the interface is up and supports broadcast and multicast.
func (*NetDev) SendEthFrame ¶
SendEthFrame sends a raw Ethernet frame out the WiFi interface. The frame must include the Ethernet header and be at least 60 bytes (including CRC, which is not included in the frame). SendEthFrame returns an error if the frame is too short or too long, or if the driver is not ready to send.
func (*NetDev) SetEthRecvHandler ¶
SetEthRecvHandler sets the callback to be called when a new Ethernet frame is received.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack wraps an lneto async network stack on top of a NetDev (EthernetDevice).
func NewStack ¶
func NewStack(dev *NetDev, cfg StackConfig) (*Stack, error)
NewStack creates a new lneto-based TCP/IP stack on top of the given NetDev. The NetDev must already be started (WiFi joined, StartNetDev called).
func (*Stack) LnetoStack ¶
func (stack *Stack) LnetoStack() *xnet.StackAsync
LnetoStack returns the underlying lneto async stack for advanced use.
func (*Stack) RecvAndSend ¶
RecvAndSend polls the device for received frames and sends any pending outgoing frames. Returns the number of bytes sent and received.
func (*Stack) SetupWithDHCP ¶
func (stack *Stack) SetupWithDHCP(cfg DHCPConfig) (*xnet.DHCPResults, error)
SetupWithDHCP performs DHCPv4 to obtain an IP address and configures the stack with the results. Blocks until complete or timeout.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
ap
command
This example shows how to set up an AP with a DHCP server.
|
This example shows how to set up an AP with a DHCP server. |
|
connect-and-dhcp
command
This example shows how to connect to a Wi-Fi network and get an IP address with DHCP.
|
This example shows how to connect to a Wi-Fi network and get an IP address with DHCP. |
|
hello
command
|
|
|
http-app
command
This example shows how to create a simple HTTP server that serves a webpage with a button to toggle an LED and a list of recent actions.
|
This example shows how to create a simple HTTP server that serves a webpage with a button to toggle an LED and a list of recent actions. |
|
http-get
command
This example gets an URL using http.Get().
|
This example gets an URL using http.Get(). |
|
http-static
command
This example shows how to create a simple HTTP server that serves a static webpage.
|
This example shows how to create a simple HTTP server that serves a static webpage. |
|
mqtt
command
|
|
|
scan
command
This example demonstrates how to scan for available Wi-Fi access points using the ESP32 radio.
|
This example demonstrates how to scan for available Wi-Fi access points using the ESP32 radio. |
|
starting
command
|
|
|
webserver
command
This example listens on port :80 serving a web page.
|
This example listens on port :80 serving a web page. |
